Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

fix(crypto): secp256k1 cgo duplicate symbols #18306

Closed
wants to merge 33 commits into from
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
33 commits
Select commit Hold shift + click to select a range
4d2cca5
rename secp256k1_ec_pubkey_serialize
JulianToledano Oct 30, 2023
84abbb3
rename secp256k1_ec_privkey_tweak_mul
JulianToledano Oct 30, 2023
13c7c26
rename secp256k1_ecdsa_signature_parse_compact
JulianToledano Oct 30, 2023
7dd2b3a
rename secp256k1_context_clone
JulianToledano Oct 30, 2023
a313664
rename secp256k1_ecdsa_recoverable_signature_convert
JulianToledano Oct 30, 2023
b124002
rename secp256k1_nonce_function_rfc6979
JulianToledano Oct 30, 2023
02a0014
rename secp256k1GoPanicIllegal
JulianToledano Oct 30, 2023
78f90df
rename secp256k1_ecdsa_sign
JulianToledano Oct 30, 2023
d602ade
rename secp256k1_ecdsa_signature_normalize
JulianToledano Oct 30, 2023
0fa942b
rename secp256k1_ec_pubkey_parse
JulianToledano Oct 30, 2023
b17ff60
rename secp256k1_ec_pubkey_tweak_mul
JulianToledano Oct 30, 2023
298dc6f
rename secp256k1_context_set_illegal_callback
JulianToledano Oct 30, 2023
3ee3f0e
rename secp256k1_ecdsa_recover
JulianToledano Oct 30, 2023
ecd554c
rename secp256k1_ec_pubkey_tweak_add
JulianToledano Oct 30, 2023
89a0bb5
rename secp256k1_ext_scalar_mul
JulianToledano Oct 30, 2023
2ace469
rename secp256k1_ec_seckey_verify
JulianToledano Oct 30, 2023
6a53946
rename secp256k1_context_create
JulianToledano Oct 30, 2023
bd68e8f
rename secp256k1_ecdsa_verify
JulianToledano Oct 30, 2023
10a780d
rename secp256k1_context_destroy
JulianToledano Oct 30, 2023
ff8def8
rename secp256k1GoPanicError
JulianToledano Oct 30, 2023
88e8798
rename secp256k1_ecdsa_sign_recoverable
JulianToledano Oct 30, 2023
bd68d30
rename secp256k1_ecdsa_recoverable_signature_parse_compact
JulianToledano Oct 30, 2023
2b4f437
rename CURVE_B
JulianToledano Oct 30, 2023
9df6d67
rename secp256k1_ec_privkey_tweak_add
JulianToledano Oct 30, 2023
8b2f162
rename secp256k1_ecdsa_signature_serialize_compact
JulianToledano Oct 30, 2023
7653845
rename secp256k1_context_randomize
JulianToledano Oct 30, 2023
c1f8ac4
rename secp256k1_ecdsa_signature_parse_der
JulianToledano Oct 30, 2023
1085c17
rename secp256k1_ec_pubkey_combine
JulianToledano Oct 30, 2023
bee3192
rename secp256k1_ecdsa_recoverable_signature_serialize_compact
JulianToledano Oct 30, 2023
e02b5c5
rename secp256k1_ecdsa_signature_serialize_der
JulianToledano Oct 30, 2023
22c049b
rename secp256k1_ec_pubkey_create
JulianToledano Oct 30, 2023
90a90e8
rename secp256k1_nonce_function_default
JulianToledano Oct 30, 2023
44d0bdc
rename secp256k1_context_set_error_callback
JulianToledano Oct 30, 2023
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
22 changes: 11 additions & 11 deletions crypto/keys/secp256k1/internal/secp256k1/ext.h
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@

// secp256k1_context_create_sign_verify creates a context for signing and signature verification.
static secp256k1_context* secp256k1_context_create_sign_verify() {
return secp256k1_context_create(SECP256K1_CONTEXT_SIGN | SECP256K1_CONTEXT_VERIFY);
return cosmos_secp256k1_context_create(SECP256K1_CONTEXT_SIGN | SECP256K1_CONTEXT_VERIFY);
}

