Skip to content

Commit 1a0f2ed

Browse files
committed
use reduce field element x modulo n, use secp256k1_scalar_eq over memcmp
1 parent 2fcd799 commit 1a0f2ed

File tree

1 file changed

+5
-7
lines changed

1 file changed

+5
-7
lines changed

src/modules/ecdsa_sign_to_contract/main_impl.h

+5-7
Original file line numberDiff line numberDiff line change
@@ -39,9 +39,8 @@ int secp256k1_ecdsa_s2c_sign(const secp256k1_context *ctx, secp256k1_ecdsa_signa
3939
int secp256k1_ecdsa_s2c_verify_commit(const secp256k1_context* ctx, const secp256k1_ecdsa_signature *sig, const unsigned char *data32, const secp256k1_s2c_opening *opening) {
4040
secp256k1_pubkey commitment;
4141
secp256k1_ge commitment_ge;
42-
unsigned char x_bytes1[32];
43-
unsigned char x_bytes2[32];
44-
secp256k1_scalar sigr, sigs;
42+
unsigned char x_bytes[32];
43+
secp256k1_scalar sigr, sigs, x_scalar;
4544

4645
VERIFY_CHECK(ctx != NULL);
4746
ARG_CHECK(sig != NULL);
@@ -67,10 +66,9 @@ int secp256k1_ecdsa_s2c_verify_commit(const secp256k1_context* ctx, const secp25
6766
return 0;
6867
}
6968
secp256k1_fe_normalize(&commitment_ge.x);
70-
secp256k1_fe_get_b32(x_bytes1, &commitment_ge.x);
71-
secp256k1_scalar_get_b32(x_bytes2, &sigr);
72-
return memcmp(x_bytes1, x_bytes2, 32) == 0;
73-
69+
secp256k1_fe_get_b32(x_bytes, & commitment_ge.x);
70+
secp256k1_scalar_set_b32(&x_scalar, x_bytes, NULL);
71+
return secp256k1_scalar_eq(&sigr, &x_scalar);
7472
}
7573
int secp256k1_ecdsa_s2c_anti_nonce_covert_channel_host_commit(secp256k1_context *ctx, unsigned char *rand_commitment32, const unsigned char *rand32) {
7674
secp256k1_sha256 sha;

0 commit comments

Comments
 (0)