Skip to content

Commit d93380f

Browse files
Merge #1731: schnorrsig: Securely clear buf containing k or its negation
325d65a Rename and clear var containing k or -k (John Moffett) Pull request description: Follow-up to #1579. `buf` still holds the nonce or its negation, so ought to be cleared. ACKs for top commit: theStack: Code review re-ACK 325d65a real-or-random: utACK 325d65a Tree-SHA512: a2fe39d7c44cebc0abe712828d521c2a7aba1db2d9dc5fc811dcaf96f1e45494dba5d7f016b6d9200ab523641ff62083686dbc942284e0f548183aaf60d8bfa2
2 parents 8113671 + 325d65a commit d93380f

File tree

1 file changed

+4
-3
lines changed

1 file changed

+4
-3
lines changed

src/modules/schnorrsig/main_impl.h

Lines changed: 4 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -139,7 +139,7 @@ static int secp256k1_schnorrsig_sign_internal(const secp256k1_context* ctx, unsi
139139
secp256k1_gej rj;
140140
secp256k1_ge pk;
141141
secp256k1_ge r;
142-
unsigned char buf[32] = { 0 };
142+
unsigned char nonce32[32] = { 0 };
143143
unsigned char pk_buf[32];
144144
unsigned char seckey[32];
145145
int ret = 1;
@@ -164,8 +164,8 @@ static int secp256k1_schnorrsig_sign_internal(const secp256k1_context* ctx, unsi
164164

165165
secp256k1_scalar_get_b32(seckey, &sk);
166166
secp256k1_fe_get_b32(pk_buf, &pk.x);
167-
ret &= !!noncefp(buf, msg, msglen, seckey, pk_buf, bip340_algo, sizeof(bip340_algo), ndata);
168-
secp256k1_scalar_set_b32(&k, buf, NULL);
167+
ret &= !!noncefp(nonce32, msg, msglen, seckey, pk_buf, bip340_algo, sizeof(bip340_algo), ndata);
168+
secp256k1_scalar_set_b32(&k, nonce32, NULL);
169169
ret &= !secp256k1_scalar_is_zero(&k);
170170
secp256k1_scalar_cmov(&k, &secp256k1_scalar_one, !ret);
171171

@@ -191,6 +191,7 @@ static int secp256k1_schnorrsig_sign_internal(const secp256k1_context* ctx, unsi
191191
secp256k1_scalar_clear(&k);
192192
secp256k1_scalar_clear(&sk);
193193
secp256k1_memclear(seckey, sizeof(seckey));
194+
secp256k1_memclear(nonce32, sizeof(nonce32));
194195
secp256k1_gej_clear(&rj);
195196

196197
return ret;

0 commit comments

Comments
 (0)