Changeset View
Changeset View
Standalone View
Standalone View
src/secp256k1/src/tests.c
Show First 20 Lines • Show All 187 Lines • ▼ Show 20 Lines | void run_context_tests(int use_prealloc) { | ||||
} | } | ||||
memset(&zero_pubkey, 0, sizeof(zero_pubkey)); | memset(&zero_pubkey, 0, sizeof(zero_pubkey)); | ||||
ecount = 0; | ecount = 0; | ||||
ecount2 = 10; | ecount2 = 10; | ||||
secp256k1_context_set_illegal_callback(vrfy, counting_illegal_callback_fn, &ecount); | secp256k1_context_set_illegal_callback(vrfy, counting_illegal_callback_fn, &ecount); | ||||
secp256k1_context_set_illegal_callback(sign, counting_illegal_callback_fn, &ecount2); | secp256k1_context_set_illegal_callback(sign, counting_illegal_callback_fn, &ecount2); | ||||
secp256k1_context_set_error_callback(sign, counting_illegal_callback_fn, NULL); | /* set error callback (to a function that still aborts in case malloc() fails in secp256k1_context_clone() below) */ | ||||
CHECK(vrfy->error_callback.fn != sign->error_callback.fn); | secp256k1_context_set_error_callback(sign, secp256k1_default_illegal_callback_fn, NULL); | ||||
CHECK(sign->error_callback.fn != vrfy->error_callback.fn); | |||||
CHECK(sign->error_callback.fn == secp256k1_default_illegal_callback_fn); | |||||
/* check if sizes for cloning are consistent */ | /* check if sizes for cloning are consistent */ | ||||
CHECK(secp256k1_context_preallocated_clone_size(none) == secp256k1_context_preallocated_size(SECP256K1_CONTEXT_NONE)); | CHECK(secp256k1_context_preallocated_clone_size(none) == secp256k1_context_preallocated_size(SECP256K1_CONTEXT_NONE)); | ||||
CHECK(secp256k1_context_preallocated_clone_size(sign) == secp256k1_context_preallocated_size(SECP256K1_CONTEXT_SIGN)); | CHECK(secp256k1_context_preallocated_clone_size(sign) == secp256k1_context_preallocated_size(SECP256K1_CONTEXT_SIGN)); | ||||
CHECK(secp256k1_context_preallocated_clone_size(vrfy) == secp256k1_context_preallocated_size(SECP256K1_CONTEXT_VERIFY)); | CHECK(secp256k1_context_preallocated_clone_size(vrfy) == secp256k1_context_preallocated_size(SECP256K1_CONTEXT_VERIFY)); | ||||
CHECK(secp256k1_context_preallocated_clone_size(both) == secp256k1_context_preallocated_size(SECP256K1_CONTEXT_SIGN | SECP256K1_CONTEXT_VERIFY)); | CHECK(secp256k1_context_preallocated_clone_size(both) == secp256k1_context_preallocated_size(SECP256K1_CONTEXT_SIGN | SECP256K1_CONTEXT_VERIFY)); | ||||
/*** clone and destroy all of them to make sure cloning was complete ***/ | /*** clone and destroy all of them to make sure cloning was complete ***/ | ||||
Show All 39 Lines | /*** clone and destroy all of them to make sure cloning was complete ***/ | ||||
prealloc_tmp = malloc(secp256k1_context_preallocated_size(SECP256K1_CONTEXT_SIGN | SECP256K1_CONTEXT_VERIFY)); CHECK(prealloc_tmp != NULL); | prealloc_tmp = malloc(secp256k1_context_preallocated_size(SECP256K1_CONTEXT_SIGN | SECP256K1_CONTEXT_VERIFY)); CHECK(prealloc_tmp != NULL); | ||||
ctx_tmp = both; both = secp256k1_context_preallocated_clone(both, prealloc_tmp); secp256k1_context_destroy(ctx_tmp); | ctx_tmp = both; both = secp256k1_context_preallocated_clone(both, prealloc_tmp); secp256k1_context_destroy(ctx_tmp); | ||||
ctx_tmp = both; both = secp256k1_context_clone(both); secp256k1_context_preallocated_destroy(ctx_tmp); | ctx_tmp = both; both = secp256k1_context_clone(both); secp256k1_context_preallocated_destroy(ctx_tmp); | ||||
free(prealloc_tmp); | free(prealloc_tmp); | ||||
} | } | ||||
} | } | ||||
/* Verify that the error callback makes it across the clone. */ | /* Verify that the error callback makes it across the clone. */ | ||||
CHECK(vrfy->error_callback.fn != sign->error_callback.fn); | CHECK(sign->error_callback.fn != vrfy->error_callback.fn); | ||||
CHECK(sign->error_callback.fn == secp256k1_default_illegal_callback_fn); | |||||
/* And that it resets back to default. */ | /* And that it resets back to default. */ | ||||
secp256k1_context_set_error_callback(sign, NULL, NULL); | secp256k1_context_set_error_callback(sign, NULL, NULL); | ||||
CHECK(vrfy->error_callback.fn == sign->error_callback.fn); | CHECK(vrfy->error_callback.fn == sign->error_callback.fn); | ||||
/*** attempt to use them ***/ | /*** attempt to use them ***/ | ||||
random_scalar_order_test(&msg); | random_scalar_order_test(&msg); | ||||
random_scalar_order_test(&key); | random_scalar_order_test(&key); | ||||
secp256k1_ecmult_gen(&both->ecmult_gen_ctx, &pubj, &key); | secp256k1_ecmult_gen(&both->ecmult_gen_ctx, &pubj, &key); | ||||
▲ Show 20 Lines • Show All 5,208 Lines • Show Last 20 Lines |