// secp256k1_ext_ecdsa_recover recovers the public key of an encoded compact signature.
Expand All @@ -24,14 +24,14 @@ static int secp256k1_ext_ecdsa_recover(
secp256k1_ecdsa_recoverable_signature sig;
secp256k1_pubkey pubkey;

if (!secp256k1_ecdsa_recoverable_signature_parse_compact(ctx, &sig, sigdata, (int)sigdata[64])) {
if (!cosmos_secp256k1_ecdsa_recoverable_signature_parse_compact(ctx, &sig, sigdata, (int)sigdata[64])) {
return 0;
}
if (!secp256k1_ecdsa_recover(ctx, &pubkey, &sig, msgdata)) {
if (!cosmos_secp256k1_ecdsa_recover(ctx, &pubkey, &sig, msgdata)) {
return 0;
}
size_t outputlen = 65;
return secp256k1_ec_pubkey_serialize(ctx, pubkey_out, &outputlen, &pubkey, SECP256K1_EC_UNCOMPRESSED);
return cosmos_secp256k1_ec_pubkey_serialize(ctx, pubkey_out, &outputlen, &pubkey, SECP256K1_EC_UNCOMPRESSED);
}

// secp256k1_ext_ecdsa_verify verifies an encoded compact signature.
Expand All @@ -53,13 +53,13 @@ static int secp256k1_ext_ecdsa_verify(
secp256k1_ecdsa_signature sig;
secp256k1_pubkey pubkey;

if (!secp256k1_ecdsa_signature_parse_compact(ctx, &sig, sigdata)) {
if (!cosmos_secp256k1_ecdsa_signature_parse_compact(ctx, &sig, sigdata)) {
return 0;
}
if (!secp256k1_ec_pubkey_parse(ctx, &pubkey, pubkeydata, pubkeylen)) {
if (!cosmos_secp256k1_ec_pubkey_parse(ctx, &pubkey, pubkeydata, pubkeylen)) {
return 0;
}
return secp256k1_ecdsa_verify(ctx, &sig, msgdata, &pubkey);
return cosmos_secp256k1_ecdsa_verify(ctx, &sig, msgdata, &pubkey);
}

// secp256k1_ext_reencode_pubkey decodes then encodes a public key. It can be used to
Expand All @@ -82,14 +82,14 @@ static int secp256k1_ext_reencode_pubkey(
) {
secp256k1_pubkey pubkey;

if (!secp256k1_ec_pubkey_parse(ctx, &pubkey, pubkeydata, pubkeylen)) {
if (!cosmos_secp256k1_ec_pubkey_parse(ctx, &pubkey, pubkeydata, pubkeylen)) {
return 0;
}
unsigned int flag = (outlen == 33) ? SECP256K1_EC_COMPRESSED : SECP256K1_EC_UNCOMPRESSED;
return secp256k1_ec_pubkey_serialize(ctx, out, &outlen, &pubkey, flag);
return cosmos_secp256k1_ec_pubkey_serialize(ctx, out, &outlen, &pubkey, flag);
}

// secp256k1_ext_scalar_mul multiplies a point by a scalar in constant time.
// cosmos_secp256k1_ext_scalar_mul multiplies a point by a scalar in constant time.
//
// Returns: 1: multiplication was successful
// 0: scalar was invalid (zero or overflow)
Expand All @@ -98,7 +98,7 @@ static int secp256k1_ext_reencode_pubkey(
// In: point: pointer to a 64-byte public point,
// encoded as two 256bit big-endian numbers.
// scalar: a 32-byte scalar with which to multiply the point
int secp256k1_ext_scalar_mul(const secp256k1_context* ctx, unsigned char *point, const unsigned char *scalar) {
int cosmos_secp256k1_ext_scalar_mul(const secp256k1_context* ctx, unsigned char *point, const unsigned char *scalar) {
int ret = 0;
int overflow = 0;
secp256k1_fe feX, feY;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,7 @@ int ecdsa_signature_parse_der_lax(const secp256k1_context* ctx, secp256k1_ecdsa_
int overflow = 0;

/* Hack to initialize sig with a correctly-parsed but invalid signature. */
secp256k1_ecdsa_signature_parse_compact(ctx, sig, tmpsig);
cosmos_secp256k1_ecdsa_signature_parse_compact(ctx, sig, tmpsig);

/* Sequence tag byte */
if (pos == inputlen || input[pos] != 0x30) {
Expand Down Expand Up @@ -139,11 +139,11 @@ int ecdsa_signature_parse_der_lax(const secp256k1_context* ctx, secp256k1_ecdsa_
}

if (!overflow) {
overflow = !secp256k1_ecdsa_signature_parse_compact(ctx, sig, tmpsig);
overflow = !cosmos_secp256k1_ecdsa_signature_parse_compact(ctx, sig, tmpsig);
}
if (overflow) {
memset(tmpsig, 0, 64);
secp256k1_ecdsa_signature_parse_compact(ctx, sig, tmpsig);
cosmos_secp256k1_ecdsa_signature_parse_compact(ctx, sig, tmpsig);
}
return 1;
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -26,8 +26,8 @@
* certain violations are easily supported. You may need to adapt it.
*
* Do not use this for new systems. Use well-defined DER or compact signatures
* instead if you have the choice (see secp256k1_ecdsa_signature_parse_der and
* secp256k1_ecdsa_signature_parse_compact).
* instead if you have the choice (see cosmos_secp256k1_ecdsa_signature_parse_der and
* cosmos_secp256k1_ecdsa_signature_parse_compact).
*
* The supported violations are:
* - All numbers are parsed as nonnegative integers, even though X.609-0207
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -46,7 +46,7 @@ int ec_privkey_import_der(const secp256k1_context* ctx, unsigned char *out32, co
return 0;
}
memcpy(out32 + 32 - privkey[1], privkey + 2, privkey[1]);
if (!secp256k1_ec_seckey_verify(ctx, out32)) {
if (!cosmos_secp256k1_ec_seckey_verify(ctx, out32)) {
memset(out32, 0, 32);
return 0;
}
Expand All @@ -56,7 +56,7 @@ int ec_privkey_import_der(const secp256k1_context* ctx, unsigned char *out32, co
int ec_privkey_export_der(const secp256k1_context *ctx, unsigned char *privkey, size_t *privkeylen, const unsigned char *key32, int compressed) {
secp256k1_pubkey pubkey;
size_t pubkeylen = 0;
if (!secp256k1_ec_pubkey_create(ctx, &pubkey, key32)) {
if (!cosmos_secp256k1_ec_pubkey_create(ctx, &pubkey, key32)) {
*privkeylen = 0;
return 0;
}
Expand All @@ -80,7 +80,7 @@ int ec_privkey_export_der(const secp256k1_context *ctx, unsigned char *privkey,
memcpy(ptr, key32, 32); ptr += 32;
memcpy(ptr, middle, sizeof(middle)); ptr += sizeof(middle);
pubkeylen = 33;
secp256k1_ec_pubkey_serialize(ctx, ptr, &pubkeylen, &pubkey, SECP256K1_EC_COMPRESSED);
cosmos_secp256k1_ec_pubkey_serialize(ctx, ptr, &pubkeylen, &pubkey, SECP256K1_EC_COMPRESSED);
ptr += pubkeylen;
*privkeylen = ptr - privkey;
} else {
Expand All @@ -105,7 +105,7 @@ int ec_privkey_export_der(const secp256k1_context *ctx, unsigned char *privkey,
memcpy(ptr, key32, 32); ptr += 32;
memcpy(ptr, middle, sizeof(middle)); ptr += sizeof(middle);
pubkeylen = 65;
secp256k1_ec_pubkey_serialize(ctx, ptr, &pubkeylen, &pubkey, SECP256K1_EC_UNCOMPRESSED);
cosmos_secp256k1_ec_pubkey_serialize(ctx, ptr, &pubkeylen, &pubkey, SECP256K1_EC_UNCOMPRESSED);
ptr += pubkeylen;
*privkeylen = ptr - privkey;
}
Expand Down
Loading