diff options
author | Felix Lange <fjl@users.noreply.github.com> | 2017-12-06 23:07:08 +0800 |
---|---|---|
committer | GitHub <noreply@github.com> | 2017-12-06 23:07:08 +0800 |
commit | e85b68ef53e80eb66c7ab394c57e9eb146a60b91 (patch) | |
tree | 92a728f14c9a0d42b50f2410d3c67a46795364d6 /crypto/secp256k1/ext.h | |
parent | 6e613cf3de6ebfd14edd5a332baf6e4079c1c86f (diff) | |
download | dexon-e85b68ef53e80eb66c7ab394c57e9eb146a60b91.tar dexon-e85b68ef53e80eb66c7ab394c57e9eb146a60b91.tar.gz dexon-e85b68ef53e80eb66c7ab394c57e9eb146a60b91.tar.bz2 dexon-e85b68ef53e80eb66c7ab394c57e9eb146a60b91.tar.lz dexon-e85b68ef53e80eb66c7ab394c57e9eb146a60b91.tar.xz dexon-e85b68ef53e80eb66c7ab394c57e9eb146a60b91.tar.zst dexon-e85b68ef53e80eb66c7ab394c57e9eb146a60b91.zip |
crypto: add DecompressPubkey, VerifySignature (#15615)
We need those operations for p2p/enr.
Also upgrade github.com/btcsuite/btcd/btcec to the latest version
and improve BenchmarkSha3. The benchmark printed extra output
that confused tools like benchstat and ignored N.
Diffstat (limited to 'crypto/secp256k1/ext.h')
-rw-r--r-- | crypto/secp256k1/ext.h | 49 |
1 files changed, 49 insertions, 0 deletions
diff --git a/crypto/secp256k1/ext.h b/crypto/secp256k1/ext.h index ee759fde6..b0f30b73c 100644 --- a/crypto/secp256k1/ext.h +++ b/crypto/secp256k1/ext.h @@ -46,6 +46,55 @@ static int secp256k1_ecdsa_recover_pubkey( return secp256k1_ec_pubkey_serialize(ctx, pubkey_out, &outputlen, &pubkey, SECP256K1_EC_UNCOMPRESSED); } +// secp256k1_ecdsa_verify_enc verifies an encoded compact signature. +// +// Returns: 1: signature is valid +// 0: signature is invalid +// Args: ctx: pointer to a context object (cannot be NULL) +// In: sigdata: pointer to a 64-byte signature (cannot be NULL) +// msgdata: pointer to a 32-byte message (cannot be NULL) +// pubkeydata: pointer to public key data (cannot be NULL) +// pubkeylen: length of pubkeydata +static int secp256k1_ecdsa_verify_enc( + const secp256k1_context* ctx, + const unsigned char *sigdata, + const unsigned char *msgdata, + const unsigned char *pubkeydata, + size_t pubkeylen +) { + secp256k1_ecdsa_signature sig; + secp256k1_pubkey pubkey; + + if (!secp256k1_ecdsa_signature_parse_compact(ctx, &sig, sigdata)) { + return 0; + } + if (!secp256k1_ec_pubkey_parse(ctx, &pubkey, pubkeydata, pubkeylen)) { + return 0; + } + return secp256k1_ecdsa_verify(ctx, &sig, msgdata, &pubkey); +} + +// secp256k1_decompress_pubkey decompresses a public key. +// +// Returns: 1: public key is valid +// 0: public key is invalid +// Args: ctx: pointer to a context object (cannot be NULL) +// Out: pubkey_out: the serialized 65-byte public key (cannot be NULL) +// In: pubkeydata: pointer to 33 bytes of compressed public key data (cannot be NULL) +static int secp256k1_decompress_pubkey( + const secp256k1_context* ctx, + unsigned char *pubkey_out, + const unsigned char *pubkeydata +) { + secp256k1_pubkey pubkey; + + if (!secp256k1_ec_pubkey_parse(ctx, &pubkey, pubkeydata, 33)) { + return 0; + } + size_t outputlen = 65; + return secp256k1_ec_pubkey_serialize(ctx, pubkey_out, &outputlen, &pubkey, SECP256K1_EC_UNCOMPRESSED); +} + // secp256k1_pubkey_scalar_mul multiplies a point by a scalar in constant time. // // Returns: 1: multiplication was successful |