rust-secp256k1-unsafe-fast/secp256k1-sys/depend/secp256k1/src/ecmult.h

49 lines
2.8 KiB
C
Raw Normal View History

2015-10-26 14:54:21 +00:00
/**********************************************************************
* Copyright (c) 2013, 2014, 2017 Pieter Wuille, Andrew Poelstra *
2015-10-26 14:54:21 +00:00
* Distributed under the MIT software license, see the accompanying *
* file COPYING or http://www.opensource.org/licenses/mit-license.php.*
**********************************************************************/
#ifndef SECP256K1_ECMULT_H
#define SECP256K1_ECMULT_H
2015-10-26 14:54:21 +00:00
#include "num.h"
#include "group.h"
#include "scalar.h"
#include "scratch.h"
2015-10-26 14:54:21 +00:00
typedef struct {
/* For accelerating the computation of a*P + b*G: */
2020-09-15 01:39:26 +00:00
rustsecp256k1_v0_3_1_ge_storage (*pre_g)[]; /* odd multiples of the generator */
2015-10-26 14:54:21 +00:00
#ifdef USE_ENDOMORPHISM
2020-09-15 01:39:26 +00:00
rustsecp256k1_v0_3_1_ge_storage (*pre_g_128)[]; /* odd multiples of 2^128*generator */
2015-10-26 14:54:21 +00:00
#endif
2020-09-15 01:39:26 +00:00
} rustsecp256k1_v0_3_1_ecmult_context;
2015-10-26 14:54:21 +00:00
static const size_t SECP256K1_ECMULT_CONTEXT_PREALLOCATED_SIZE;
2020-09-15 01:39:26 +00:00
static void rustsecp256k1_v0_3_1_ecmult_context_init(rustsecp256k1_v0_3_1_ecmult_context *ctx);
static void rustsecp256k1_v0_3_1_ecmult_context_build(rustsecp256k1_v0_3_1_ecmult_context *ctx, void **prealloc);
static void rustsecp256k1_v0_3_1_ecmult_context_finalize_memcpy(rustsecp256k1_v0_3_1_ecmult_context *dst, const rustsecp256k1_v0_3_1_ecmult_context *src);
static void rustsecp256k1_v0_3_1_ecmult_context_clear(rustsecp256k1_v0_3_1_ecmult_context *ctx);
static int rustsecp256k1_v0_3_1_ecmult_context_is_built(const rustsecp256k1_v0_3_1_ecmult_context *ctx);
2015-10-26 14:54:21 +00:00
/** Double multiply: R = na*A + ng*G */
2020-09-15 01:39:26 +00:00
static void rustsecp256k1_v0_3_1_ecmult(const rustsecp256k1_v0_3_1_ecmult_context *ctx, rustsecp256k1_v0_3_1_gej *r, const rustsecp256k1_v0_3_1_gej *a, const rustsecp256k1_v0_3_1_scalar *na, const rustsecp256k1_v0_3_1_scalar *ng);
2015-10-26 14:54:21 +00:00
2020-09-15 01:39:26 +00:00
typedef int (rustsecp256k1_v0_3_1_ecmult_multi_callback)(rustsecp256k1_v0_3_1_scalar *sc, rustsecp256k1_v0_3_1_ge *pt, size_t idx, void *data);
/**
* 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
* 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.
* 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
*/
2020-09-15 01:39:26 +00:00
static int rustsecp256k1_v0_3_1_ecmult_multi_var(const rustsecp256k1_v0_3_1_callback* error_callback, const rustsecp256k1_v0_3_1_ecmult_context *ctx, rustsecp256k1_v0_3_1_scratch *scratch, rustsecp256k1_v0_3_1_gej *r, const rustsecp256k1_v0_3_1_scalar *inp_g_sc, rustsecp256k1_v0_3_1_ecmult_multi_callback cb, void *cbdata, size_t n);
#endif /* SECP256K1_ECMULT_H */