Test demonstrating discrepancy in sqr output
This commit is contained in:
committed by
Pieter Wuille
parent
5e53856862
commit
59447da38d
24
src/tests.c
24
src/tests.c
@@ -312,6 +312,29 @@ void run_field_inv_all_var() {
|
||||
}
|
||||
}
|
||||
|
||||
void run_sqr() {
|
||||
secp256k1_fe_t x, s;
|
||||
|
||||
#if defined(USE_FIELD_5X52)
|
||||
// Known issue with reduction part of sqr. For simplicity, we trigger the problem here
|
||||
// with "negative" powers of 2, but the problem exists for large ranges of values.
|
||||
{
|
||||
secp256k1_fe_set_int(&x, 1);
|
||||
secp256k1_fe_negate(&x, &x, 1);
|
||||
|
||||
for (int i=1; i<=512; ++i) {
|
||||
secp256k1_fe_mul_int(&x, 2);
|
||||
secp256k1_fe_normalize(&x);
|
||||
secp256k1_fe_sqr(&s, &x);
|
||||
if (!secp256k1_fe_verify(&s)) {
|
||||
printf("%4i: %016llx %016llx %016llx %016llx %016llx\n",
|
||||
i, s.n[4], s.n[3], s.n[2], s.n[1], s.n[0]);
|
||||
}
|
||||
}
|
||||
}
|
||||
#endif
|
||||
}
|
||||
|
||||
void test_sqrt(const secp256k1_fe_t *a, const secp256k1_fe_t *k) {
|
||||
secp256k1_fe_t r1, r2;
|
||||
int v = secp256k1_fe_sqrt(&r1, a);
|
||||
@@ -609,6 +632,7 @@ int main(int argc, char **argv) {
|
||||
run_field_inv_var();
|
||||
run_field_inv_all();
|
||||
run_field_inv_all_var();
|
||||
run_sqr();
|
||||
run_sqrt();
|
||||
|
||||
// ecmult tests
|
||||
|
||||
Reference in New Issue
Block a user