refactor: introduce testutil.h (deduplicate random_fe_, ge_equals_ helpers)
This commit is contained in:
@@ -28,54 +28,11 @@
|
||||
#include "testrand_impl.h"
|
||||
#include "ecmult_compute_table_impl.h"
|
||||
#include "ecmult_gen_compute_table_impl.h"
|
||||
#include "testutil.h"
|
||||
#include "util.h"
|
||||
|
||||
static int count = 2;
|
||||
|
||||
/** stolen from tests.c */
|
||||
static void ge_equals_ge(const secp256k1_ge *a, const secp256k1_ge *b) {
|
||||
CHECK(a->infinity == b->infinity);
|
||||
if (a->infinity) {
|
||||
return;
|
||||
}
|
||||
CHECK(secp256k1_fe_equal(&a->x, &b->x));
|
||||
CHECK(secp256k1_fe_equal(&a->y, &b->y));
|
||||
}
|
||||
|
||||
static void ge_equals_gej(const secp256k1_ge *a, const secp256k1_gej *b) {
|
||||
secp256k1_fe z2s;
|
||||
secp256k1_fe u1, u2, s1, s2;
|
||||
CHECK(a->infinity == b->infinity);
|
||||
if (a->infinity) {
|
||||
return;
|
||||
}
|
||||
/* Check a.x * b.z^2 == b.x && a.y * b.z^3 == b.y, to avoid inverses. */
|
||||
secp256k1_fe_sqr(&z2s, &b->z);
|
||||
secp256k1_fe_mul(&u1, &a->x, &z2s);
|
||||
u2 = b->x;
|
||||
secp256k1_fe_mul(&s1, &a->y, &z2s); secp256k1_fe_mul(&s1, &s1, &b->z);
|
||||
s2 = b->y;
|
||||
CHECK(secp256k1_fe_equal(&u1, &u2));
|
||||
CHECK(secp256k1_fe_equal(&s1, &s2));
|
||||
}
|
||||
|
||||
static void random_fe(secp256k1_fe *x) {
|
||||
unsigned char bin[32];
|
||||
do {
|
||||
secp256k1_testrand256(bin);
|
||||
if (secp256k1_fe_set_b32_limit(x, bin)) {
|
||||
return;
|
||||
}
|
||||
} while(1);
|
||||
}
|
||||
|
||||
static void random_fe_non_zero(secp256k1_fe *nz) {
|
||||
do {
|
||||
random_fe(nz);
|
||||
} while (secp256k1_fe_is_zero(nz));
|
||||
}
|
||||
/** END stolen from tests.c */
|
||||
|
||||
static uint32_t num_cores = 1;
|
||||
static uint32_t this_core = 0;
|
||||
|
||||
|
||||
Reference in New Issue
Block a user