Skip to content

Commit 248f046

Browse files
Make sure we're not using an uninitialized variable in secp256k1_wnaf_const(...)
1 parent 452d8e4 commit 248f046

File tree

1 file changed

+6
-2
lines changed

1 file changed

+6
-2
lines changed

src/ecmult_const_impl.h

+6-2
Original file line numberDiff line numberDiff line change
@@ -61,6 +61,10 @@ static int secp256k1_wnaf_const(int *wnaf, secp256k1_scalar s, int w, int size)
6161
int bit;
6262
secp256k1_scalar neg_s;
6363
int not_neg_one;
64+
65+
VERIFY_CHECK(w > 0);
66+
VERIFY_CHECK(size > 0);
67+
6468
/* Note that we cannot handle even numbers by negating them to be odd, as is
6569
* done in other implementations, since if our scalars were specified to have
6670
* width < 256 for performance reasons, their negations would have width 256
@@ -93,7 +97,7 @@ static int secp256k1_wnaf_const(int *wnaf, secp256k1_scalar s, int w, int size)
9397

9498
/* 4 */
9599
u_last = secp256k1_scalar_shr_int(&s, w);
96-
while (word * w < size) {
100+
do {
97101
int sign;
98102
int even;
99103

@@ -109,7 +113,7 @@ static int secp256k1_wnaf_const(int *wnaf, secp256k1_scalar s, int w, int size)
109113
wnaf[word++] = u_last * global_sign;
110114

111115
u_last = u;
112-
}
116+
} while (word * w < size);
113117
wnaf[word] = u * global_sign;
114118

115119
VERIFY_CHECK(secp256k1_scalar_is_zero(&s));

0 commit comments

Comments
 (0)