@@ -109,7 +109,7 @@ int secp256k1_borromean_verify(secp256k1_scalar *evalues, const unsigned char *e
109109}
110110
111111int secp256k1_borromean_sign (const secp256k1_ecmult_gen_context * ecmult_gen_ctx ,
112- unsigned char * e0 , secp256k1_scalar * s , const secp256k1_gej * pubs , const secp256k1_scalar * k , const secp256k1_scalar * sec ,
112+ unsigned char * e0 , secp256k1_scalar * s , const secp256k1_gej * pubs , const secp256k1_scalar * sec ,
113113 const size_t * rsizes , const size_t * secidx , size_t nrings , const unsigned char * m , size_t mlen ) {
114114 secp256k1_gej rgej ;
115115 secp256k1_ge rge ;
@@ -125,7 +125,6 @@ int secp256k1_borromean_sign(const secp256k1_ecmult_gen_context *ecmult_gen_ctx,
125125 VERIFY_CHECK (e0 != NULL );
126126 VERIFY_CHECK (s != NULL );
127127 VERIFY_CHECK (pubs != NULL );
128- VERIFY_CHECK (k != NULL );
129128 VERIFY_CHECK (sec != NULL );
130129 VERIFY_CHECK (rsizes != NULL );
131130 VERIFY_CHECK (secidx != NULL );
@@ -135,7 +134,8 @@ int secp256k1_borromean_sign(const secp256k1_ecmult_gen_context *ecmult_gen_ctx,
135134 count = 0 ;
136135 for (i = 0 ; i < nrings ; i ++ ) {
137136 VERIFY_CHECK (INT_MAX - count > rsizes [i ]);
138- secp256k1_ecmult_gen (ecmult_gen_ctx , & rgej , & k [i ]);
137+ /* We have been provided an s value that we will just overwrite, so use it as a nonce */
138+ secp256k1_ecmult_gen (ecmult_gen_ctx , & rgej , & s [count + secidx [i ]]);
139139 secp256k1_ge_set_gej (& rge , & rgej );
140140 if (secp256k1_gej_is_infinity (& rgej )) {
141141 return 0 ;
@@ -165,6 +165,10 @@ int secp256k1_borromean_sign(const secp256k1_ecmult_gen_context *ecmult_gen_ctx,
165165 secp256k1_sha256_finalize (& sha256_e0 , e0 );
166166 count = 0 ;
167167 for (i = 0 ; i < nrings ; i ++ ) {
168+ /* We have been provided an s value that we will just overwrite, so use it as a nonce */
169+ secp256k1_scalar k = s [count + secidx [i ]];
170+ secp256k1_scalar_clear (& s [count + secidx [i ]]);
171+
168172 VERIFY_CHECK (INT_MAX - count > rsizes [i ]);
169173 secp256k1_borromean_hash (tmp , m , mlen , e0 , 32 , i , 0 );
170174 secp256k1_scalar_set_b32 (& ens , tmp , & overflow );
@@ -186,7 +190,7 @@ int secp256k1_borromean_sign(const secp256k1_ecmult_gen_context *ecmult_gen_ctx,
186190 }
187191 secp256k1_scalar_mul (& s [count + j ], & ens , & sec [i ]);
188192 secp256k1_scalar_negate (& s [count + j ], & s [count + j ]);
189- secp256k1_scalar_add (& s [count + j ], & s [count + j ], & k [ i ] );
193+ secp256k1_scalar_add (& s [count + j ], & s [count + j ], & k );
190194 if (secp256k1_scalar_is_zero (& s [count + j ])) {
191195 return 0 ;
192196 }
0 commit comments