From 70ae0d2851fd78afda12a4e3c023d1088b1c2937 Mon Sep 17 00:00:00 2001 From: Gregory Maxwell Date: Wed, 31 Dec 2014 05:56:00 -0800 Subject: [PATCH] Use secp256k1_fe_equal_var in secp256k1_fe_sqrt_var. In theory this should be faster, since secp256k1_fe_equal_var is able to shortcut the normalization. On x86_64 the improvement appears to be in the noise for me. At least it makes the code cleaner. --- src/field_impl.h | 5 +---- 1 file changed, 1 insertion(+), 4 deletions(-) diff --git a/src/field_impl.h b/src/field_impl.h index 484e67310c5..4e2c24aa153 100644 --- a/src/field_impl.h +++ b/src/field_impl.h @@ -135,10 +135,7 @@ static int secp256k1_fe_sqrt_var(secp256k1_fe_t *r, const secp256k1_fe_t *a) { /* Check that a square root was actually calculated */ secp256k1_fe_sqr(&t1, r); - secp256k1_fe_negate(&t1, &t1, 1); - secp256k1_fe_add(&t1, a); - secp256k1_fe_normalize_var(&t1); - return secp256k1_fe_is_zero(&t1); + return secp256k1_fe_equal_var(&t1, a); } static void secp256k1_fe_inv(secp256k1_fe_t *r, const secp256k1_fe_t *a) {