This is a backwards-compatible API change: Before this commit, a context initialized for signing was required to call functions that rely on ecmult_gen. After this commit, this is no longer necessary because the static ecmult_gen table is always present. In practice this means that the corresponding functions will just work instead of calling the illegal callback when given a context which is not (officially) initialized for signing. This is in line with 6815761, which made the analogous change with respect to ecmult and contexts initialized for signing. But as opposed to 681571, which removed the ecmult context entirely, we cannot remove the ecmult_gen context entirely because it is still used for random blinding. Moreover, since the secp256k1_context_no_precomp context is const and cannot meaningfully support random blinding, we refrain (for now) from changing its API, i.e., the illegal callback will still be called when trying to use ecmult_gen operations with the static secp256k1_context_no_precomp context.
38 lines
1.4 KiB
C
38 lines
1.4 KiB
C
/***********************************************************************
|
|
* Copyright (c) 2013, 2014 Pieter Wuille *
|
|
* Distributed under the MIT software license, see the accompanying *
|
|
* file COPYING or https://www.opensource.org/licenses/mit-license.php.*
|
|
***********************************************************************/
|
|
|
|
#ifndef SECP256K1_ECMULT_GEN_H
|
|
#define SECP256K1_ECMULT_GEN_H
|
|
|
|
#include "scalar.h"
|
|
#include "group.h"
|
|
|
|
#if ECMULT_GEN_PREC_BITS != 2 && ECMULT_GEN_PREC_BITS != 4 && ECMULT_GEN_PREC_BITS != 8
|
|
# error "Set ECMULT_GEN_PREC_BITS to 2, 4 or 8."
|
|
#endif
|
|
#define ECMULT_GEN_PREC_B ECMULT_GEN_PREC_BITS
|
|
#define ECMULT_GEN_PREC_G (1 << ECMULT_GEN_PREC_B)
|
|
#define ECMULT_GEN_PREC_N (256 / ECMULT_GEN_PREC_B)
|
|
|
|
typedef struct {
|
|
/* Whether the context has been built. */
|
|
int built;
|
|
|
|
/* Blinding values used when computing (n-b)G + bG. */
|
|
secp256k1_scalar blind; /* -b */
|
|
secp256k1_gej initial; /* bG */
|
|
} secp256k1_ecmult_gen_context;
|
|
|
|
static void secp256k1_ecmult_gen_context_build(secp256k1_ecmult_gen_context* ctx);
|
|
static void secp256k1_ecmult_gen_context_clear(secp256k1_ecmult_gen_context* ctx);
|
|
|
|
/** Multiply with the generator: R = a*G */
|
|
static void secp256k1_ecmult_gen(const secp256k1_ecmult_gen_context* ctx, secp256k1_gej *r, const secp256k1_scalar *a);
|
|
|
|
static void secp256k1_ecmult_gen_blind(secp256k1_ecmult_gen_context *ctx, const unsigned char *seed32);
|
|
|
|
#endif /* SECP256K1_ECMULT_GEN_H */
|