comparison libtomcrypt/src/pk/asn1/der/integer/der_encode_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_encode_integer.c 12 @file der_encode_integer.c
25 @param out [out] The destination for the DER encoded integers 23 @param out [out] The destination for the DER encoded integers
26 @param outlen [in/out] The max size and resulting size of the DER encoded integers 24 @param outlen [in/out] The max size and resulting size of the DER encoded integers
27 @return CRYPT_OK if successful 25 @return CRYPT_OK if successful
28 */ 26 */
29 int der_encode_integer(void *num, unsigned char *out, unsigned long *outlen) 27 int der_encode_integer(void *num, unsigned char *out, unsigned long *outlen)
30 { 28 {
31 unsigned long tmplen, y; 29 unsigned long tmplen, y;
32 int err, leading_zero; 30 int err, leading_zero;
33 31
34 LTC_ARGCHK(num != NULL); 32 LTC_ARGCHK(num != NULL);
35 LTC_ARGCHK(out != NULL); 33 LTC_ARGCHK(out != NULL);
95 if ((err = mp_to_unsigned_bin(num, out)) != CRYPT_OK) { 93 if ((err = mp_to_unsigned_bin(num, out)) != CRYPT_OK) {
96 return err; 94 return err;
97 } 95 }
98 } else if (mp_iszero(num) != LTC_MP_YES) { 96 } else if (mp_iszero(num) != LTC_MP_YES) {
99 void *tmp; 97 void *tmp;
100 98
101 /* negative */ 99 /* negative */
102 if (mp_init(&tmp) != CRYPT_OK) { 100 if (mp_init(&tmp) != CRYPT_OK) {
103 return CRYPT_MEM; 101 return CRYPT_MEM;
104 } 102 }
105 103
117 } 115 }
118 mp_clear(tmp); 116 mp_clear(tmp);
119 } 117 }
120 118
121 /* we good */ 119 /* we good */
122 *outlen = tmplen; 120 *outlen = tmplen;
123 return CRYPT_OK; 121 return CRYPT_OK;
124 } 122 }
125 123
126 #endif 124 #endif
127 125
128 /* $Source$ */ 126 /* ref: $Format:%D$ */
129 /* $Revision$ */ 127 /* git commit: $Format:%H$ */
130 /* $Date$ */ 128 /* commit time: $Format:%ai$ */