diff options
author | Mark J. Cox <mark@openssl.org> | 1999-01-28 10:40:38 +0000 |
---|---|---|
committer | Mark J. Cox <mark@openssl.org> | 1999-01-28 10:40:38 +0000 |
commit | a0a5407901ae93fadcfead6d44b923b8ef1ad579 (patch) | |
tree | f491c5aedf07971f7a960e0976e7eef3d508e090 /crypto/bn/bn_sqr.c | |
parent | 8938272b322353aa564c21597ff43c010a0dd487 (diff) |
Fixes to BN code. Previously the default was to define BN_RECURSION
but the BN code had some problems that would cause failures when
doing certificate verification and some other functions.
Submitted by: Eric A Young from a C2Net version of SSLeay
Reviewed by: Mark J Cox
PR:
Diffstat (limited to 'crypto/bn/bn_sqr.c')
-rw-r--r-- | crypto/bn/bn_sqr.c | 40 |
1 files changed, 28 insertions, 12 deletions
diff --git a/crypto/bn/bn_sqr.c b/crypto/bn/bn_sqr.c index 3166e6ce5a..bcd9c3b6af 100644 --- a/crypto/bn/bn_sqr.c +++ b/crypto/bn/bn_sqr.c @@ -68,13 +68,14 @@ BIGNUM *a; BN_CTX *ctx; { int max,al; - BIGNUM *tmp; + BIGNUM *tmp,*rr; #ifdef BN_COUNT printf("BN_sqr %d * %d\n",a->top,a->top); #endif bn_check_top(a); tmp= &(ctx->bn[ctx->tos]); + rr=(a != r)?r: (&ctx->bn[ctx->tos+1]); al=a->top; if (al <= 0) @@ -84,25 +85,25 @@ printf("BN_sqr %d * %d\n",a->top,a->top); } max=(al+al); - if (bn_wexpand(r,max+1) == NULL) return(0); + if (bn_wexpand(rr,max+1) == NULL) return(0); r->neg=0; if (al == 4) { #ifndef BN_SQR_COMBA BN_ULONG t[8]; - bn_sqr_normal(r->d,a->d,4,t); + bn_sqr_normal(rr->d,a->d,4,t); #else - bn_sqr_comba4(r->d,a->d); + bn_sqr_comba4(rr->d,a->d); #endif } else if (al == 8) { #ifndef BN_SQR_COMBA BN_ULONG t[16]; - bn_sqr_normal(r->d,a->d,8,t); + bn_sqr_normal(rr->d,a->d,8,t); #else - bn_sqr_comba8(r->d,a->d); + bn_sqr_comba8(rr->d,a->d); #endif } else @@ -111,21 +112,36 @@ printf("BN_sqr %d * %d\n",a->top,a->top); if (al < BN_SQR_RECURSIVE_SIZE_NORMAL) { BN_ULONG t[BN_SQR_RECURSIVE_SIZE_NORMAL*2]; - bn_sqr_normal(r->d,a->d,al,t); + bn_sqr_normal(rr->d,a->d,al,t); } else { - if (bn_wexpand(tmp,2*max+1) == NULL) return(0); - bn_sqr_recursive(r->d,a->d,al,tmp->d); + int j,k; + + j=BN_num_bits_word((BN_ULONG)al); + j=1<<(j-1); + k=j+j; + if (al == j) + { + if (bn_wexpand(a,k*2) == NULL) return(0); + if (bn_wexpand(tmp,k*2) == NULL) return(0); + bn_sqr_recursive(rr->d,a->d,al,tmp->d); + } + else + { + if (bn_wexpand(tmp,max) == NULL) return(0); + bn_sqr_normal(rr->d,a->d,al,tmp->d); + } } #else if (bn_wexpand(tmp,max) == NULL) return(0); - bn_sqr_normal(r->d,a->d,al,tmp->d); + bn_sqr_normal(rr->d,a->d,al,tmp->d); #endif } - r->top=max; - if ((max > 0) && (r->d[max-1] == 0)) r->top--; + rr->top=max; + if ((max > 0) && (rr->d[max-1] == 0)) rr->top--; + if (rr != r) BN_copy(r,rr); return(1); } |