comparison libtomcrypt/src/pk/asn1/der/integer/der_decode_integer.c @ 1471:6dba84798cd5

Update to libtomcrypt 1.18.1, merged with Dropbear changes
author Matt Johnston <matt@ucc.asn.au>
date Fri, 09 Feb 2018 21:44:05 +0800
parents f849a5ca2efc
children
comparison
equal deleted inserted replaced
1470:8bba51a55704 1471:6dba84798cd5
3 * LibTomCrypt is a library that provides various cryptographic 3 * LibTomCrypt is a library that provides various cryptographic
4 * algorithms in a highly modular and flexible manner. 4 * algorithms in a highly modular and flexible manner.
5 * 5 *
6 * The library is free for all purposes without any express 6 * The library is free for all purposes without any express
7 * guarantee it works. 7 * guarantee it works.
8 *
9 * Tom St Denis, [email protected], http://libtom.org
10 */ 8 */
11 #include "tomcrypt.h" 9 #include "tomcrypt.h"
12 10
13 /** 11 /**
14 @file der_decode_integer.c 12 @file der_decode_integer.c
52 50
53 /* will it overflow? */ 51 /* will it overflow? */
54 if (x + z > inlen) { 52 if (x + z > inlen) {
55 return CRYPT_INVALID_PACKET; 53 return CRYPT_INVALID_PACKET;
56 } 54 }
57 55
58 /* no so read it */ 56 /* no so read it */
59 if ((err = mp_read_unsigned_bin(num, (unsigned char *)in + x, z)) != CRYPT_OK) { 57 if ((err = mp_read_unsigned_bin(num, (unsigned char *)in + x, z)) != CRYPT_OK) {
60 return err; 58 return err;
61 } 59 }
62 } else { 60 } else {
63 /* long form */ 61 /* long form */
64 z &= 0x7F; 62 z &= 0x7F;
65 63
66 /* will number of length bytes overflow? (or > 4) */ 64 /* will number of length bytes overflow? (or > 4) */
67 if (((x + z) > inlen) || (z > 4) || (z == 0)) { 65 if (((x + z) > inlen) || (z > 4) || (z == 0)) {
68 return CRYPT_INVALID_PACKET; 66 return CRYPT_INVALID_PACKET;
69 } 67 }
70 68
95 if (mp_2expt(tmp, mp_count_bits(num)) != CRYPT_OK || mp_sub(num, tmp, num) != CRYPT_OK) { 93 if (mp_2expt(tmp, mp_count_bits(num)) != CRYPT_OK || mp_sub(num, tmp, num) != CRYPT_OK) {
96 mp_clear(tmp); 94 mp_clear(tmp);
97 return CRYPT_MEM; 95 return CRYPT_MEM;
98 } 96 }
99 mp_clear(tmp); 97 mp_clear(tmp);
100 } 98 }
101 99
102 return CRYPT_OK; 100 return CRYPT_OK;
103 101
104 } 102 }
105 103
106 #endif 104 #endif
107 105
108 /* $Source$ */ 106 /* ref: $Format:%D$ */
109 /* $Revision$ */ 107 /* git commit: $Format:%H$ */
110 /* $Date$ */ 108 /* commit time: $Format:%ai$ */