Changeset View
Changeset View
Standalone View
Standalone View
src/secp256k1/src/valgrind_ctime_test.c
Show All 15 Lines | |||||
#if ENABLE_MODULE_RECOVERY | #if ENABLE_MODULE_RECOVERY | ||||
# include "include/secp256k1_recovery.h" | # include "include/secp256k1_recovery.h" | ||||
#endif | #endif | ||||
#if ENABLE_MODULE_SCHNORR | #if ENABLE_MODULE_SCHNORR | ||||
# include "include/secp256k1_schnorr.h" | # include "include/secp256k1_schnorr.h" | ||||
#endif | #endif | ||||
#if ENABLE_MODULE_EXTRAKEYS | |||||
# include "include/secp256k1_extrakeys.h" | |||||
#endif | |||||
int main(void) { | int main(void) { | ||||
secp256k1_context* ctx; | secp256k1_context* ctx; | ||||
secp256k1_ecdsa_signature signature; | secp256k1_ecdsa_signature signature; | ||||
secp256k1_pubkey pubkey; | secp256k1_pubkey pubkey; | ||||
size_t siglen = 74; | size_t siglen = 74; | ||||
size_t outputlen = 33; | size_t outputlen = 33; | ||||
int i; | int i; | ||||
int ret; | int ret; | ||||
unsigned char msg[32]; | unsigned char msg[32]; | ||||
unsigned char key[32]; | unsigned char key[32]; | ||||
unsigned char sig[74]; | unsigned char sig[74]; | ||||
unsigned char spubkey[33]; | unsigned char spubkey[33]; | ||||
#if ENABLE_MODULE_RECOVERY | #if ENABLE_MODULE_RECOVERY | ||||
secp256k1_ecdsa_recoverable_signature recoverable_signature; | secp256k1_ecdsa_recoverable_signature recoverable_signature; | ||||
int recid; | int recid; | ||||
#endif | #endif | ||||
#if ENABLE_MODULE_EXTRAKEYS | |||||
secp256k1_keypair keypair; | |||||
#endif | |||||
if (!RUNNING_ON_VALGRIND) { | if (!RUNNING_ON_VALGRIND) { | ||||
fprintf(stderr, "This test can only usefully be run inside valgrind.\n"); | fprintf(stderr, "This test can only usefully be run inside valgrind.\n"); | ||||
fprintf(stderr, "Usage: libtool --mode=execute valgrind ./valgrind_ctime_test\n"); | fprintf(stderr, "Usage: libtool --mode=execute valgrind ./valgrind_ctime_test\n"); | ||||
exit(1); | exit(1); | ||||
} | } | ||||
/** In theory, testing with a single secret input should be sufficient: | /** In theory, testing with a single secret input should be sufficient: | ||||
▲ Show 20 Lines • Show All 75 Lines • ▼ Show 20 Lines | #endif | ||||
CHECK(ret == 1); | CHECK(ret == 1); | ||||
/* Test context randomisation. Do this last because it leaves the context tainted. */ | /* Test context randomisation. Do this last because it leaves the context tainted. */ | ||||
VALGRIND_MAKE_MEM_UNDEFINED(key, 32); | VALGRIND_MAKE_MEM_UNDEFINED(key, 32); | ||||
ret = secp256k1_context_randomize(ctx, key); | ret = secp256k1_context_randomize(ctx, key); | ||||
VALGRIND_MAKE_MEM_DEFINED(&ret, sizeof(ret)); | VALGRIND_MAKE_MEM_DEFINED(&ret, sizeof(ret)); | ||||
CHECK(ret); | CHECK(ret); | ||||
#if ENABLE_MODULE_EXTRAKEYS | |||||
VALGRIND_MAKE_MEM_UNDEFINED(key, 32); | |||||
ret = secp256k1_keypair_create(ctx, &keypair, key); | |||||
VALGRIND_MAKE_MEM_DEFINED(&ret, sizeof(ret)); | |||||
CHECK(ret == 1); | |||||
#endif | |||||
secp256k1_context_destroy(ctx); | secp256k1_context_destroy(ctx); | ||||
return 0; | return 0; | ||||
} | } |