0
0
Fork 0
mirror of https://github.com/bitcoin/bitcoin.git synced 2025-02-08 10:31:50 -05:00

Add a reference consistency test to ge_tests.

This adds all points used in the test together in random order, which
should result in infinity.

Suggested by Greg Maxwell.
This commit is contained in:
Pieter Wuille 2014-12-29 17:21:39 +01:00
parent 60571c6e45
commit 9ab93355f2

View file

@ -881,6 +881,29 @@ void test_ge(void) {
}
}
/* Test adding all points together in random order equals infinity. */
{
secp256k1_gej_t *gej_shuffled = malloc((4 * runs + 1) * sizeof(secp256k1_gej_t));
for (int i = 0; i < 4 * runs + 1; i++) {
gej_shuffled[i] = gej[i];
}
for (int i = 0; i < 4 * runs + 1; i++) {
int swap = i + secp256k1_rand32() % (4 * runs + 1 - i);
if (swap != i) {
secp256k1_gej_t t = gej_shuffled[i];
gej_shuffled[i] = gej_shuffled[swap];
gej_shuffled[swap] = t;
}
}
secp256k1_gej_t sum;
secp256k1_gej_set_infinity(&sum);
for (int i = 0; i < 4 * runs + 1; i++) {
secp256k1_gej_add_var(&sum, &sum, &gej_shuffled[i]);
}
CHECK(secp256k1_gej_is_infinity(&sum));
free(gej_shuffled);
}
/* Test batch gej -> ge conversion. */
{
secp256k1_ge_t *ge_set_all = malloc((4 * runs + 1) * sizeof(secp256k1_ge_t));