summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorGeoff Thorpe <geoff@openssl.org>2004-06-20 04:16:12 +0000
committerGeoff Thorpe <geoff@openssl.org>2004-06-20 04:16:12 +0000
commitd459e39012e9912e5e827338741e7894e7b2a876 (patch)
tree8972d36383351f6d5878c0c124f1410e0a807808
parent340f5856ec089c0a61f95795b21c1445292748d1 (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
-rw-r--r--crypto/bn/bn.h10
-rw-r--r--crypto/bn/bn_lib.c19
-rw-r--r--crypto/bn/bn_print.c11
3 files changed, 10 insertions, 30 deletions
diff --git a/crypto/bn/bn.h b/crypto/bn/bn.h
index 3477a13fff..cbe3153e9e 100644
--- a/crypto/bn/bn.h
+++ b/crypto/bn/bn.h
@@ -726,16 +726,6 @@ BN_ULONG bn_div_words(BN_ULONG h, BN_ULONG l, BN_ULONG d);
BN_ULONG bn_add_words(BN_ULONG *rp, const BN_ULONG *ap, const BN_ULONG *bp,int num);
BN_ULONG bn_sub_words(BN_ULONG *rp, const BN_ULONG *ap, const BN_ULONG *bp,int num);
-#ifdef BN_DEBUG
-void bn_dump1(FILE *o, const char *a, const BN_ULONG *b,int n);
-# define bn_print(a) {fprintf(stderr, #a "="); BN_print_fp(stderr,a); \
- fprintf(stderr,"\n");}
-# define bn_dump(a,n) bn_dump1(stderr,#a,a,n);
-#else
-# define bn_print(a)
-# define bn_dump(a,b)
-#endif
-
int BN_bntest_rand(BIGNUM *rnd, int bits, int top,int bottom);
/* BEGIN ERROR CODES */
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;
diff --git a/crypto/bn/bn_print.c b/crypto/bn/bn_print.c
index 7f7b36a122..092322d2ff 100644
--- a/crypto/bn/bn_print.c
+++ b/crypto/bn/bn_print.c
@@ -322,14 +322,3 @@ end:
return(ret);
}
#endif
-
-#ifdef BN_DEBUG
-void bn_dump1(FILE *o, const char *a, const BN_ULONG *b,int n)
- {
- int i;
- fprintf(o, "%s=", a);
- for (i=n-1;i>=0;i--)
- fprintf(o, "%08lX", b[i]); /* assumes 32-bit BN_ULONG */
- fprintf(o, "\n");
- }
-#endif