add secp256k1_ec_pubkey_cmp method
This commit is contained in:
@@ -316,6 +316,32 @@ int secp256k1_ec_pubkey_serialize(const secp256k1_context* ctx, unsigned char *o
|
||||
return ret;
|
||||
}
|
||||
|
||||
int secp256k1_ec_pubkey_cmp(const secp256k1_context* ctx, const secp256k1_pubkey* pubkey0, const secp256k1_pubkey* pubkey1) {
|
||||
unsigned char out[2][33];
|
||||
const secp256k1_pubkey* pk[2];
|
||||
int i;
|
||||
|
||||
VERIFY_CHECK(ctx != NULL);
|
||||
pk[0] = pubkey0; pk[1] = pubkey1;
|
||||
for (i = 0; i < 2; i++) {
|
||||
size_t out_size = sizeof(out[i]);
|
||||
/* If the public key is NULL or invalid, ec_pubkey_serialize will call
|
||||
* the illegal_callback and return 0. In that case we will serialize the
|
||||
* key as all zeros which is less than any valid public key. This
|
||||
* results in consistent comparisons even if NULL or invalid pubkeys are
|
||||
* involved and prevents edge cases such as sorting algorithms that use
|
||||
* this function and do not terminate as a result. */
|
||||
if (!secp256k1_ec_pubkey_serialize(ctx, out[i], &out_size, pk[i], SECP256K1_EC_COMPRESSED)) {
|
||||
/* Note that ec_pubkey_serialize should already set the output to
|
||||
* zero in that case, but it's not guaranteed by the API, we can't
|
||||
* test it and writing a VERIFY_CHECK is more complex than
|
||||
* explicitly memsetting (again). */
|
||||
memset(out[i], 0, sizeof(out[i]));
|
||||
}
|
||||
}
|
||||
return secp256k1_memcmp_var(out[0], out[1], sizeof(out[0]));
|
||||
}
|
||||
|
||||
static void secp256k1_ecdsa_signature_load(const secp256k1_context* ctx, secp256k1_scalar* r, secp256k1_scalar* s, const secp256k1_ecdsa_signature* sig) {
|
||||
(void)ctx;
|
||||
if (sizeof(secp256k1_scalar) == 32) {
|
||||
|
||||
Reference in New Issue
Block a user