2014-11-15 15:28:10 +00:00
|
|
|
/**********************************************************************
|
2017-08-16 14:45:27 -07:00
|
|
|
* Copyright (c) 2013, 2014, 2017 Pieter Wuille, Andrew Poelstra *
|
2014-11-15 15:28:10 +00:00
|
|
|
* Distributed under the MIT software license, see the accompanying *
|
|
|
|
* file COPYING or http://www.opensource.org/licenses/mit-license.php.*
|
|
|
|
**********************************************************************/
|
2013-05-09 15:24:32 +02:00
|
|
|
|
2017-08-26 18:44:21 +03:00
|
|
|
#ifndef SECP256K1_ECMULT_H
|
|
|
|
#define SECP256K1_ECMULT_H
|
2013-03-08 02:52:50 +01:00
|
|
|
|
2013-03-10 04:24:00 +01:00
|
|
|
#include "num.h"
|
2013-03-31 17:02:52 +02:00
|
|
|
#include "group.h"
|
2017-08-16 14:45:27 -07:00
|
|
|
#include "scalar.h"
|
|
|
|
#include "scratch.h"
|
2013-03-08 02:52:50 +01:00
|
|
|
|
2015-02-03 17:27:00 -08:00
|
|
|
typedef struct {
|
|
|
|
/* For accelerating the computation of a*P + b*G: */
|
2015-09-21 20:57:54 +02:00
|
|
|
secp256k1_ge_storage (*pre_g)[]; /* odd multiples of the generator */
|
2015-02-03 17:27:00 -08:00
|
|
|
#ifdef USE_ENDOMORPHISM
|
2015-09-21 20:57:54 +02:00
|
|
|
secp256k1_ge_storage (*pre_g_128)[]; /* odd multiples of 2^128*generator */
|
2015-02-03 17:27:00 -08:00
|
|
|
#endif
|
2015-09-21 20:57:54 +02:00
|
|
|
} secp256k1_ecmult_context;
|
2015-02-03 17:27:00 -08:00
|
|
|
|
2018-10-22 16:23:09 +02:00
|
|
|
static const size_t SECP256K1_ECMULT_CONTEXT_PREALLOCATED_SIZE;
|
2015-09-21 20:57:54 +02:00
|
|
|
static void secp256k1_ecmult_context_init(secp256k1_ecmult_context *ctx);
|
2018-10-22 16:25:26 +02:00
|
|
|
static void secp256k1_ecmult_context_build(secp256k1_ecmult_context *ctx, void **prealloc);
|
|
|
|
static void secp256k1_ecmult_context_finalize_memcpy(secp256k1_ecmult_context *dst, const secp256k1_ecmult_context *src);
|
2015-09-21 20:57:54 +02:00
|
|
|
static void secp256k1_ecmult_context_clear(secp256k1_ecmult_context *ctx);
|
|
|
|
static int secp256k1_ecmult_context_is_built(const secp256k1_ecmult_context *ctx);
|
2013-04-01 06:29:30 +02:00
|
|
|
|
|
|
|
/** Double multiply: R = na*A + ng*G */
|
2015-09-21 20:57:54 +02:00
|
|
|
static void secp256k1_ecmult(const secp256k1_ecmult_context *ctx, secp256k1_gej *r, const secp256k1_gej *a, const secp256k1_scalar *na, const secp256k1_scalar *ng);
|
2013-03-09 22:47:40 +01:00
|
|
|
|
2017-08-16 14:45:27 -07:00
|
|
|
typedef int (secp256k1_ecmult_multi_callback)(secp256k1_scalar *sc, secp256k1_ge *pt, size_t idx, void *data);
|
|
|
|
|
2017-09-14 17:55:13 +02:00
|
|
|
/**
|
|
|
|
* Multi-multiply: R = inp_g_sc * G + sum_i ni * Ai.
|
2017-11-05 19:40:18 +00:00
|
|
|
* Chooses the right algorithm for a given number of points and scratch space
|
|
|
|
* size. Resets and overwrites the given scratch space. If the points do not
|
|
|
|
* fit in the scratch space the algorithm is repeatedly run with batches of
|
2018-12-20 20:48:19 +00:00
|
|
|
* points. If no scratch space is given then a simple algorithm is used that
|
|
|
|
* simply multiplies the points with the corresponding scalars and adds them up.
|
2017-09-14 17:55:13 +02:00
|
|
|
* Returns: 1 on success (including when inp_g_sc is NULL and n is 0)
|
|
|
|
* 0 if there is not enough scratch space for a single point or
|
|
|
|
* callback returns 0
|
|
|
|
*/
|
|
|
|
static int secp256k1_ecmult_multi_var(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);
|
2017-08-16 14:45:27 -07:00
|
|
|
|
2017-08-26 18:44:21 +03:00
|
|
|
#endif /* SECP256K1_ECMULT_H */
|