Index: openssl/crypto/ec/ec_mult.c |
=================================================================== |
--- openssl/crypto/ec/ec_mult.c (revision 105093) |
+++ openssl/crypto/ec/ec_mult.c (working copy) |
@@ -169,11 +169,13 @@ |
EC_POINT **p; |
for (p = pre->points; *p != NULL; p++) |
+ { |
EC_POINT_clear_free(*p); |
- OPENSSL_cleanse(pre->points, sizeof pre->points); |
+ OPENSSL_cleanse(p, sizeof *p); |
+ } |
OPENSSL_free(pre->points); |
} |
- OPENSSL_cleanse(pre, sizeof pre); |
+ OPENSSL_cleanse(pre, sizeof *pre); |
OPENSSL_free(pre); |
} |
@@ -224,6 +226,12 @@ |
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 +241,6 @@ |
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 */ |
@@ -419,7 +421,7 @@ |
if (numblocks > pre_comp->numblocks) |
numblocks = pre_comp->numblocks; |
- pre_points_per_block = 1u << (pre_comp->w - 1); |
+ pre_points_per_block = (size_t)1 << (pre_comp->w - 1); |
/* check that pre_comp looks sane */ |
if (pre_comp->num != (pre_comp->numblocks * pre_points_per_block)) |
@@ -461,7 +463,7 @@ |
bits = i < num ? BN_num_bits(scalars[i]) : BN_num_bits(scalar); |
wsize[i] = EC_window_bits_for_scalar_size(bits); |
- num_val += 1u << (wsize[i] - 1); |
+ num_val += (size_t)1 << (wsize[i] - 1); |
wNAF[i + 1] = NULL; /* make sure we always have a pivot */ |
wNAF[i] = compute_wNAF((i < num ? scalars[i] : scalar), wsize[i], &wNAF_len[i]); |
if (wNAF[i] == NULL) |
@@ -600,7 +602,7 @@ |
for (i = 0; i < num + num_scalar; i++) |
{ |
val_sub[i] = v; |
- for (j = 0; j < (1u << (wsize[i] - 1)); j++) |
+ for (j = 0; j < ((size_t)1 << (wsize[i] - 1)); j++) |
{ |
*v = EC_POINT_new(group); |
if (*v == NULL) goto err; |
@@ -636,7 +638,7 @@ |
if (wsize[i] > 1) |
{ |
if (!EC_POINT_dbl(group, tmp, val_sub[i][0], ctx)) goto err; |
- for (j = 1; j < (1u << (wsize[i] - 1)); j++) |
+ for (j = 1; j < ((size_t)1 << (wsize[i] - 1)); j++) |
{ |
if (!EC_POINT_add(group, val_sub[i][j], val_sub[i][j - 1], tmp, ctx)) goto err; |
} |
@@ -820,7 +822,7 @@ |
numblocks = (bits + blocksize - 1) / blocksize; /* max. number of blocks to use for wNAF splitting */ |
- pre_points_per_block = 1u << (w - 1); |
+ pre_points_per_block = (size_t)1 << (w - 1); |
num = pre_points_per_block * numblocks; /* number of points to compute and store */ |
points = OPENSSL_malloc(sizeof (EC_POINT*)*(num + 1)); |