Merge pull request #250
210ffed Use separate in and out pointers in `secp256k1_ec_pubkey_decompress` (Andrew Poelstra)
This commit is contained in:
@@ -271,15 +271,16 @@ int secp256k1_ec_pubkey_create(const secp256k1_context_t* ctx, unsigned char *pu
|
||||
return ret;
|
||||
}
|
||||
|
||||
int secp256k1_ec_pubkey_decompress(const secp256k1_context_t* ctx, unsigned char *pubkey, int *pubkeylen) {
|
||||
int secp256k1_ec_pubkey_decompress(const secp256k1_context_t* ctx, const unsigned char *pubkeyin, unsigned char *pubkeyout, int *pubkeylen) {
|
||||
secp256k1_ge_t p;
|
||||
int ret = 0;
|
||||
DEBUG_CHECK(pubkey != NULL);
|
||||
DEBUG_CHECK(pubkeyin != NULL);
|
||||
DEBUG_CHECK(pubkeyout != NULL);
|
||||
DEBUG_CHECK(pubkeylen != NULL);
|
||||
(void)ctx;
|
||||
|
||||
if (secp256k1_eckey_pubkey_parse(&p, pubkey, *pubkeylen)) {
|
||||
ret = secp256k1_eckey_pubkey_serialize(&p, pubkey, pubkeylen, 0);
|
||||
if (secp256k1_eckey_pubkey_parse(&p, pubkeyin, *pubkeylen)) {
|
||||
ret = secp256k1_eckey_pubkey_serialize(&p, pubkeyout, pubkeylen, 0);
|
||||
}
|
||||
return ret;
|
||||
}
|
||||
|
||||
14
src/tests.c
14
src/tests.c
@@ -1511,7 +1511,19 @@ void test_ecdsa_end_to_end(void) {
|
||||
CHECK(secp256k1_ec_seckey_verify(ctx, privkey) == 1);
|
||||
CHECK(secp256k1_ec_pubkey_create(ctx, pubkey, &pubkeylen, privkey, (secp256k1_rand32() & 3) != 0) == 1);
|
||||
if (secp256k1_rand32() & 1) {
|
||||
CHECK(secp256k1_ec_pubkey_decompress(ctx, pubkey, &pubkeylen));
|
||||
unsigned char pubkey2[65] = {0};
|
||||
int pubkey2len = pubkeylen;
|
||||
/* Decompress into a new array */
|
||||
CHECK(secp256k1_ec_pubkey_decompress(ctx, pubkey, pubkey2, &pubkey2len));
|
||||
/* Check that the key was changed iff it was originally compressed */
|
||||
if (pubkeylen == 65) {
|
||||
CHECK(memcmp(pubkey, pubkey2, 65) == 0);
|
||||
} else {
|
||||
CHECK(memcmp(pubkey, pubkey2, 65) != 0);
|
||||
}
|
||||
/* Decompress in place */
|
||||
CHECK(secp256k1_ec_pubkey_decompress(ctx, pubkey, pubkey, &pubkeylen));
|
||||
CHECK(memcmp(pubkey, pubkey2, 65) == 0);
|
||||
}
|
||||
CHECK(secp256k1_ec_pubkey_verify(ctx, pubkey, pubkeylen));
|
||||
|
||||
|
||||
Reference in New Issue
Block a user