Add size constants for preallocated memory
This commit is contained in:
parent
3f1a8580a2
commit
16d4a0a251
@ -20,6 +20,7 @@ typedef struct {
|
|||||||
#endif
|
#endif
|
||||||
} secp256k1_ecmult_context;
|
} secp256k1_ecmult_context;
|
||||||
|
|
||||||
|
static const size_t SECP256K1_ECMULT_CONTEXT_PREALLOCATED_SIZE;
|
||||||
static void secp256k1_ecmult_context_init(secp256k1_ecmult_context *ctx);
|
static void secp256k1_ecmult_context_init(secp256k1_ecmult_context *ctx);
|
||||||
static void secp256k1_ecmult_context_build(secp256k1_ecmult_context *ctx, const secp256k1_callback *cb);
|
static void secp256k1_ecmult_context_build(secp256k1_ecmult_context *ctx, const secp256k1_callback *cb);
|
||||||
static void secp256k1_ecmult_context_clone(secp256k1_ecmult_context *dst,
|
static void secp256k1_ecmult_context_clone(secp256k1_ecmult_context *dst,
|
||||||
|
@ -28,6 +28,7 @@ typedef struct {
|
|||||||
secp256k1_gej initial;
|
secp256k1_gej initial;
|
||||||
} secp256k1_ecmult_gen_context;
|
} secp256k1_ecmult_gen_context;
|
||||||
|
|
||||||
|
static const size_t SECP256K1_ECMULT_GEN_CONTEXT_PREALLOCATED_SIZE;
|
||||||
static void secp256k1_ecmult_gen_context_init(secp256k1_ecmult_gen_context* ctx);
|
static void secp256k1_ecmult_gen_context_init(secp256k1_ecmult_gen_context* ctx);
|
||||||
static void secp256k1_ecmult_gen_context_build(secp256k1_ecmult_gen_context* ctx, const secp256k1_callback* cb);
|
static void secp256k1_ecmult_gen_context_build(secp256k1_ecmult_gen_context* ctx, const secp256k1_callback* cb);
|
||||||
static void secp256k1_ecmult_gen_context_clone(secp256k1_ecmult_gen_context *dst,
|
static void secp256k1_ecmult_gen_context_clone(secp256k1_ecmult_gen_context *dst,
|
||||||
|
@ -7,6 +7,7 @@
|
|||||||
#ifndef SECP256K1_ECMULT_GEN_IMPL_H
|
#ifndef SECP256K1_ECMULT_GEN_IMPL_H
|
||||||
#define SECP256K1_ECMULT_GEN_IMPL_H
|
#define SECP256K1_ECMULT_GEN_IMPL_H
|
||||||
|
|
||||||
|
#include "util.h"
|
||||||
#include "scalar.h"
|
#include "scalar.h"
|
||||||
#include "group.h"
|
#include "group.h"
|
||||||
#include "ecmult_gen.h"
|
#include "ecmult_gen.h"
|
||||||
@ -14,6 +15,13 @@
|
|||||||
#ifdef USE_ECMULT_STATIC_PRECOMPUTATION
|
#ifdef USE_ECMULT_STATIC_PRECOMPUTATION
|
||||||
#include "ecmult_static_context.h"
|
#include "ecmult_static_context.h"
|
||||||
#endif
|
#endif
|
||||||
|
|
||||||
|
#ifndef USE_ECMULT_STATIC_PRECOMPUTATION
|
||||||
|
static const size_t SECP256K1_ECMULT_GEN_CONTEXT_PREALLOCATED_SIZE = ROUND_TO_ALIGN(sizeof(*((secp256k1_ecmult_gen_context*) NULL)->prec));
|
||||||
|
#else
|
||||||
|
static const size_t SECP256K1_ECMULT_GEN_CONTEXT_PREALLOCATED_SIZE = 0;
|
||||||
|
#endif
|
||||||
|
|
||||||
static void secp256k1_ecmult_gen_context_init(secp256k1_ecmult_gen_context *ctx) {
|
static void secp256k1_ecmult_gen_context_init(secp256k1_ecmult_gen_context *ctx) {
|
||||||
ctx->prec = NULL;
|
ctx->prec = NULL;
|
||||||
}
|
}
|
||||||
|
@ -10,6 +10,7 @@
|
|||||||
#include <string.h>
|
#include <string.h>
|
||||||
#include <stdint.h>
|
#include <stdint.h>
|
||||||
|
|
||||||
|
#include "util.h"
|
||||||
#include "group.h"
|
#include "group.h"
|
||||||
#include "scalar.h"
|
#include "scalar.h"
|
||||||
#include "ecmult.h"
|
#include "ecmult.h"
|
||||||
@ -293,6 +294,13 @@ static void secp256k1_ecmult_odd_multiples_table_storage_var(const int n, secp25
|
|||||||
} \
|
} \
|
||||||
} while(0)
|
} while(0)
|
||||||
|
|
||||||
|
static const size_t SECP256K1_ECMULT_CONTEXT_PREALLOCATED_SIZE =
|
||||||
|
ROUND_TO_ALIGN(sizeof((*((secp256k1_ecmult_context*) NULL)->pre_g)[0]) * ECMULT_TABLE_SIZE(WINDOW_G))
|
||||||
|
#ifdef USE_ENDOMORPHISM
|
||||||
|
+ ROUND_TO_ALIGN(sizeof((*((secp256k1_ecmult_context*) NULL)->pre_g_128)[0]) * ECMULT_TABLE_SIZE(WINDOW_G))
|
||||||
|
#endif
|
||||||
|
;
|
||||||
|
|
||||||
static void secp256k1_ecmult_context_init(secp256k1_ecmult_context *ctx) {
|
static void secp256k1_ecmult_context_init(secp256k1_ecmult_context *ctx) {
|
||||||
ctx->pre_g = NULL;
|
ctx->pre_g = NULL;
|
||||||
#ifdef USE_ENDOMORPHISM
|
#ifdef USE_ENDOMORPHISM
|
||||||
|
@ -74,6 +74,24 @@ static const secp256k1_context secp256k1_context_no_precomp_ = {
|
|||||||
};
|
};
|
||||||
const secp256k1_context *secp256k1_context_no_precomp = &secp256k1_context_no_precomp_;
|
const secp256k1_context *secp256k1_context_no_precomp = &secp256k1_context_no_precomp_;
|
||||||
|
|
||||||
|
size_t secp256k1_context_preallocated_size(unsigned int flags) {
|
||||||
|
size_t ret = ROUND_TO_ALIGN(sizeof(secp256k1_context));
|
||||||
|
|
||||||
|
if (EXPECT((flags & SECP256K1_FLAGS_TYPE_MASK) != SECP256K1_FLAGS_TYPE_CONTEXT, 0)) {
|
||||||
|
secp256k1_callback_call(&default_illegal_callback,
|
||||||
|
"Invalid flags");
|
||||||
|
return 0;
|
||||||
|
}
|
||||||
|
|
||||||
|
if (flags & SECP256K1_FLAGS_BIT_CONTEXT_SIGN) {
|
||||||
|
ret += SECP256K1_ECMULT_GEN_CONTEXT_PREALLOCATED_SIZE;
|
||||||
|
}
|
||||||
|
if (flags & SECP256K1_FLAGS_BIT_CONTEXT_VERIFY) {
|
||||||
|
ret += SECP256K1_ECMULT_CONTEXT_PREALLOCATED_SIZE;
|
||||||
|
}
|
||||||
|
return ret;
|
||||||
|
}
|
||||||
|
|
||||||
secp256k1_context* secp256k1_context_create(unsigned int flags) {
|
secp256k1_context* secp256k1_context_create(unsigned int flags) {
|
||||||
secp256k1_context* ret = (secp256k1_context*)checked_malloc(&default_error_callback, sizeof(secp256k1_context));
|
secp256k1_context* ret = (secp256k1_context*)checked_malloc(&default_error_callback, sizeof(secp256k1_context));
|
||||||
ret->illegal_callback = default_illegal_callback;
|
ret->illegal_callback = default_illegal_callback;
|
||||||
|
Loading…
x
Reference in New Issue
Block a user