diff --git a/src/field_impl.h b/src/field_impl.h index 551a6243e2..1994017ba5 100644 --- a/src/field_impl.h +++ b/src/field_impl.h @@ -208,6 +208,16 @@ static void secp256k1_fe_inv(secp256k1_fe *r, const secp256k1_fe *a) { } static void secp256k1_fe_inv_var(secp256k1_fe *r, const secp256k1_fe *a) { +#if !defined(USE_FIELD_INV_BUILTIN) && !defined(USE_FIELD_INV_NUM) + /* In case no field inverse implementation has been selected, + choose one based on num implementation. */ + #if defined(USE_NUM_GMP) + #define USE_FIELD_INV_NUM 1 /* "NUM" implementation requires GMP */ + #else + #define USE_FIELD_INV_BUILTIN 1 + #endif +#endif + #if defined(USE_FIELD_INV_BUILTIN) secp256k1_fe_inv(r, a); #elif defined(USE_FIELD_INV_NUM) diff --git a/src/scalar_impl.h b/src/scalar_impl.h index 88ea97de86..ec2d8985a6 100644 --- a/src/scalar_impl.h +++ b/src/scalar_impl.h @@ -240,6 +240,16 @@ SECP256K1_INLINE static int secp256k1_scalar_is_even(const secp256k1_scalar *a) } static void secp256k1_scalar_inverse_var(secp256k1_scalar *r, const secp256k1_scalar *x) { +#if !defined(USE_SCALAR_INV_BUILTIN) && !defined(USE_SCALAR_INV_NUM) + /* In case no scalar inverse implementation has been selected, + choose one based on num implementation. */ + #if defined(USE_NUM_GMP) + #define USE_SCALAR_INV_NUM 1 /* "NUM" implementation requires GMP */ + #else + #define USE_SCALAR_INV_BUILTIN 1 + #endif +#endif + #if defined(USE_SCALAR_INV_BUILTIN) secp256k1_scalar_inverse(r, x); #elif defined(USE_SCALAR_INV_NUM)