7 #ifndef _SECP256K1_ECMULT_IMPL_H_ 8 #define _SECP256K1_ECMULT_IMPL_H_ 19 #ifdef USE_ENDOMORPHISM 28 #define ECMULT_TABLE_SIZE(w) (1 << ((w)-2)) 59 for (i = 1; i <
n; i++) {
106 for (i = 0; i <
n; i++) {
117 #define ECMULT_TABLE_GET_GE(r,pre,n,w) do { \ 118 VERIFY_CHECK(((n) & 1) == 1); \ 119 VERIFY_CHECK((n) >= -((1 << ((w)-1)) - 1)); \ 120 VERIFY_CHECK((n) <= ((1 << ((w)-1)) - 1)); \ 122 *(r) = (pre)[((n)-1)/2]; \ 124 secp256k1_ge_neg((r), &(pre)[(-(n)-1)/2]); \ 128 #define ECMULT_TABLE_GET_GE_STORAGE(r,pre,n,w) do { \ 129 VERIFY_CHECK(((n) & 1) == 1); \ 130 VERIFY_CHECK((n) >= -((1 << ((w)-1)) - 1)); \ 131 VERIFY_CHECK((n) <= ((1 << ((w)-1)) - 1)); \ 133 secp256k1_ge_from_storage((r), &(pre)[((n)-1)/2]); \ 135 secp256k1_ge_from_storage((r), &(pre)[(-(n)-1)/2]); \ 136 secp256k1_ge_neg((r), (r)); \ 142 #ifdef USE_ENDOMORPHISM 143 ctx->pre_g_128 = NULL;
150 if (
ctx->pre_g != NULL) {
162 #ifdef USE_ENDOMORPHISM 171 for (i = 0; i < 128; i++) {
181 if (src->
pre_g == NULL) {
188 #ifdef USE_ENDOMORPHISM 189 if (src->pre_g_128 == NULL) {
190 dst->pre_g_128 = NULL;
194 memcpy(dst->pre_g_128, src->pre_g_128, size);
200 return ctx->pre_g != NULL;
205 #ifdef USE_ENDOMORPHISM 206 free(
ctx->pre_g_128);
220 int last_set_bit = -1;
230 memset(wnaf, 0, len *
sizeof(wnaf[0]));
246 if (now > len - bit) {
252 carry = (word >> (w-1)) & 1;
255 wnaf[bit] = sign * word;
266 return last_set_bit + 1;
273 #ifdef USE_ENDOMORPHISM 279 int wnaf_na_lam[130];
284 int wnaf_ng_128[129];
295 #ifdef USE_ENDOMORPHISM 297 secp256k1_scalar_split_lambda(&na_1, &na_lam, na);
305 if (bits_na_lam > bits) {
326 #ifdef USE_ENDOMORPHISM 328 secp256k1_ge_mul_lambda(&pre_a_lam[i], &pre_a[i]);
332 secp256k1_scalar_split_128(&ng_1, &ng_128, ng);
337 if (bits_ng_1 > bits) {
340 if (bits_ng_128 > bits) {
345 if (bits_ng > bits) {
352 for (i = bits - 1; i >= 0; i--) {
355 #ifdef USE_ENDOMORPHISM 356 if (i < bits_na_1 && (
n = wnaf_na_1[i])) {
360 if (i < bits_na_lam && (
n = wnaf_na_lam[i])) {
364 if (i < bits_ng_1 && (
n = wnaf_ng_1[i])) {
368 if (i < bits_ng_128 && (
n = wnaf_ng_128[i])) {
373 if (i < bits_na && (
n = wnaf_na[i])) {
377 if (i < bits_ng && (
n = wnaf_ng[i])) {
static void secp256k1_ge_globalz_set_table_gej(size_t len, secp256k1_ge *r, secp256k1_fe *globalz, const secp256k1_gej *a, const secp256k1_fe *zr)
#define VERIFY_CHECK(cond)
static int secp256k1_ecmult_context_is_built(const secp256k1_ecmult_context *ctx)
static void secp256k1_ecmult_context_clone(secp256k1_ecmult_context *dst, const secp256k1_ecmult_context *src, const secp256k1_callback *cb)
static void secp256k1_ecmult_context_clear(secp256k1_ecmult_context *ctx)
static void secp256k1_ecmult_context_init(secp256k1_ecmult_context *ctx)
static void secp256k1_fe_mul(secp256k1_fe *r, const secp256k1_fe *a, const secp256k1_fe *SECP256K1_RESTRICT b)
static unsigned int secp256k1_scalar_get_bits(const secp256k1_scalar *a, unsigned int offset, unsigned int count)
static void secp256k1_scalar_negate(secp256k1_scalar *r, const secp256k1_scalar *a)
static void secp256k1_ecmult_odd_multiples_table_storage_var(int n, secp256k1_ge_storage *pre, const secp256k1_gej *a, const secp256k1_callback *cb)
#define ECMULT_TABLE_GET_GE_STORAGE(r, pre, n, w)
#define ECMULT_TABLE_SIZE(w)
static void secp256k1_gej_add_zinv_var(secp256k1_gej *r, const secp256k1_gej *a, const secp256k1_ge *b, const secp256k1_fe *bzinv)
static void secp256k1_gej_set_infinity(secp256k1_gej *r)
static void secp256k1_gej_add_ge_var(secp256k1_gej *r, const secp256k1_gej *a, const secp256k1_ge *b, secp256k1_fe *rzr)
static void secp256k1_gej_double_var(secp256k1_gej *r, const secp256k1_gej *a, secp256k1_fe *rzr)
static const secp256k1_ge secp256k1_ge_const_g
static void secp256k1_ecmult_odd_multiples_table_globalz_windowa(secp256k1_ge *pre, secp256k1_fe *globalz, const secp256k1_gej *a)
static void secp256k1_ge_set_table_gej_var(size_t len, secp256k1_ge *r, const secp256k1_gej *a, const secp256k1_fe *zr)
static secp256k1_context * ctx
#define ECMULT_TABLE_GET_GE(r, pre, n, w)
static void secp256k1_ge_set_gej_zinv(secp256k1_ge *r, const secp256k1_gej *a, const secp256k1_fe *zi)
static void secp256k1_ecmult_odd_multiples_table(int n, secp256k1_gej *prej, secp256k1_fe *zr, const secp256k1_gej *a)
void * memcpy(void *a, const void *b, size_t c)
static unsigned int secp256k1_scalar_get_bits_var(const secp256k1_scalar *a, unsigned int offset, unsigned int count)
static void secp256k1_gej_set_ge(secp256k1_gej *r, const secp256k1_ge *a)
static int secp256k1_ecmult_wnaf(int *wnaf, int len, const secp256k1_scalar *a, int w)
static void secp256k1_ecmult(const secp256k1_ecmult_context *ctx, secp256k1_gej *r, const secp256k1_gej *a, const secp256k1_scalar *na, const secp256k1_scalar *ng)
static void secp256k1_ge_to_storage(secp256k1_ge_storage *r, const secp256k1_ge *a)
static SECP256K1_INLINE void * checked_malloc(const secp256k1_callback *cb, size_t size)
static void secp256k1_ecmult_context_build(secp256k1_ecmult_context *ctx, const secp256k1_callback *cb)
secp256k1_ge_storage(* pre_g)[]