7#ifndef SECP256K1_ECMULT_GEN_IMPL_H
8#define SECP256K1_ECMULT_GEN_IMPL_H
19 ecmult_gen_ctx->
built = 1;
23 return ecmult_gen_ctx->
built;
27 ecmult_gen_ctx->
built = 0;
29 secp256k1_ge_clear(&ecmult_gen_ctx->
ge_offset);
30 secp256k1_fe_clear(&ecmult_gen_ctx->
proj_blind);
41 secp256k1_scalar_half(&neghalf, &secp256k1_scalar_one);
42 secp256k1_scalar_negate(&neghalf, &neghalf);
45 *diff = secp256k1_scalar_one;
47 secp256k1_scalar_add(diff, diff, diff);
51 secp256k1_scalar_add(diff, diff, &neghalf);
63 uint32_t recoded[(
COMB_BITS + 31) >> 5] = {0};
66 memset(&adds, 0,
sizeof(adds));
110 secp256k1_scalar_add(&d, &ecmult_gen_ctx->
scalar_offset, gn);
112 for (i = 0; i < 8 && i < ((
COMB_BITS + 31) >> 5); ++i) {
113 recoded[i] = secp256k1_scalar_get_bits_limb32(&d, 32 * i, 32);
115 secp256k1_scalar_clear(&d);
195 uint32_t bit_pos = comb_off;
200 uint32_t bits = 0,
sign, abs, index, tooth;
209 for (tooth = 0; tooth <
COMB_TEETH; ++tooth) {
222 uint32_t
volatile vmask = ~(1 << tooth);
226 bits ^= bitdata << tooth;
252 secp256k1_ge_from_storage(&add, &adds);
259 secp256k1_gej_set_ge(r, &add);
261 secp256k1_gej_rescale(r, &ecmult_gen_ctx->
proj_blind);
264 secp256k1_gej_add_ge(r, r, &add);
269 if (comb_off-- == 0)
break;
270 secp256k1_gej_double(r, r);
275 secp256k1_gej_add_ge(r, r, &ecmult_gen_ctx->
ge_offset);
278 secp256k1_fe_clear(&neg);
279 secp256k1_ge_clear(&add);
287 secp256k1_ge_set_gej(r, &rj);
290 secp256k1_gej_clear(&rj);
298 unsigned char nonce32[32];
300 unsigned char keydata[64];
305 if (seed32 == NULL) {
307 secp256k1_ge_neg(&ecmult_gen_ctx->
ge_offset, &secp256k1_ge_const_g);
308 secp256k1_scalar_add(&ecmult_gen_ctx->
scalar_offset, &secp256k1_scalar_one, &diff);
309 ecmult_gen_ctx->
proj_blind = secp256k1_fe_one;
313 secp256k1_scalar_get_b32(keydata, &ecmult_gen_ctx->
scalar_offset);
319 memcpy(keydata + 32, seed32, 32);
331 secp256k1_scalar_set_b32(&b, nonce32, NULL);
334 secp256k1_scalar_cmov(&b, &secp256k1_scalar_one, secp256k1_scalar_is_zero(&b));
337 secp256k1_scalar_negate(&b, &b);
338 secp256k1_scalar_add(&ecmult_gen_ctx->
scalar_offset, &b, &diff);
342 secp256k1_scalar_clear(&b);
343 secp256k1_fe_clear(&f);
static void secp256k1_ecmult_gen_context_clear(secp256k1_ecmult_gen_context *ecmult_gen_ctx)
static void secp256k1_ecmult_gen_blind(secp256k1_ecmult_gen_context *ecmult_gen_ctx, const secp256k1_hash_ctx *hash_ctx, const unsigned char *seed32)
static void secp256k1_ecmult_gen_context_build(secp256k1_ecmult_gen_context *ecmult_gen_ctx, const secp256k1_hash_ctx *hash_ctx)
static void secp256k1_ecmult_gen_gej(const secp256k1_ecmult_gen_context *ecmult_gen_ctx, secp256k1_gej *r, const secp256k1_scalar *gn)
static int secp256k1_ecmult_gen_context_is_built(const secp256k1_ecmult_gen_context *ecmult_gen_ctx)
static void secp256k1_ecmult_gen_scalar_diff(secp256k1_scalar *diff)
static SECP256K1_INLINE void secp256k1_ecmult_gen_ge(const secp256k1_ecmult_gen_context *ecmult_gen_ctx, secp256k1_ge *r, const secp256k1_scalar *a)
#define secp256k1_fe_cmov
#define secp256k1_fe_negate(r, a, m)
Negate a field element.
#define secp256k1_fe_set_b32_mod
#define secp256k1_fe_normalizes_to_zero
static int sign(const secp256k1_context *ctx, struct signer_secrets *signer_secrets, struct signer *signer, const secp256k1_musig_keyagg_cache *cache, const unsigned char *msg32, unsigned char *sig64)
const secp256k1_ge_storage secp256k1_ecmult_gen_prec_table[COMB_BLOCKS][COMB_POINTS]
static void secp256k1_rfc6979_hmac_sha256_clear(secp256k1_rfc6979_hmac_sha256 *rng)
static void secp256k1_rfc6979_hmac_sha256_generate(const secp256k1_hash_ctx *hash_ctx, secp256k1_rfc6979_hmac_sha256 *rng, unsigned char *out, size_t outlen)
static void secp256k1_rfc6979_hmac_sha256_initialize(const secp256k1_hash_ctx *hash_ctx, secp256k1_rfc6979_hmac_sha256 *rng, const unsigned char *key, size_t keylen)
static void secp256k1_rfc6979_hmac_sha256_finalize(secp256k1_rfc6979_hmac_sha256 *rng)
static SECP256K1_INLINE void secp256k1_memclear_explicit(void *ptr, size_t len)
static SECP256K1_INLINE uint32_t secp256k1_rotr32(const uint32_t x, const unsigned int by)
#define VERIFY_CHECK(cond)
secp256k1_scalar scalar_offset
This field implementation represents the value as 10 uint32_t limbs in base 2^26.
A group element in affine coordinates on the secp256k1 curve, or occasionally on an isomorphic curve ...
A group element of the secp256k1 curve, in jacobian coordinates.
A scalar modulo the group order of the secp256k1 curve.