Tidy up, including;
authorGeoff Thorpe <geoff@openssl.org>
Sun, 20 Jun 2004 04:16:12 +0000 (04:16 +0000)
committerGeoff Thorpe <geoff@openssl.org>
Sun, 20 Jun 2004 04:16:12 +0000 (04:16 +0000)
- 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

crypto/bn/bn.h
crypto/bn/bn_lib.c
crypto/bn/bn_print.c

index 3477a13fffafdedd4bbfe7fb053181d0cd4a5fb0..cbe3153e9e14f59680b46df40ef7c745b16fe718 100644 (file)
@@ -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 */
index 789e9aa4fb6c59c81720d662439f2cfc916efbac..bbefd80309d096623a891cd7943bb478636cf4af 100644 (file)
@@ -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;
index 7f7b36a122a7cd5f2f91f0fcd0f202fb73d734ac..092322d2ff8b0e51bfbcb63e855bf8407b494550 100644 (file)
@@ -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