Changeset View
Changeset View
Standalone View
Standalone View
src/secp256k1/src/tests.c
Show First 20 Lines • Show All 2,847 Lines • ▼ Show 20 Lines | for(; scratch_size < max_size; scratch_size+=256) { | ||||
bucket_window = secp256k1_pippenger_bucket_window(n_points_supported); | bucket_window = secp256k1_pippenger_bucket_window(n_points_supported); | ||||
CHECK(secp256k1_scratch_allocate_frame(scratch, secp256k1_pippenger_scratch_size(n_points_supported, bucket_window), PIPPENGER_SCRATCH_OBJECTS)); | CHECK(secp256k1_scratch_allocate_frame(scratch, secp256k1_pippenger_scratch_size(n_points_supported, bucket_window), PIPPENGER_SCRATCH_OBJECTS)); | ||||
secp256k1_scratch_deallocate_frame(scratch); | secp256k1_scratch_deallocate_frame(scratch); | ||||
secp256k1_scratch_destroy(scratch); | secp256k1_scratch_destroy(scratch); | ||||
} | } | ||||
CHECK(bucket_window == PIPPENGER_MAX_BUCKET_WINDOW); | CHECK(bucket_window == PIPPENGER_MAX_BUCKET_WINDOW); | ||||
} | } | ||||
void test_ecmult_multi_batch_size_helper(void) { | |||||
size_t n_batches, n_batch_points, max_n_batch_points, n; | |||||
max_n_batch_points = 0; | |||||
n = 1; | |||||
CHECK(secp256k1_ecmult_multi_batch_size_helper(&n_batches, &n_batch_points, max_n_batch_points, n) == 0); | |||||
max_n_batch_points = 1; | |||||
n = 0; | |||||
CHECK(secp256k1_ecmult_multi_batch_size_helper(&n_batches, &n_batch_points, max_n_batch_points, n) == 1); | |||||
CHECK(n_batches == 0); | |||||
CHECK(n_batch_points == 0); | |||||
max_n_batch_points = 2; | |||||
n = 5; | |||||
CHECK(secp256k1_ecmult_multi_batch_size_helper(&n_batches, &n_batch_points, max_n_batch_points, n) == 1); | |||||
CHECK(n_batches == 3); | |||||
CHECK(n_batch_points == 2); | |||||
max_n_batch_points = ECMULT_MAX_POINTS_PER_BATCH; | |||||
n = ECMULT_MAX_POINTS_PER_BATCH; | |||||
CHECK(secp256k1_ecmult_multi_batch_size_helper(&n_batches, &n_batch_points, max_n_batch_points, n) == 1); | |||||
CHECK(n_batches == 1); | |||||
CHECK(n_batch_points == ECMULT_MAX_POINTS_PER_BATCH); | |||||
max_n_batch_points = ECMULT_MAX_POINTS_PER_BATCH + 1; | |||||
n = ECMULT_MAX_POINTS_PER_BATCH + 1; | |||||
CHECK(secp256k1_ecmult_multi_batch_size_helper(&n_batches, &n_batch_points, max_n_batch_points, n) == 1); | |||||
CHECK(n_batches == 2); | |||||
CHECK(n_batch_points == ECMULT_MAX_POINTS_PER_BATCH/2 + 1); | |||||
max_n_batch_points = 1; | |||||
n = SIZE_MAX; | |||||
CHECK(secp256k1_ecmult_multi_batch_size_helper(&n_batches, &n_batch_points, max_n_batch_points, n) == 1); | |||||
CHECK(n_batches == SIZE_MAX); | |||||
CHECK(n_batch_points == 1); | |||||
max_n_batch_points = 2; | |||||
n = SIZE_MAX; | |||||
CHECK(secp256k1_ecmult_multi_batch_size_helper(&n_batches, &n_batch_points, max_n_batch_points, n) == 1); | |||||
CHECK(n_batches == SIZE_MAX/2 + 1); | |||||
CHECK(n_batch_points == 2); | |||||
} | |||||
/** | /** | ||||
* Run secp256k1_ecmult_multi_var with num points and a scratch space restricted to | * Run secp256k1_ecmult_multi_var with num points and a scratch space restricted to | ||||
* 1 <= i <= num points. | * 1 <= i <= num points. | ||||
*/ | */ | ||||
void test_ecmult_multi_batching(void) { | void test_ecmult_multi_batching(void) { | ||||
static const int n_points = 2*ECMULT_PIPPENGER_THRESHOLD; | static const int n_points = 2*ECMULT_PIPPENGER_THRESHOLD; | ||||
secp256k1_scalar scG; | secp256k1_scalar scG; | ||||
secp256k1_scalar szero; | secp256k1_scalar szero; | ||||
▲ Show 20 Lines • Show All 66 Lines • ▼ Show 20 Lines | void run_ecmult_multi_tests(void) { | ||||
test_ecmult_multi(scratch, secp256k1_ecmult_strauss_batch_single); | test_ecmult_multi(scratch, secp256k1_ecmult_strauss_batch_single); | ||||
secp256k1_scratch_destroy(scratch); | secp256k1_scratch_destroy(scratch); | ||||
/* Run test_ecmult_multi with space for exactly one point */ | /* Run test_ecmult_multi with space for exactly one point */ | ||||
scratch = secp256k1_scratch_create(&ctx->error_callback, secp256k1_strauss_scratch_size(1) + STRAUSS_SCRATCH_OBJECTS*ALIGNMENT); | scratch = secp256k1_scratch_create(&ctx->error_callback, secp256k1_strauss_scratch_size(1) + STRAUSS_SCRATCH_OBJECTS*ALIGNMENT); | ||||
test_ecmult_multi(scratch, secp256k1_ecmult_multi_var); | test_ecmult_multi(scratch, secp256k1_ecmult_multi_var); | ||||
secp256k1_scratch_destroy(scratch); | secp256k1_scratch_destroy(scratch); | ||||
test_ecmult_multi_batch_size_helper(); | |||||
test_ecmult_multi_batching(); | test_ecmult_multi_batching(); | ||||
} | } | ||||
void test_wnaf(const secp256k1_scalar *number, int w) { | void test_wnaf(const secp256k1_scalar *number, int w) { | ||||
secp256k1_scalar x, two, t; | secp256k1_scalar x, two, t; | ||||
int wnaf[256]; | int wnaf[256]; | ||||
int zeroes = -1; | int zeroes = -1; | ||||
int i; | int i; | ||||
▲ Show 20 Lines • Show All 2,176 Lines • Show Last 20 Lines |