summaryrefslogtreecommitdiffstats
path: root/crypto
diff options
context:
space:
mode:
authorBen Laurie <ben@openssl.org>2008-12-27 02:15:16 +0000
committerBen Laurie <ben@openssl.org>2008-12-27 02:15:16 +0000
commit57a6ac7c4fc6f8854249cd91bce81472412d913d (patch)
treed384985fa5465e0fdd144fb61e6fbe98f7cbf757 /crypto
parent9b9cb004f755ea2add69f2d9df6468c331fef4f8 (diff)
Check scalar->d before we use it (in BN_num_bits()). (Coverity ID 129)
Diffstat (limited to 'crypto')
-rw-r--r--crypto/ec/ec_mult.c12
1 files changed, 6 insertions, 6 deletions
diff --git a/crypto/ec/ec_mult.c b/crypto/ec/ec_mult.c
index 2ba173ef36..84488c9643 100644
--- a/crypto/ec/ec_mult.c
+++ b/crypto/ec/ec_mult.c
@@ -224,6 +224,12 @@ static signed char *compute_wNAF(const BIGNUM *scalar, int w, size_t *ret_len)
sign = -1;
}
+ if (scalar->d == NULL || scalar->top == 0)
+ {
+ ECerr(EC_F_COMPUTE_WNAF, ERR_R_INTERNAL_ERROR);
+ goto err;
+ }
+
len = BN_num_bits(scalar);
r = OPENSSL_malloc(len + 1); /* modified wNAF may be one digit longer than binary representation
* (*ret_len will be set to the actual length, i.e. at most
@@ -233,12 +239,6 @@ static signed char *compute_wNAF(const BIGNUM *scalar, int w, size_t *ret_len)
ECerr(EC_F_COMPUTE_WNAF, ERR_R_MALLOC_FAILURE);
goto err;
}
-
- if (scalar->d == NULL || scalar->top == 0)
- {
- ECerr(EC_F_COMPUTE_WNAF, ERR_R_INTERNAL_ERROR);
- goto err;
- }
window_val = scalar->d[0] & mask;
j = 0;
while ((window_val != 0) || (j + w + 1 < len)) /* if j+w+1 >= len, window_val will not increase */