diff --git a/src/field.h b/src/field.h index c057472c28..9e517dca80 100644 --- a/src/field.h +++ b/src/field.h @@ -83,6 +83,7 @@ static const secp256k1_fe secp256k1_const_beta = SECP256K1_FE_CONST( # define secp256k1_fe_set_int secp256k1_fe_impl_set_int # define secp256k1_fe_clear secp256k1_fe_impl_clear # define secp256k1_fe_is_zero secp256k1_fe_impl_is_zero +# define secp256k1_fe_is_odd secp256k1_fe_impl_is_odd #endif /* !defined(VERIFY) */ /** Normalize a field element. @@ -142,7 +143,11 @@ static void secp256k1_fe_clear(secp256k1_fe *a); */ static int secp256k1_fe_is_zero(const secp256k1_fe *a); -/** Check the "oddness" of a field element. Requires the input to be normalized. */ +/** Determine whether a (mod p) is odd. + * + * On input, a must be a valid normalized field element. + * Returns (int(a) mod p) & 1. + */ static int secp256k1_fe_is_odd(const secp256k1_fe *a); /** Compare two field elements. Requires magnitude-1 inputs. */ diff --git a/src/field_10x26_impl.h b/src/field_10x26_impl.h index 5e934c438c..e7305abb3e 100644 --- a/src/field_10x26_impl.h +++ b/src/field_10x26_impl.h @@ -274,11 +274,7 @@ SECP256K1_INLINE static int secp256k1_fe_impl_is_zero(const secp256k1_fe *a) { return (t[0] | t[1] | t[2] | t[3] | t[4] | t[5] | t[6] | t[7] | t[8] | t[9]) == 0; } -SECP256K1_INLINE static int secp256k1_fe_is_odd(const secp256k1_fe *a) { -#ifdef VERIFY - VERIFY_CHECK(a->normalized); - secp256k1_fe_verify(a); -#endif +SECP256K1_INLINE static int secp256k1_fe_impl_is_odd(const secp256k1_fe *a) { return a->n[0] & 1; } diff --git a/src/field_5x52_impl.h b/src/field_5x52_impl.h index 0572d77bec..31c3bcb7a6 100644 --- a/src/field_5x52_impl.h +++ b/src/field_5x52_impl.h @@ -220,11 +220,7 @@ SECP256K1_INLINE static int secp256k1_fe_impl_is_zero(const secp256k1_fe *a) { return (t[0] | t[1] | t[2] | t[3] | t[4]) == 0; } -SECP256K1_INLINE static int secp256k1_fe_is_odd(const secp256k1_fe *a) { -#ifdef VERIFY - VERIFY_CHECK(a->normalized); - secp256k1_fe_verify(a); -#endif +SECP256K1_INLINE static int secp256k1_fe_impl_is_odd(const secp256k1_fe *a) { return a->n[0] & 1; } diff --git a/src/field_impl.h b/src/field_impl.h index 8c85134057..bd6982033c 100644 --- a/src/field_impl.h +++ b/src/field_impl.h @@ -209,6 +209,13 @@ SECP256K1_INLINE static int secp256k1_fe_is_zero(const secp256k1_fe *a) { VERIFY_CHECK(a->normalized); return secp256k1_fe_impl_is_zero(a); } + +static int secp256k1_fe_impl_is_odd(const secp256k1_fe *a); +SECP256K1_INLINE static int secp256k1_fe_is_odd(const secp256k1_fe *a) { + secp256k1_fe_verify(a); + VERIFY_CHECK(a->normalized); + return secp256k1_fe_impl_is_odd(a); +} #endif /* defined(VERIFY) */ #endif /* SECP256K1_FIELD_IMPL_H */