2020-12-29 17:15:51 +00:00
|
|
|
/***********************************************************************
|
|
|
|
* Copyright (c) 2013, 2014, 2017 Pieter Wuille, Andrew Poelstra *
|
|
|
|
* Distributed under the MIT software license, see the accompanying *
|
|
|
|
* file COPYING or https://www.opensource.org/licenses/mit-license.php.*
|
|
|
|
***********************************************************************/
|
2015-10-26 14:54:21 +00:00
|
|
|
|
2018-07-09 11:17:44 +00:00
|
|
|
#ifndef SECP256K1_ECMULT_H
|
|
|
|
#define SECP256K1_ECMULT_H
|
2015-10-26 14:54:21 +00:00
|
|
|
|
|
|
|
#include "group.h"
|
2018-07-09 11:17:44 +00:00
|
|
|
#include "scalar.h"
|
|
|
|
#include "scratch.h"
|
2015-10-26 14:54:21 +00:00
|
|
|
|
2022-12-20 21:11:14 +00:00
|
|
|
#ifndef ECMULT_WINDOW_SIZE
|
|
|
|
# define ECMULT_WINDOW_SIZE 15
|
|
|
|
# ifdef DEBUG_CONFIG
|
|
|
|
# pragma message DEBUG_CONFIG_MSG("ECMULT_WINDOW_SIZE undefined, assuming default value")
|
|
|
|
# endif
|
|
|
|
#endif
|
|
|
|
|
|
|
|
#ifdef DEBUG_CONFIG
|
|
|
|
# pragma message DEBUG_CONFIG_DEF(ECMULT_WINDOW_SIZE)
|
|
|
|
#endif
|
|
|
|
|
2022-03-08 19:45:41 +00:00
|
|
|
/* Noone will ever need more than a window size of 24. The code might
|
|
|
|
* be correct for larger values of ECMULT_WINDOW_SIZE but this is not
|
|
|
|
* tested.
|
|
|
|
*
|
|
|
|
* The following limitations are known, and there are probably more:
|
|
|
|
* If WINDOW_G > 27 and size_t has 32 bits, then the code is incorrect
|
|
|
|
* because the size of the memory object that we allocate (in bytes)
|
|
|
|
* will not fit in a size_t.
|
|
|
|
* If WINDOW_G > 31 and int has 32 bits, then the code is incorrect
|
|
|
|
* because certain expressions will overflow.
|
|
|
|
*/
|
|
|
|
#if ECMULT_WINDOW_SIZE < 2 || ECMULT_WINDOW_SIZE > 24
|
|
|
|
# error Set ECMULT_WINDOW_SIZE to an integer in range [2..24].
|
|
|
|
#endif
|
|
|
|
|
|
|
|
/** The number of entries a table with precomputed multiples needs to have. */
|
|
|
|
#define ECMULT_TABLE_SIZE(w) (1L << ((w)-2))
|
2015-10-26 14:54:21 +00:00
|
|
|
|
|
|
|
/** Double multiply: R = na*A + ng*G */
|
2023-03-17 05:22:01 +00:00
|
|
|
static void rustsecp256k1_v0_8_1_ecmult(rustsecp256k1_v0_8_1_gej *r, const rustsecp256k1_v0_8_1_gej *a, const rustsecp256k1_v0_8_1_scalar *na, const rustsecp256k1_v0_8_1_scalar *ng);
|
2015-10-26 14:54:21 +00:00
|
|
|
|
2023-03-17 05:22:01 +00:00
|
|
|
typedef int (rustsecp256k1_v0_8_1_ecmult_multi_callback)(rustsecp256k1_v0_8_1_scalar *sc, rustsecp256k1_v0_8_1_ge *pt, size_t idx, void *data);
|
2018-07-09 11:17:44 +00:00
|
|
|
|
|
|
|
/**
|
|
|
|
* Multi-multiply: R = inp_g_sc * G + sum_i ni * Ai.
|
|
|
|
* 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
|
2019-05-28 12:23:28 +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.
|
2018-07-09 11:17:44 +00: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
|
|
|
|
*/
|
2023-03-17 05:22:01 +00:00
|
|
|
static int rustsecp256k1_v0_8_1_ecmult_multi_var(const rustsecp256k1_v0_8_1_callback* error_callback, rustsecp256k1_v0_8_1_scratch *scratch, rustsecp256k1_v0_8_1_gej *r, const rustsecp256k1_v0_8_1_scalar *inp_g_sc, rustsecp256k1_v0_8_1_ecmult_multi_callback cb, void *cbdata, size_t n);
|
2018-07-09 11:17:44 +00:00
|
|
|
|
|
|
|
#endif /* SECP256K1_ECMULT_H */
|