@@ -40,22 +40,21 @@ static void secp256k1_ecmult_gen_context_clear(secp256k1_ecmult_gen_context *ctx
40
40
* precomputed (call it prec(i, n_i)). The formula now becomes sum(prec(i, n_i), i=0 ... PREC_N-1).
41
41
* None of the resulting prec group elements have a known scalar, and neither do any of
42
42
* the intermediate sums while computing a*G.
43
- * The prec values are stored in secp256k1_ecmult_gen_prec_table[j][i ] = (PREC_G)^j * i * G + U_i.
43
+ * The prec values are stored in secp256k1_ecmult_gen_prec_table[i][n_i ] = n_i * (PREC_G)^i * G + U_i.
44
44
*/
45
45
static void secp256k1_ecmult_gen (const secp256k1_ecmult_gen_context * ctx , secp256k1_gej * r , const secp256k1_scalar * gn ) {
46
46
secp256k1_ge add ;
47
47
secp256k1_ge_storage adds ;
48
48
secp256k1_scalar gnb ;
49
- int bits ;
50
- int i , j ;
49
+ int i , j , n_i ;
51
50
memset (& adds , 0 , sizeof (adds ));
52
51
* r = ctx -> initial ;
53
52
/* Blind scalar/point multiplication by computing (n-b)G + bG instead of nG. */
54
53
secp256k1_scalar_add (& gnb , gn , & ctx -> blind );
55
54
add .infinity = 0 ;
56
- for (j = 0 ; j < ECMULT_GEN_PREC_N ; j ++ ) {
57
- bits = secp256k1_scalar_get_bits (& gnb , j * ECMULT_GEN_PREC_B , ECMULT_GEN_PREC_B );
58
- for (i = 0 ; i < ECMULT_GEN_PREC_G ; i ++ ) {
55
+ for (i = 0 ; i < ECMULT_GEN_PREC_N ; i ++ ) {
56
+ n_i = secp256k1_scalar_get_bits (& gnb , i * ECMULT_GEN_PREC_B , ECMULT_GEN_PREC_B );
57
+ for (j = 0 ; j < ECMULT_GEN_PREC_G ; j ++ ) {
59
58
/** This uses a conditional move to avoid any secret data in array indexes.
60
59
* _Any_ use of secret indexes has been demonstrated to result in timing
61
60
* sidechannels, even when the cache-line access patterns are uniform.
@@ -66,12 +65,12 @@ static void secp256k1_ecmult_gen(const secp256k1_ecmult_gen_context *ctx, secp25
66
65
* by Dag Arne Osvik, Adi Shamir, and Eran Tromer
67
66
* (https://www.tau.ac.il/~tromer/papers/cache.pdf)
68
67
*/
69
- secp256k1_ge_storage_cmov (& adds , & secp256k1_ecmult_gen_prec_table [j ][ i ], i == bits );
68
+ secp256k1_ge_storage_cmov (& adds , & secp256k1_ecmult_gen_prec_table [i ][ j ], j == n_i );
70
69
}
71
70
secp256k1_ge_from_storage (& add , & adds );
72
71
secp256k1_gej_add_ge (r , r , & add );
73
72
}
74
- bits = 0 ;
73
+ n_i = 0 ;
75
74
secp256k1_ge_clear (& add );
76
75
secp256k1_scalar_clear (& gnb );
77
76
}
0 commit comments