diff options
author | Geoff Thorpe <geoff@openssl.org> | 2004-06-20 04:16:12 +0000 |
---|---|---|
committer | Geoff Thorpe <geoff@openssl.org> | 2004-06-20 04:16:12 +0000 |
commit | d459e39012e9912e5e827338741e7894e7b2a876 (patch) | |
tree | 8972d36383351f6d5878c0c124f1410e0a807808 /crypto/bn/bn_lib.c | |
parent | 340f5856ec089c0a61f95795b21c1445292748d1 (diff) |
Tidy up, including;
- Remove unused and unuseful debug cruft.
- Remove unnecessary 'top' fudging from BN_copy().
- Fix a potential memory leak and simplify the expansion logic in
BN_bin2bn().
Submitted by: Nils Larsch
Reviewed by: Geoff Thorpe
Diffstat (limited to 'crypto/bn/bn_lib.c')
-rw-r--r-- | crypto/bn/bn_lib.c | 19 |
1 files changed, 10 insertions, 9 deletions
diff --git a/crypto/bn/bn_lib.c b/crypto/bn/bn_lib.c index 789e9aa4fb..bbefd80309 100644 --- a/crypto/bn/bn_lib.c +++ b/crypto/bn/bn_lib.c @@ -526,10 +526,6 @@ BIGNUM *BN_copy(BIGNUM *a, const BIGNUM *b) #endif a->top=b->top; -#ifndef BN_STRICT - if ((a->top == 0) && (a->d != NULL)) - a->d[0]=0; -#endif a->neg=b->neg; bn_check_top(a); return(a); @@ -643,8 +639,10 @@ BIGNUM *BN_bin2bn(const unsigned char *s, int len, BIGNUM *ret) unsigned int i,m; unsigned int n; BN_ULONG l; + BIGNUM *bn = NULL; - if (ret == NULL) ret=BN_new(); + if (ret == NULL) + ret = bn = BN_new(); if (ret == NULL) return(NULL); bn_check_top(ret); l=0; @@ -654,13 +652,16 @@ BIGNUM *BN_bin2bn(const unsigned char *s, int len, BIGNUM *ret) ret->top=0; return(ret); } - if (bn_expand(ret,(int)(n+2)*8) == NULL) - return(NULL); i=((n-1)/BN_BYTES)+1; m=((n-1)%(BN_BYTES)); + if (bn_wexpand(ret, (int)i) == NULL) + { + if (bn) BN_free(bn); + return NULL; + } ret->top=i; ret->neg=0; - while (n-- > 0) + while (n--) { l=(l<<8L)| *(s++); if (m-- == 0) @@ -684,7 +685,7 @@ int BN_bn2bin(const BIGNUM *a, unsigned char *to) bn_check_top(a); n=i=BN_num_bytes(a); - while (i-- > 0) + while (i--) { l=a->d[i/BN_BYTES]; *(to++)=(unsigned char)(l>>(8*(i%BN_BYTES)))&0xff; |