1 /***********************************************************************
2 * Copyright (c) 2013, 2014, 2017 Pieter Wuille, Andrew Poelstra *
3 * Distributed under the MIT software license, see the accompanying *
4 * file COPYING or https://www.opensource.org/licenses/mit-license.php.*
5 ***********************************************************************/
7 #ifndef SECP256K1_ECMULT_H
8 #define SECP256K1_ECMULT_H
15 /* For accelerating the computation of a*P + b*G: */
16 secp256k1_ge_storage (*pre_g)[]; /* odd multiples of the generator */
17 secp256k1_ge_storage (*pre_g_128)[]; /* odd multiples of 2^128*generator */
18 } secp256k1_ecmult_context;
20 static void secp256k1_ecmult_context_init(secp256k1_ecmult_context *ctx);
21 static void secp256k1_ecmult_context_build(secp256k1_ecmult_context *ctx, void **prealloc);
22 static void secp256k1_ecmult_context_finalize_memcpy(secp256k1_ecmult_context *dst, const secp256k1_ecmult_context *src);
23 static void secp256k1_ecmult_context_clear(secp256k1_ecmult_context *ctx);
24 static int secp256k1_ecmult_context_is_built(const secp256k1_ecmult_context *ctx);
26 /** Double multiply: R = na*A + ng*G */
27 static void secp256k1_ecmult(const secp256k1_ecmult_context *ctx, secp256k1_gej *r, const secp256k1_gej *a, const secp256k1_scalar *na, const secp256k1_scalar *ng);
29 typedef int (secp256k1_ecmult_multi_callback)(secp256k1_scalar *sc, secp256k1_ge *pt, size_t idx, void *data);
32 * Multi-multiply: R = inp_g_sc * G + sum_i ni * Ai.
33 * Chooses the right algorithm for a given number of points and scratch space
34 * size. Resets and overwrites the given scratch space. If the points do not
35 * fit in the scratch space the algorithm is repeatedly run with batches of
36 * points. If no scratch space is given then a simple algorithm is used that
37 * simply multiplies the points with the corresponding scalars and adds them up.
38 * Returns: 1 on success (including when inp_g_sc is NULL and n is 0)
39 * 0 if there is not enough scratch space for a single point or
42 static int secp256k1_ecmult_multi_var(const secp256k1_callback* error_callback, const secp256k1_ecmult_context *ctx, secp256k1_scratch *scratch, secp256k1_gej *r, const secp256k1_scalar *inp_g_sc, secp256k1_ecmult_multi_callback cb, void *cbdata, size_t n);
44 #endif /* SECP256K1_ECMULT_H */