Skip to content

Default selection of field/scalar inverse implementation #331

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Closed
wants to merge 1 commit into from
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
10 changes: 10 additions & 0 deletions src/field_impl.h
Original file line number Diff line number Diff line change
Expand Up @@ -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)
Expand Down
10 changes: 10 additions & 0 deletions src/scalar_impl.h
Original file line number Diff line number Diff line change
Expand Up @@ -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)
Expand Down