Changeset View
Changeset View
Standalone View
Standalone View
src/secp256k1/src/tests.c
Show First 20 Lines • Show All 410 Lines • ▼ Show 20 Lines | void run_scratch_tests(void) { | ||||
CHECK(secp256k1_scratch_alloc(&none->error_callback, scratch, SIZE_MAX) == NULL); | CHECK(secp256k1_scratch_alloc(&none->error_callback, scratch, SIZE_MAX) == NULL); | ||||
secp256k1_scratch_space_destroy(none, scratch); | secp256k1_scratch_space_destroy(none, scratch); | ||||
/* cleanup */ | /* cleanup */ | ||||
secp256k1_scratch_space_destroy(none, NULL); /* no-op */ | secp256k1_scratch_space_destroy(none, NULL); /* no-op */ | ||||
secp256k1_context_destroy(none); | secp256k1_context_destroy(none); | ||||
} | } | ||||
void run_ctz_tests(void) { | |||||
static const uint32_t b32[] = {1, 0xffffffff, 0x5e56968f, 0xe0d63129}; | |||||
static const uint64_t b64[] = {1, 0xffffffffffffffff, 0xbcd02462139b3fc3, 0x98b5f80c769693ef}; | |||||
int shift; | |||||
unsigned i; | |||||
for (i = 0; i < sizeof(b32) / sizeof(b32[0]); ++i) { | |||||
for (shift = 0; shift < 32; ++shift) { | |||||
CHECK(secp256k1_ctz32_var_debruijn(b32[i] << shift) == shift); | |||||
CHECK(secp256k1_ctz32_var(b32[i] << shift) == shift); | |||||
} | |||||
} | |||||
for (i = 0; i < sizeof(b64) / sizeof(b64[0]); ++i) { | |||||
for (shift = 0; shift < 64; ++shift) { | |||||
CHECK(secp256k1_ctz64_var_debruijn(b64[i] << shift) == shift); | |||||
CHECK(secp256k1_ctz64_var(b64[i] << shift) == shift); | |||||
} | |||||
} | |||||
} | |||||
/***** HASH TESTS *****/ | /***** HASH TESTS *****/ | ||||
void run_sha256_tests(void) { | void run_sha256_tests(void) { | ||||
static const char *inputs[8] = { | static const char *inputs[8] = { | ||||
"", "abc", "message digest", "secure hash algorithm", "SHA256 is considered to be safe", | "", "abc", "message digest", "secure hash algorithm", "SHA256 is considered to be safe", | ||||
"abcdbcdecdefdefgefghfghighijhijkijkljklmklmnlmnomnopnopq", | "abcdbcdecdefdefgefghfghighijhijkijkljklmklmnlmnomnopnopq", | ||||
"For this sample, this 63-byte string will be used as input data", | "For this sample, this 63-byte string will be used as input data", | ||||
"This is exactly 64 bytes long, not counting the terminating byte" | "This is exactly 64 bytes long, not counting the terminating byte" | ||||
▲ Show 20 Lines • Show All 5,183 Lines • ▼ Show 20 Lines | if (secp256k1_testrand_bits(1)) { | ||||
unsigned char rand32[32]; | unsigned char rand32[32]; | ||||
secp256k1_testrand256(rand32); | secp256k1_testrand256(rand32); | ||||
CHECK(secp256k1_context_randomize(ctx, secp256k1_testrand_bits(1) ? rand32 : NULL)); | CHECK(secp256k1_context_randomize(ctx, secp256k1_testrand_bits(1) ? rand32 : NULL)); | ||||
} | } | ||||
run_rand_bits(); | run_rand_bits(); | ||||
run_rand_int(); | run_rand_int(); | ||||
run_ctz_tests(); | |||||
run_sha256_tests(); | run_sha256_tests(); | ||||
run_hmac_sha256_tests(); | run_hmac_sha256_tests(); | ||||
run_rfc6979_hmac_sha256_tests(); | run_rfc6979_hmac_sha256_tests(); | ||||
#ifndef USE_NUM_NONE | #ifndef USE_NUM_NONE | ||||
/* num tests */ | /* num tests */ | ||||
run_num_smalltests(); | run_num_smalltests(); | ||||
#endif | #endif | ||||
▲ Show 20 Lines • Show All 89 Lines • Show Last 20 Lines |