diff options
author | Geoff Thorpe <geoff@openssl.org> | 2004-03-13 23:57:20 +0000 |
---|---|---|
committer | Geoff Thorpe <geoff@openssl.org> | 2004-03-13 23:57:20 +0000 |
commit | b6358c89a10128692875fb92921b663c4d079a1e (patch) | |
tree | d36362a84ee41209484b4b088c2b9d1728bfc613 /crypto/bn/bn_sqr.c | |
parent | 5d735465d1b5b7853506979946ad5730cc3615bb (diff) |
Convert openssl code not to assume the deprecated form of BN_zero().
Remove certain redundant BN_zero() initialisations, because BN_CTX_get(),
BN_init(), [etc] already initialise to zero.
Correct error checking in bn_sqr.c, and be less wishy-wash about how/why
the result's 'top' value is set (note also, 'max' is always > 0 at this
point).
Diffstat (limited to 'crypto/bn/bn_sqr.c')
-rw-r--r-- | crypto/bn/bn_sqr.c | 17 |
1 files changed, 11 insertions, 6 deletions
diff --git a/crypto/bn/bn_sqr.c b/crypto/bn/bn_sqr.c index ab678d1f30..8831daa390 100644 --- a/crypto/bn/bn_sqr.c +++ b/crypto/bn/bn_sqr.c @@ -77,15 +77,15 @@ int BN_sqr(BIGNUM *r, const BIGNUM *a, BN_CTX *ctx) if (al <= 0) { r->top=0; - return(1); + return 1; } BN_CTX_start(ctx); rr=(a != r) ? r : BN_CTX_get(ctx); tmp=BN_CTX_get(ctx); - if (tmp == NULL) goto err; + if (!rr || !tmp) goto err; - max=(al+al); + max = 2 * al; /* Non-zero (from above) */ if (bn_wexpand(rr,max+1) == NULL) goto err; if (al == 4) @@ -138,14 +138,19 @@ int BN_sqr(BIGNUM *r, const BIGNUM *a, BN_CTX *ctx) #endif } - rr->top=max; rr->neg=0; - if ((max > 0) && (rr->d[max-1] == 0)) rr->top--; + /* If the most-significant half of the top word of 'a' is zero, then + * the square of 'a' will max-1 words. */ + if(a->d[al - 1] == (a->d[al - 1] & BN_MASK2l)) + rr->top = max - 1; + else + rr->top = max; if (rr != r) BN_copy(r,rr); ret = 1; err: + if(rr) bn_check_top(rr); + if(tmp) bn_check_top(tmp); BN_CTX_end(ctx); - bn_check_top(r); return(ret); } |