14 #ifdef ENABLE_OPENSSL_TESTS 15 #include <openssl/bn.h> 16 #include <openssl/ecdsa.h> 17 #include <openssl/obj_mac.h> 22 unsigned char msg[32];
23 unsigned char key[32];
24 unsigned char sig[72];
26 unsigned char pubkey[33];
28 #ifdef ENABLE_OPENSSL_TESTS 33 static void benchmark_verify(
void* arg) {
37 for (i = 0; i < 20000; i++) {
40 data->
sig[data->
siglen - 1] ^= (i & 0xFF);
41 data->
sig[data->
siglen - 2] ^= ((i >> 8) & 0xFF);
42 data->
sig[data->
siglen - 3] ^= ((i >> 16) & 0xFF);
46 data->
sig[data->
siglen - 1] ^= (i & 0xFF);
47 data->
sig[data->
siglen - 2] ^= ((i >> 8) & 0xFF);
48 data->
sig[data->
siglen - 3] ^= ((i >> 16) & 0xFF);
52 #ifdef ENABLE_OPENSSL_TESTS 53 static void benchmark_verify_openssl(
void* arg) {
57 for (i = 0; i < 20000; i++) {
58 data->
sig[data->
siglen - 1] ^= (i & 0xFF);
59 data->
sig[data->
siglen - 2] ^= ((i >> 8) & 0xFF);
60 data->
sig[data->
siglen - 3] ^= ((i >> 16) & 0xFF);
62 EC_KEY *pkey = EC_KEY_new();
63 const unsigned char *pubkey = &data->
pubkey[0];
67 result = EC_KEY_set_group(pkey, data->ec_group);
69 result = (o2i_ECPublicKey(&pkey, &pubkey, data->
pubkeylen)) != NULL;
71 result = ECDSA_verify(0, &data->
msg[0],
sizeof(data->
msg), &data->
sig[0], data->
siglen, pkey) == (i == 0);
75 data->
sig[data->
siglen - 1] ^= (i & 0xFF);
76 data->
sig[data->
siglen - 2] ^= ((i >> 8) & 0xFF);
77 data->
sig[data->
siglen - 3] ^= ((i >> 16) & 0xFF);
90 for (i = 0; i < 32; i++) {
93 for (i = 0; i < 32; i++) {
103 run_benchmark(
"ecdsa_verify", benchmark_verify, NULL, NULL, &data, 10, 20000);
104 #ifdef ENABLE_OPENSSL_TESTS 105 data.ec_group = EC_GROUP_new_by_curve_name(NID_secp256k1);
106 run_benchmark(
"ecdsa_verify_openssl", benchmark_verify_openssl, NULL, NULL, &data, 10, 20000);
107 EC_GROUP_free(data.ec_group);
SECP256K1_API int secp256k1_ec_pubkey_serialize(const secp256k1_context *ctx, unsigned char *output, size_t *outputlen, const secp256k1_pubkey *pubkey, unsigned int flags) SECP256K1_ARG_NONNULL(1) SECP256K1_ARG_NONNULL(2) SECP256K1_ARG_NONNULL(3) SECP256K1_ARG_NONNULL(4)
Serialize a pubkey object into a serialized byte sequence.
#define SECP256K1_CONTEXT_SIGN
SECP256K1_API void secp256k1_context_destroy(secp256k1_context *ctx)
Destroy a secp256k1 context object.
SECP256K1_API SECP256K1_WARN_UNUSED_RESULT int secp256k1_ec_pubkey_create(const secp256k1_context *ctx, secp256k1_pubkey *pubkey, const unsigned char *seckey) SECP256K1_ARG_NONNULL(1) SECP256K1_ARG_NONNULL(2) SECP256K1_ARG_NONNULL(3)
Compute the public key for a secret key.
#define SECP256K1_EC_COMPRESSED
Flag to pass to secp256k1_ec_pubkey_serialize and secp256k1_ec_privkey_export.
void run_benchmark(char *name, void(*benchmark)(void *), void(*setup)(void *), void(*teardown)(void *), void *data, int count, int iter)
SECP256K1_API int secp256k1_ecdsa_sign(const secp256k1_context *ctx, secp256k1_ecdsa_signature *sig, const unsigned char *msg32, const unsigned char *seckey, secp256k1_nonce_function noncefp, const void *ndata) SECP256K1_ARG_NONNULL(1) SECP256K1_ARG_NONNULL(2) SECP256K1_ARG_NONNULL(3) SECP256K1_ARG_NONNULL(4)
Create an ECDSA signature.
SECP256K1_API SECP256K1_WARN_UNUSED_RESULT int secp256k1_ec_pubkey_parse(const secp256k1_context *ctx, secp256k1_pubkey *pubkey, const unsigned char *input, size_t inputlen) SECP256K1_ARG_NONNULL(1) SECP256K1_ARG_NONNULL(2) SECP256K1_ARG_NONNULL(3)
Parse a variable-length public key into the pubkey object.
Opaque data structured that holds a parsed ECDSA signature.
SECP256K1_API int secp256k1_ecdsa_signature_parse_der(const secp256k1_context *ctx, secp256k1_ecdsa_signature *sig, const unsigned char *input, size_t inputlen) SECP256K1_ARG_NONNULL(1) SECP256K1_ARG_NONNULL(2) SECP256K1_ARG_NONNULL(3)
Parse a DER ECDSA signature.
#define SECP256K1_CONTEXT_VERIFY
Flags to pass to secp256k1_context_create.
SECP256K1_API int secp256k1_ecdsa_signature_serialize_der(const secp256k1_context *ctx, unsigned char *output, size_t *outputlen, const secp256k1_ecdsa_signature *sig) SECP256K1_ARG_NONNULL(1) SECP256K1_ARG_NONNULL(2) SECP256K1_ARG_NONNULL(3) SECP256K1_ARG_NONNULL(4)
Serialize an ECDSA signature in DER format.
SECP256K1_API secp256k1_context * secp256k1_context_create(unsigned int flags) SECP256K1_WARN_UNUSED_RESULT
Create a secp256k1 context object.
Opaque data structure that holds a parsed and valid public key.
SECP256K1_API SECP256K1_WARN_UNUSED_RESULT int secp256k1_ecdsa_verify(const secp256k1_context *ctx, const secp256k1_ecdsa_signature *sig, const unsigned char *msg32, const secp256k1_pubkey *pubkey) SECP256K1_ARG_NONNULL(1) SECP256K1_ARG_NONNULL(2) SECP256K1_ARG_NONNULL(3) SECP256K1_ARG_NONNULL(4)
Verify an ECDSA signature.