From b797a500ec194948eecbea8bd80f6b7d455f7ca2 Mon Sep 17 00:00:00 2001 From: Russell O'Connor Date: Tue, 18 Jan 2022 22:41:00 -0500 Subject: [PATCH] Create a SECP256K1_ECMULT_TABLE_VERIFY macro. --- src/ecmult_impl.h | 17 ++++++++--------- 1 file changed, 8 insertions(+), 9 deletions(-) diff --git a/src/ecmult_impl.h b/src/ecmult_impl.h index 9a5da8c9fcb39..bbc820c77c748 100644 --- a/src/ecmult_impl.h +++ b/src/ecmult_impl.h @@ -114,10 +114,13 @@ static void secp256k1_ecmult_odd_multiples_table(int n, secp256k1_ge *pre_a, sec secp256k1_fe_mul(z, &ai.z, &d.z); } +#define SECP256K1_ECMULT_TABLE_VERIFY(n,w) \ + VERIFY_CHECK(((n) & 1) == 1); \ + VERIFY_CHECK((n) >= -((1 << ((w)-1)) - 1)); \ + VERIFY_CHECK((n) <= ((1 << ((w)-1)) - 1)); + SECP256K1_INLINE static void secp256k1_ecmult_table_get_ge(secp256k1_ge *r, const secp256k1_ge *pre, int n, int w) { - VERIFY_CHECK((n & 1) == 1); - VERIFY_CHECK(n >= -((1 << (w-1)) - 1)); - VERIFY_CHECK(n <= ((1 << (w-1)) - 1)); + SECP256K1_ECMULT_TABLE_VERIFY(n,w) if (n > 0) { *r = pre[(n-1)/2]; } else { @@ -127,9 +130,7 @@ SECP256K1_INLINE static void secp256k1_ecmult_table_get_ge(secp256k1_ge *r, cons } SECP256K1_INLINE static void secp256k1_ecmult_table_get_ge_lambda(secp256k1_ge *r, const secp256k1_ge *pre, const secp256k1_fe *x, int n, int w) { - VERIFY_CHECK((n & 1) == 1); - VERIFY_CHECK(n >= -((1 << (w-1)) - 1)); - VERIFY_CHECK(n <= ((1 << (w-1)) - 1)); + SECP256K1_ECMULT_TABLE_VERIFY(n,w) if (n > 0) { secp256k1_ge_set_xy(r, &x[(n-1)/2], &pre[(n-1)/2].y); } else { @@ -139,9 +140,7 @@ SECP256K1_INLINE static void secp256k1_ecmult_table_get_ge_lambda(secp256k1_ge * } SECP256K1_INLINE static void secp256k1_ecmult_table_get_ge_storage(secp256k1_ge *r, const secp256k1_ge_storage *pre, int n, int w) { - VERIFY_CHECK((n & 1) == 1); - VERIFY_CHECK(n >= -((1 << (w-1)) - 1)); - VERIFY_CHECK(n <= ((1 << (w-1)) - 1)); + SECP256K1_ECMULT_TABLE_VERIFY(n,w) if (n > 0) { secp256k1_ge_from_storage(r, &pre[(n-1)/2]); } else {