]> Git Repo - secp256k1.git/commitdiff
Make sure we're not using an uninitialized variable in secp256k1_wnaf_const(...)
authorpracticalswift <[email protected]>
Sun, 6 May 2018 07:28:54 +0000 (09:28 +0200)
committerpracticalswift <[email protected]>
Thu, 21 Mar 2019 18:06:08 +0000 (19:06 +0100)
src/ecmult_const_impl.h

index 8411752eb069f6da43a8e555939f106c81d2abbd..61a47701d8d5ff78fe740848a4ec5054d7b11675 100644 (file)
@@ -61,6 +61,10 @@ static int secp256k1_wnaf_const(int *wnaf, secp256k1_scalar s, int w, int size)
     int bit;
     secp256k1_scalar neg_s;
     int not_neg_one;
+
+    VERIFY_CHECK(w > 0);
+    VERIFY_CHECK(size > 0);
+
     /* Note that we cannot handle even numbers by negating them to be odd, as is
      * done in other implementations, since if our scalars were specified to have
      * 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)
 
     /* 4 */
     u_last = secp256k1_scalar_shr_int(&s, w);
-    while (word * w < size) {
+    do {
         int sign;
         int even;
 
@@ -109,7 +113,7 @@ static int secp256k1_wnaf_const(int *wnaf, secp256k1_scalar s, int w, int size)
         wnaf[word++] = u_last * global_sign;
 
         u_last = u;
-    }
+    } while (word * w < size);
     wnaf[word] = u * global_sign;
 
     VERIFY_CHECK(secp256k1_scalar_is_zero(&s));
This page took 0.041485 seconds and 4 git commands to generate.