Skip to content

Commit ffc0872

Browse files
committed
use reduce field element x modulo n, use secp256k1_scalar_eq over memcmp
1 parent f8c7f7e commit ffc0872

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
@@ -41,9 +41,8 @@ int secp256k1_ecdsa_s2c_sign(const secp256k1_context *ctx, secp256k1_ecdsa_signa
4141
int secp256k1_ecdsa_s2c_verify_commit(const secp256k1_context* ctx, const secp256k1_ecdsa_signature *sig, const unsigned char *data32, const secp256k1_s2c_opening *opening) {
4242
secp256k1_pubkey commitment;
4343
secp256k1_ge commitment_ge;
44-
unsigned char x_bytes1[32];
45-
unsigned char x_bytes2[32];
46-
secp256k1_scalar sigr, sigs;
44+
unsigned char x_bytes[32];
45+
secp256k1_scalar sigr, sigs, x_scalar;
4746

4847
VERIFY_CHECK(ctx != NULL);
4948
ARG_CHECK(sig != NULL);
@@ -69,10 +68,9 @@ int secp256k1_ecdsa_s2c_verify_commit(const secp256k1_context* ctx, const secp25
6968
return 0;
7069
}
7170
secp256k1_fe_normalize(&commitment_ge.x);
72-
secp256k1_fe_get_b32(x_bytes1, &commitment_ge.x);
73-
secp256k1_scalar_get_b32(x_bytes2, &sigr);
74-
return memcmp(x_bytes1, x_bytes2, 32) == 0;
75-
71+
secp256k1_fe_get_b32(x_bytes, & commitment_ge.x);
72+
secp256k1_scalar_set_b32(&x_scalar, x_bytes, NULL);
73+
return secp256k1_scalar_eq(&sigr, &x_scalar);
7674
}
7775
int secp256k1_ecdsa_s2c_anti_nonce_covert_channel_host_commit(secp256k1_context *ctx, unsigned char *rand_commitment32, const unsigned char *rand32) {
7876
secp256k1_sha256 sha;

0 commit comments

Comments
 (0)