From 77f5323d8c6cbb9deffd40ddfec17a12ad007e98 Mon Sep 17 00:00:00 2001 From: siv2r Date: Wed, 5 Jan 2022 04:23:30 +0530 Subject: [PATCH] remove unwanted `secp256k1_fe_normalize_weak` call It is not neccessary for the second argument in `secp256k1_fe_equal_var` to have magnitude = 1. Hence, removed the `secp256k1_fe_normalize_weak` call for those second argument. --- src/group_impl.h | 3 +-- src/tests.c | 8 ++++---- 2 files changed, 5 insertions(+), 6 deletions(-) diff --git a/src/group_impl.h b/src/group_impl.h index f02891de77..94907695ec 100644 --- a/src/group_impl.h +++ b/src/group_impl.h @@ -241,7 +241,7 @@ static int secp256k1_gej_eq_x_var(const secp256k1_fe *x, const secp256k1_gej *a) secp256k1_fe r, r2; VERIFY_CHECK(!a->infinity); secp256k1_fe_sqr(&r, &a->z); secp256k1_fe_mul(&r, &r, x); - r2 = a->x; secp256k1_fe_normalize_weak(&r2); + r2 = a->x; return secp256k1_fe_equal_var(&r, &r2); } @@ -267,7 +267,6 @@ static int secp256k1_ge_is_valid_var(const secp256k1_ge *a) { secp256k1_fe_sqr(&y2, &a->y); secp256k1_fe_sqr(&x3, &a->x); secp256k1_fe_mul(&x3, &x3, &a->x); secp256k1_fe_add(&x3, &secp256k1_fe_const_b); - secp256k1_fe_normalize_weak(&x3); return secp256k1_fe_equal_var(&y2, &x3); } diff --git a/src/tests.c b/src/tests.c index a7474994a5..13ec6d0b6d 100644 --- a/src/tests.c +++ b/src/tests.c @@ -3032,9 +3032,9 @@ void ge_equals_gej(const secp256k1_ge *a, const secp256k1_gej *b) { /* 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_normalize_weak(&u2); + u2 = b->x; secp256k1_fe_mul(&s1, &a->y, &z2s); secp256k1_fe_mul(&s1, &s1, &b->z); - s2 = b->y; secp256k1_fe_normalize_weak(&s2); + s2 = b->y; CHECK(secp256k1_fe_equal_var(&u1, &u2)); CHECK(secp256k1_fe_equal_var(&s1, &s2)); } @@ -3489,8 +3489,8 @@ void test_pre_g_table(const secp256k1_ge_storage * pre_g, size_t n) { secp256k1_ge_from_storage(&q, &pre_g[i]); CHECK(secp256k1_ge_is_valid_var(&q)); - secp256k1_fe_negate(&dqx, &q.x, 1); secp256k1_fe_add(&dqx, &gg.x); secp256k1_fe_normalize_weak(&dqx); - dqy = q.y; secp256k1_fe_add(&dqy, &gg.y); secp256k1_fe_normalize_weak(&dqy); + secp256k1_fe_negate(&dqx, &q.x, 1); secp256k1_fe_add(&dqx, &gg.x); + dqy = q.y; secp256k1_fe_add(&dqy, &gg.y); /* Check that -q is not equal to gg */ CHECK(!secp256k1_fe_normalizes_to_zero_var(&dqx) || !secp256k1_fe_normalizes_to_zero_var(&dqy));