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
This commit is contained in:
Geoff Thorpe 2004-06-20 04:16:12 +00:00
parent 340f5856ec
commit d459e39012
3 changed files with 10 additions and 30 deletions

View 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 */

View 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;

View 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