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 http://www.opensource.org/licenses/mit-license.php.*
5 **********************************************************************/
7 #ifndef SECP256K1_ECMULT_H
8 #define SECP256K1_ECMULT_H
16 /* For accelerating the computation of a*P + b*G: */
17 secp256k1_ge_storage (*pre_g)[]; /* odd multiples of the generator */
18 secp256k1_ge_storage (*pre_g_128)[]; /* odd multiples of 2^128*generator */
19 } secp256k1_ecmult_context;
21 static const size_t SECP256K1_ECMULT_CONTEXT_PREALLOCATED_SIZE;
22 static void secp256k1_ecmult_context_init(secp256k1_ecmult_context *ctx);
23 static void secp256k1_ecmult_context_build(secp256k1_ecmult_context *ctx, void **prealloc);
24 static void secp256k1_ecmult_context_finalize_memcpy(secp256k1_ecmult_context *dst, const secp256k1_ecmult_context *src);
25 static void secp256k1_ecmult_context_clear(secp256k1_ecmult_context *ctx);
26 static int secp256k1_ecmult_context_is_built(const secp256k1_ecmult_context *ctx);
28 /** Double multiply: R = na*A + ng*G */
29 static void secp256k1_ecmult(const secp256k1_ecmult_context *ctx, secp256k1_gej *r, const secp256k1_gej *a, const secp256k1_scalar *na, const secp256k1_scalar *ng);
31 typedef int (secp256k1_ecmult_multi_callback)(secp256k1_scalar *sc, secp256k1_ge *pt, size_t idx, void *data);
34 * Multi-multiply: R = inp_g_sc * G + sum_i ni * Ai.
35 * Chooses the right algorithm for a given number of points and scratch space
36 * size. Resets and overwrites the given scratch space. If the points do not
37 * fit in the scratch space the algorithm is repeatedly run with batches of
38 * points. If no scratch space is given then a simple algorithm is used that
39 * simply multiplies the points with the corresponding scalars and adds them up.
40 * Returns: 1 on success (including when inp_g_sc is NULL and n is 0)
41 * 0 if there is not enough scratch space for a single point or
44 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);
46 #endif /* SECP256K1_ECMULT_H */