summaryrefslogtreecommitdiff
path: root/src/lib/libcrypto/asn1/a_int.c
diff options
context:
space:
mode:
authorbeck <>2000-03-19 11:13:58 +0000
committerbeck <>2000-03-19 11:13:58 +0000
commit796d609550df3a33fc11468741c5d2f6d3df4c11 (patch)
tree6c6d539061caa20372dad0ac4ddb1dfae2fbe7fe /src/lib/libcrypto/asn1/a_int.c
parent5be3114c1fd7e0dfea1e38d3abb4cbba75244419 (diff)
downloadopenbsd-796d609550df3a33fc11468741c5d2f6d3df4c11.tar.gz
openbsd-796d609550df3a33fc11468741c5d2f6d3df4c11.tar.bz2
openbsd-796d609550df3a33fc11468741c5d2f6d3df4c11.zip
OpenSSL 0.9.5 merge
*warning* this bumps shared lib minors for libssl and libcrypto from 2.1 to 2.2 if you are using the ssl26 packages for ssh and other things to work you will need to get new ones (see ~beck/libsslsnap/<arch>) on cvs or ~beck/src-patent.tar.gz on cvs
Diffstat (limited to 'src/lib/libcrypto/asn1/a_int.c')
-rw-r--r--src/lib/libcrypto/asn1/a_int.c41
1 files changed, 30 insertions, 11 deletions
diff --git a/src/lib/libcrypto/asn1/a_int.c b/src/lib/libcrypto/asn1/a_int.c
index d05436378b..8b6794e8c1 100644
--- a/src/lib/libcrypto/asn1/a_int.c
+++ b/src/lib/libcrypto/asn1/a_int.c
@@ -60,6 +60,18 @@
60#include "cryptlib.h" 60#include "cryptlib.h"
61#include <openssl/asn1.h> 61#include <openssl/asn1.h>
62 62
63ASN1_INTEGER *ASN1_INTEGER_new(void)
64{ return M_ASN1_INTEGER_new();}
65
66void ASN1_INTEGER_free(ASN1_INTEGER *x)
67{ M_ASN1_INTEGER_free(x);}
68
69ASN1_INTEGER *ASN1_INTEGER_dup(ASN1_INTEGER *x)
70{ return M_ASN1_INTEGER_dup(x);}
71
72int ASN1_INTEGER_cmp(ASN1_INTEGER *x, ASN1_INTEGER *y)
73{ return M_ASN1_INTEGER_cmp(x,y);}
74
63/* 75/*
64 * This converts an ASN1 INTEGER into its DER encoding. 76 * This converts an ASN1 INTEGER into its DER encoding.
65 * The internal representation is an ASN1_STRING whose data is a big endian 77 * The internal representation is an ASN1_STRING whose data is a big endian
@@ -160,7 +172,7 @@ ASN1_INTEGER *d2i_ASN1_INTEGER(ASN1_INTEGER **a, unsigned char **pp,
160 172
161 if ((a == NULL) || ((*a) == NULL)) 173 if ((a == NULL) || ((*a) == NULL))
162 { 174 {
163 if ((ret=ASN1_INTEGER_new()) == NULL) return(NULL); 175 if ((ret=M_ASN1_INTEGER_new()) == NULL) return(NULL);
164 ret->type=V_ASN1_INTEGER; 176 ret->type=V_ASN1_INTEGER;
165 } 177 }
166 else 178 else
@@ -190,7 +202,12 @@ ASN1_INTEGER *d2i_ASN1_INTEGER(ASN1_INTEGER **a, unsigned char **pp,
190 goto err; 202 goto err;
191 } 203 }
192 to=s; 204 to=s;
193 if (*p & 0x80) /* a negative number */ 205 if(!len) {
206 /* Strictly speaking this is an illegal INTEGER but we
207 * tolerate it.
208 */
209 ret->type=V_ASN1_INTEGER;
210 } else if (*p & 0x80) /* a negative number */
194 { 211 {
195 ret->type=V_ASN1_NEG_INTEGER; 212 ret->type=V_ASN1_NEG_INTEGER;
196 if ((*p == 0xff) && (len != 1)) { 213 if ((*p == 0xff) && (len != 1)) {
@@ -231,7 +248,7 @@ ASN1_INTEGER *d2i_ASN1_INTEGER(ASN1_INTEGER **a, unsigned char **pp,
231 memcpy(s,p,(int)len); 248 memcpy(s,p,(int)len);
232 } 249 }
233 250
234 if (ret->data != NULL) Free((char *)ret->data); 251 if (ret->data != NULL) Free(ret->data);
235 ret->data=s; 252 ret->data=s;
236 ret->length=(int)len; 253 ret->length=(int)len;
237 if (a != NULL) (*a)=ret; 254 if (a != NULL) (*a)=ret;
@@ -240,7 +257,7 @@ ASN1_INTEGER *d2i_ASN1_INTEGER(ASN1_INTEGER **a, unsigned char **pp,
240err: 257err:
241 ASN1err(ASN1_F_D2I_ASN1_INTEGER,i); 258 ASN1err(ASN1_F_D2I_ASN1_INTEGER,i);
242 if ((ret != NULL) && ((a == NULL) || (*a != ret))) 259 if ((ret != NULL) && ((a == NULL) || (*a != ret)))
243 ASN1_INTEGER_free(ret); 260 M_ASN1_INTEGER_free(ret);
244 return(NULL); 261 return(NULL);
245 } 262 }
246 263
@@ -260,7 +277,7 @@ ASN1_INTEGER *d2i_ASN1_UINTEGER(ASN1_INTEGER **a, unsigned char **pp,
260 277
261 if ((a == NULL) || ((*a) == NULL)) 278 if ((a == NULL) || ((*a) == NULL))
262 { 279 {
263 if ((ret=ASN1_INTEGER_new()) == NULL) return(NULL); 280 if ((ret=M_ASN1_INTEGER_new()) == NULL) return(NULL);
264 ret->type=V_ASN1_INTEGER; 281 ret->type=V_ASN1_INTEGER;
265 } 282 }
266 else 283 else
@@ -289,7 +306,8 @@ ASN1_INTEGER *d2i_ASN1_UINTEGER(ASN1_INTEGER **a, unsigned char **pp,
289 goto err; 306 goto err;
290 } 307 }
291 to=s; 308 to=s;
292 ret->type=V_ASN1_INTEGER; 309 ret->type=V_ASN1_INTEGER;
310 if(len) {
293 if ((*p == 0) && (len != 1)) 311 if ((*p == 0) && (len != 1))
294 { 312 {
295 p++; 313 p++;
@@ -297,8 +315,9 @@ ASN1_INTEGER *d2i_ASN1_UINTEGER(ASN1_INTEGER **a, unsigned char **pp,
297 } 315 }
298 memcpy(s,p,(int)len); 316 memcpy(s,p,(int)len);
299 p+=len; 317 p+=len;
318 }
300 319
301 if (ret->data != NULL) Free((char *)ret->data); 320 if (ret->data != NULL) Free(ret->data);
302 ret->data=s; 321 ret->data=s;
303 ret->length=(int)len; 322 ret->length=(int)len;
304 if (a != NULL) (*a)=ret; 323 if (a != NULL) (*a)=ret;
@@ -307,7 +326,7 @@ ASN1_INTEGER *d2i_ASN1_UINTEGER(ASN1_INTEGER **a, unsigned char **pp,
307err: 326err:
308 ASN1err(ASN1_F_D2I_ASN1_UINTEGER,i); 327 ASN1err(ASN1_F_D2I_ASN1_UINTEGER,i);
309 if ((ret != NULL) && ((a == NULL) || (*a != ret))) 328 if ((ret != NULL) && ((a == NULL) || (*a != ret)))
310 ASN1_INTEGER_free(ret); 329 M_ASN1_INTEGER_free(ret);
311 return(NULL); 330 return(NULL);
312 } 331 }
313 332
@@ -321,7 +340,7 @@ int ASN1_INTEGER_set(ASN1_INTEGER *a, long v)
321 if (a->length < (sizeof(long)+1)) 340 if (a->length < (sizeof(long)+1))
322 { 341 {
323 if (a->data != NULL) 342 if (a->data != NULL)
324 Free((char *)a->data); 343 Free(a->data);
325 if ((a->data=(unsigned char *)Malloc(sizeof(long)+1)) != NULL) 344 if ((a->data=(unsigned char *)Malloc(sizeof(long)+1)) != NULL)
326 memset((char *)a->data,0,sizeof(long)+1); 345 memset((char *)a->data,0,sizeof(long)+1);
327 } 346 }
@@ -385,7 +404,7 @@ ASN1_INTEGER *BN_to_ASN1_INTEGER(BIGNUM *bn, ASN1_INTEGER *ai)
385 int len,j; 404 int len,j;
386 405
387 if (ai == NULL) 406 if (ai == NULL)
388 ret=ASN1_INTEGER_new(); 407 ret=M_ASN1_INTEGER_new();
389 else 408 else
390 ret=ai; 409 ret=ai;
391 if (ret == NULL) 410 if (ret == NULL)
@@ -401,7 +420,7 @@ ASN1_INTEGER *BN_to_ASN1_INTEGER(BIGNUM *bn, ASN1_INTEGER *ai)
401 ret->length=BN_bn2bin(bn,ret->data); 420 ret->length=BN_bn2bin(bn,ret->data);
402 return(ret); 421 return(ret);
403err: 422err:
404 if (ret != ai) ASN1_INTEGER_free(ret); 423 if (ret != ai) M_ASN1_INTEGER_free(ret);
405 return(NULL); 424 return(NULL);
406 } 425 }
407 426