7#include <valgrind/memcheck.h>
14#ifdef ENABLE_MODULE_ECDH
18#ifdef ENABLE_MODULE_RECOVERY
22#ifdef ENABLE_MODULE_SCHNORR
26#ifdef ENABLE_MODULE_EXTRAKEYS
30#ifdef ENABLE_MODULE_SCHNORRSIG
38 unsigned char key[32];
41 if (!RUNNING_ON_VALGRIND) {
42 fprintf(stderr,
"This test can only usefully be run inside valgrind.\n");
43 fprintf(stderr,
"Usage: libtool --mode=execute valgrind ./valgrind_ctime_test\n");
52 for (i = 0; i < 32; i++) {
60 VALGRIND_MAKE_MEM_UNDEFINED(key, 32);
62 VALGRIND_MAKE_MEM_DEFINED(&ret,
sizeof(ret));
73 size_t outputlen = 33;
76 unsigned char msg[32];
77 unsigned char sig[74];
78 unsigned char spubkey[33];
79#ifdef ENABLE_MODULE_RECOVERY
83#ifdef ENABLE_MODULE_EXTRAKEYS
87 for (i = 0; i < 32; i++) {
92 VALGRIND_MAKE_MEM_UNDEFINED(key, 32);
95 VALGRIND_MAKE_MEM_DEFINED(&ret,
sizeof(ret));
100 VALGRIND_MAKE_MEM_UNDEFINED(key, 32);
103 VALGRIND_MAKE_MEM_DEFINED(&ret,
sizeof(ret));
107#ifdef ENABLE_MODULE_ECDH
109 VALGRIND_MAKE_MEM_UNDEFINED(key, 32);
111 VALGRIND_MAKE_MEM_DEFINED(&ret,
sizeof(ret));
115#ifdef ENABLE_MODULE_RECOVERY
117 VALGRIND_MAKE_MEM_UNDEFINED(key, 32);
119 VALGRIND_MAKE_MEM_DEFINED(&recoverable_signature,
sizeof(recoverable_signature));
120 VALGRIND_MAKE_MEM_DEFINED(&ret,
sizeof(ret));
123 CHECK(recid >= 0 && recid <= 3);
126#if ENABLE_MODULE_SCHNORR
128 VALGRIND_MAKE_MEM_UNDEFINED(key, 32);
130 VALGRIND_MAKE_MEM_DEFINED(&
sig,
sizeof(64));
131 VALGRIND_MAKE_MEM_DEFINED(&ret,
sizeof(ret));
135 VALGRIND_MAKE_MEM_UNDEFINED(key, 32);
137 VALGRIND_MAKE_MEM_DEFINED(&ret,
sizeof(ret));
140 VALGRIND_MAKE_MEM_UNDEFINED(key, 32);
142 VALGRIND_MAKE_MEM_DEFINED(&ret,
sizeof(ret));
145 VALGRIND_MAKE_MEM_UNDEFINED(key, 32);
146 VALGRIND_MAKE_MEM_UNDEFINED(msg, 32);
148 VALGRIND_MAKE_MEM_DEFINED(&ret,
sizeof(ret));
151 VALGRIND_MAKE_MEM_UNDEFINED(key, 32);
152 VALGRIND_MAKE_MEM_UNDEFINED(msg, 32);
154 VALGRIND_MAKE_MEM_DEFINED(&ret,
sizeof(ret));
158#ifdef ENABLE_MODULE_EXTRAKEYS
159 VALGRIND_MAKE_MEM_UNDEFINED(key, 32);
161 VALGRIND_MAKE_MEM_DEFINED(&ret,
sizeof(ret));
165 VALGRIND_MAKE_MEM_DEFINED(msg, 32);
167 VALGRIND_MAKE_MEM_DEFINED(&ret,
sizeof(ret));
170 VALGRIND_MAKE_MEM_UNDEFINED(key, 32);
171 VALGRIND_MAKE_MEM_UNDEFINED(&keypair,
sizeof(keypair));
173 VALGRIND_MAKE_MEM_DEFINED(&ret,
sizeof(ret));
177#ifdef ENABLE_MODULE_SCHNORRSIG
178 VALGRIND_MAKE_MEM_UNDEFINED(key, 32);
180 VALGRIND_MAKE_MEM_DEFINED(&ret,
sizeof(ret));
183 VALGRIND_MAKE_MEM_DEFINED(&ret,
sizeof(ret));
SECP256K1_API SECP256K1_WARN_UNUSED_RESULT int secp256k1_ec_seckey_tweak_mul(const secp256k1_context *ctx, unsigned char *seckey, const unsigned char *tweak32) SECP256K1_ARG_NONNULL(1) SECP256K1_ARG_NONNULL(2) SECP256K1_ARG_NONNULL(3)
Tweak a secret key by multiplying it by a tweak.
#define SECP256K1_CONTEXT_SIGN
SECP256K1_API SECP256K1_WARN_UNUSED_RESULT int secp256k1_context_randomize(secp256k1_context *ctx, const unsigned char *seed32) SECP256K1_ARG_NONNULL(1)
Updates the context randomization to protect against side-channel leakage.
#define SECP256K1_CONTEXT_DECLASSIFY
SECP256K1_API SECP256K1_WARN_UNUSED_RESULT int secp256k1_ec_seckey_negate(const secp256k1_context *ctx, unsigned char *seckey) SECP256K1_ARG_NONNULL(1) SECP256K1_ARG_NONNULL(2)
Negates a secret key in place.
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.
SECP256K1_API SECP256K1_WARN_UNUSED_RESULT int secp256k1_ec_seckey_verify(const secp256k1_context *ctx, const unsigned char *seckey) SECP256K1_ARG_NONNULL(1) SECP256K1_ARG_NONNULL(2)
Verify an ECDSA secret key.
SECP256K1_API secp256k1_context * secp256k1_context_create(unsigned int flags) SECP256K1_WARN_UNUSED_RESULT
Create a secp256k1 context object (in dynamically allocated memory).
SECP256K1_API int secp256k1_ecdsa_sign(const secp256k1_context *ctx, secp256k1_ecdsa_signature *sig, const unsigned char *msghash32, 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_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.
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.
#define SECP256K1_CONTEXT_VERIFY
Flags to pass to secp256k1_context_create, secp256k1_context_preallocated_size, and secp256k1_context...
SECP256K1_API SECP256K1_WARN_UNUSED_RESULT int secp256k1_ec_seckey_tweak_add(const secp256k1_context *ctx, unsigned char *seckey, const unsigned char *tweak32) SECP256K1_ARG_NONNULL(1) SECP256K1_ARG_NONNULL(2) SECP256K1_ARG_NONNULL(3)
Tweak a secret key by adding tweak to it.
SECP256K1_API void secp256k1_context_destroy(secp256k1_context *ctx)
Destroy a secp256k1 context object (created in dynamically allocated memory).
SECP256K1_API SECP256K1_WARN_UNUSED_RESULT int secp256k1_ecdh(const secp256k1_context *ctx, unsigned char *output, const secp256k1_pubkey *pubkey, const unsigned char *seckey, secp256k1_ecdh_hash_function hashfp, void *data) SECP256K1_ARG_NONNULL(1) SECP256K1_ARG_NONNULL(2) SECP256K1_ARG_NONNULL(3) SECP256K1_ARG_NONNULL(4)
Compute an EC Diffie-Hellman secret in constant time.
SECP256K1_API int secp256k1_ecdsa_recoverable_signature_serialize_compact(const secp256k1_context *ctx, unsigned char *output64, int *recid, const secp256k1_ecdsa_recoverable_signature *sig) SECP256K1_ARG_NONNULL(1) SECP256K1_ARG_NONNULL(2) SECP256K1_ARG_NONNULL(3) SECP256K1_ARG_NONNULL(4)
Serialize an ECDSA signature in compact format (64 bytes + recovery id).
SECP256K1_API int secp256k1_ecdsa_sign_recoverable(const secp256k1_context *ctx, secp256k1_ecdsa_recoverable_signature *sig, const unsigned char *msghash32, 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 a recoverable ECDSA signature.
SECP256K1_API int secp256k1_schnorr_sign(const secp256k1_context *ctx, unsigned char *sig64, const unsigned char *msghash32, 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 a signature using a custom EC-Schnorr-SHA256 construction.
SECP256K1_API int secp256k1_schnorrsig_sign(const secp256k1_context *ctx, unsigned char *sig64, const unsigned char *msg32, const secp256k1_keypair *keypair, unsigned char *aux_rand32) SECP256K1_ARG_NONNULL(1) SECP256K1_ARG_NONNULL(2) SECP256K1_ARG_NONNULL(3) SECP256K1_ARG_NONNULL(4)
Create a Schnorr signature.
Opaque data structured that holds a parsed ECDSA signature, supporting pubkey recovery.
Opaque data structured that holds a parsed ECDSA signature.
Opaque data structure that holds a keypair consisting of a secret and a public key.
Opaque data structure that holds a parsed and valid public key.
void run_tests(secp256k1_context *ctx, unsigned char *key)