Skip to content

Commit

Permalink
Rename _prealloc functions to _preallocated
Browse files Browse the repository at this point in the history
  • Loading branch information
real-or-random committed Nov 1, 2018
1 parent 864da3a commit 856f880
Show file tree
Hide file tree
Showing 10 changed files with 89 additions and 89 deletions.
2 changes: 1 addition & 1 deletion Makefile.am
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@ else
JNI_LIB =
endif
include_HEADERS = include/secp256k1.h
include_HEADERS += include/secp256k1_prealloc.h
include_HEADERS += include/secp256k1_preallocated.h
noinst_HEADERS =
noinst_HEADERS += src/scalar.h
noinst_HEADERS += src/scalar_4x64.h
Expand Down
30 changes: 15 additions & 15 deletions include/secp256k1_prealloc.h → include/secp256k1_preallocated.h
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
#ifndef SECP256K1_PREALLOC_H
#define SECP256K1_PREALLOC_H
#ifndef SECP256K1_PREALLOCACTED_H
#define SECP256K1_PREALLOCACTED_H

#include "secp256k1.h"

Expand All @@ -11,27 +11,27 @@ extern "C" {
* caller-provided memory.
*
* The purpose of this function is to determine how much memory must be provided
* to secp256k1_context_prealloc_create.
* to secp256k1_context_preallocated_create.
*
* Returns: the required size of the caller-provided memory block
* In: flags: which parts of the context to initialize.
*/
SECP256K1_API size_t secp256k1_context_prealloc_size(
SECP256K1_API size_t secp256k1_context_preallocated_size(
unsigned int flags
) SECP256K1_WARN_UNUSED_RESULT;

/** Create a secp256k1 context object in caller-provided memory.
*
* Returns: a newly created context object.
* In: prealloc: a pointer to a rewritable contiguous block of memory of
* size at least secp256k1_context_prealloc_size(flags)
* size at least secp256k1_context_preallocated_size(flags)
* bytes, suitably aligned to hold an object of any type
* (cannot be NULL)
* flags: which parts of the context to initialize.
*
* See also secp256k1_context_randomize.
*/
SECP256K1_API secp256k1_context* secp256k1_context_prealloc_create(
SECP256K1_API secp256k1_context* secp256k1_context_preallocated_create(
void* prealloc,
unsigned int flags
) SECP256K1_ARG_NONNULL(1) SECP256K1_WARN_UNUSED_RESULT;
Expand All @@ -40,12 +40,12 @@ SECP256K1_API secp256k1_context* secp256k1_context_prealloc_create(
* caller-provided memory.
*
* The purpose of this function is to determine how much memory must be provided
* to secp256k1_context_prealloc_clone when copying the context ctx.
* to secp256k1_context_preallocated_clone when copying the context ctx.
*
* Returns: the required size of the caller-provided memory block.
* In: ctx: an existing context to copy (cannot be NULL)
*/
SECP256K1_API size_t secp256k1_context_prealloc_clone_size(
SECP256K1_API size_t secp256k1_context_preallocated_clone_size(
const secp256k1_context* ctx
) SECP256K1_ARG_NONNULL(1) SECP256K1_WARN_UNUSED_RESULT;

Expand All @@ -54,11 +54,11 @@ SECP256K1_API size_t secp256k1_context_prealloc_clone_size(
* Returns: a newly created context object.
* Args: ctx: an existing context to copy (cannot be NULL)
* In: prealloc: a pointer to a rewritable contiguous block of memory of
* size at least secp256k1_context_prealloc_size(flags)
* size at least secp256k1_context_preallocated_size(flags)
* bytes, suitably aligned to hold an object of any type
* (cannot be NULL)
*/
SECP256K1_API secp256k1_context* secp256k1_context_prealloc_clone(
SECP256K1_API secp256k1_context* secp256k1_context_preallocated_clone(
const secp256k1_context* ctx,
void* prealloc
) SECP256K1_ARG_NONNULL(1) SECP256K1_ARG_NONNULL(2) SECP256K1_WARN_UNUSED_RESULT;
Expand All @@ -69,21 +69,21 @@ SECP256K1_API secp256k1_context* secp256k1_context_prealloc_clone(
* The context pointer may not be used afterwards.
*
* The context to destroy must have been created using
* secp256k1_context_prealloc_create or secp256k1_context_prealloc_clone.
* secp256k1_context_preallocated_create or secp256k1_context_preallocated_clone.
* If the context has instead been created using secp256k1_context_create or
* secp256k1_context_clone, the behaviour is undefined. In that case,
* secp256k1_context_destroy must be used instead.
*
* Args: ctx: an existing context to destroy, constructed using
* secp256k1_context_prealloc_create or
* secp256k1_context_prealloc_clone (cannot be NULL)
* secp256k1_context_preallocated_create or
* secp256k1_context_preallocated_clone (cannot be NULL)
*/
SECP256K1_API void secp256k1_context_prealloc_destroy(
SECP256K1_API void secp256k1_context_preallocated_destroy(
secp256k1_context* ctx
);

#ifdef __cplusplus
}
#endif

#endif /* SECP256K1_PREALLOC_H */
#endif /* SECP256K1_PREALLOCATED_H */
2 changes: 1 addition & 1 deletion src/ecmult.h
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,7 @@ typedef struct {
#endif
} secp256k1_ecmult_context;

static size_t secp256k1_ecmult_context_prealloc_size(void);
static size_t secp256k1_ecmult_context_preallocated_size(void);
static void secp256k1_ecmult_context_init(secp256k1_ecmult_context *ctx);
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);
Expand Down
2 changes: 1 addition & 1 deletion src/ecmult_gen.h
Original file line number Diff line number Diff line change
Expand Up @@ -28,7 +28,7 @@ typedef struct {
secp256k1_gej initial;
} secp256k1_ecmult_gen_context;

static size_t secp256k1_ecmult_gen_context_prealloc_size(void);
static size_t secp256k1_ecmult_gen_context_preallocated_size(void);
static void secp256k1_ecmult_gen_context_init(secp256k1_ecmult_gen_context* ctx);
static void secp256k1_ecmult_gen_context_build(secp256k1_ecmult_gen_context* ctx, void **prealloc);
static void secp256k1_ecmult_gen_context_finalize_memcpy(secp256k1_ecmult_gen_context *dst, const secp256k1_ecmult_gen_context* src);
Expand Down
6 changes: 3 additions & 3 deletions src/ecmult_gen_impl.h
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,7 @@
#include "ecmult_static_context.h"
#endif

static size_t secp256k1_ecmult_gen_context_prealloc_size(void) {
static size_t secp256k1_ecmult_gen_context_preallocated_size(void) {
#ifndef USE_ECMULT_STATIC_PRECOMPUTATION
return ROUND_TO_ALIGN(sizeof(*((secp256k1_ecmult_gen_context*) NULL)->prec));
#else
Expand All @@ -34,15 +34,15 @@ static void secp256k1_ecmult_gen_context_build(secp256k1_ecmult_gen_context *ctx
secp256k1_gej gj;
secp256k1_gej nums_gej;
int i, j;
size_t const prealloc_size = secp256k1_ecmult_gen_context_prealloc_size();
size_t const prealloc_size = secp256k1_ecmult_gen_context_preallocated_size();
void* const base = *prealloc;
#endif

if (ctx->prec != NULL) {
return;
}
#ifndef USE_ECMULT_STATIC_PRECOMPUTATION
ctx->prec = (secp256k1_ge_storage (*)[64][16])manual_alloc(prealloc, prealloc_size, base, prealloc_size);
ctx->prec = (secp256k1_ge_storage (*)[64][16])manual_malloc(prealloc, prealloc_size, base, prealloc_size);

/* get the generator */
secp256k1_gej_set_ge(&gj, &secp256k1_ge_const_g);
Expand Down
8 changes: 4 additions & 4 deletions src/ecmult_impl.h
Original file line number Diff line number Diff line change
Expand Up @@ -254,7 +254,7 @@ static void secp256k1_ecmult_odd_multiples_table_storage_var(const int n, secp25
} \
} while(0)

static size_t secp256k1_ecmult_context_prealloc_size(void) {
static size_t secp256k1_ecmult_context_preallocated_size(void) {
int ret = ROUND_TO_ALIGN(sizeof((*((secp256k1_ecmult_context*) NULL)->pre_g)[0]) * ECMULT_TABLE_SIZE(WINDOW_G));
#ifdef USE_ENDOMORPHISM
ret += ROUND_TO_ALIGN(sizeof((*((secp256k1_ecmult_context*) NULL)->pre_g_128)[0]) * ECMULT_TABLE_SIZE(WINDOW_G));
Expand All @@ -272,7 +272,7 @@ static void secp256k1_ecmult_context_init(secp256k1_ecmult_context *ctx) {
static void secp256k1_ecmult_context_build(secp256k1_ecmult_context *ctx, void **prealloc) {
secp256k1_gej gj;
void* const base = *prealloc;
size_t const prealloc_size = secp256k1_ecmult_context_prealloc_size();
size_t const prealloc_size = secp256k1_ecmult_context_preallocated_size();

if (ctx->pre_g != NULL) {
return;
Expand All @@ -281,7 +281,7 @@ static void secp256k1_ecmult_context_build(secp256k1_ecmult_context *ctx, void *
/* get the generator */
secp256k1_gej_set_ge(&gj, &secp256k1_ge_const_g);

ctx->pre_g = (secp256k1_ge_storage (*)[])manual_alloc(prealloc, sizeof((*ctx->pre_g)[0]) * ECMULT_TABLE_SIZE(WINDOW_G), base, prealloc_size);
ctx->pre_g = (secp256k1_ge_storage (*)[])manual_malloc(prealloc, sizeof((*ctx->pre_g)[0]) * ECMULT_TABLE_SIZE(WINDOW_G), base, prealloc_size);

/* precompute the tables with odd multiples */
secp256k1_ecmult_odd_multiples_table_storage_var(ECMULT_TABLE_SIZE(WINDOW_G), *ctx->pre_g, &gj);
Expand All @@ -291,7 +291,7 @@ static void secp256k1_ecmult_context_build(secp256k1_ecmult_context *ctx, void *
secp256k1_gej g_128j;
int i;

ctx->pre_g_128 = (secp256k1_ge_storage (*)[])manual_alloc(prealloc, sizeof((*ctx->pre_g_128)[0]) * ECMULT_TABLE_SIZE(WINDOW_G), base, prealloc_size);
ctx->pre_g_128 = (secp256k1_ge_storage (*)[])manual_malloc(prealloc, sizeof((*ctx->pre_g_128)[0]) * ECMULT_TABLE_SIZE(WINDOW_G), base, prealloc_size);

/* calculate 2^128*generator */
g_128j = gj;
Expand Down
6 changes: 3 additions & 3 deletions src/gen_context.c
Original file line number Diff line number Diff line change
Expand Up @@ -47,7 +47,7 @@ int main(int argc, char **argv) {
fprintf(fp, "#define SC SECP256K1_GE_STORAGE_CONST\n");
fprintf(fp, "static const secp256k1_ge_storage secp256k1_ecmult_static_context[64][16] = {\n");

base = checked_malloc(&default_error_callback, secp256k1_ecmult_gen_context_prealloc_size());
base = checked_malloc(&default_error_callback, secp256k1_ecmult_gen_context_preallocated_size());
prealloc = base;
secp256k1_ecmult_gen_context_init(&ctx);
secp256k1_ecmult_gen_context_build(&ctx, &prealloc);
Expand All @@ -70,10 +70,10 @@ int main(int argc, char **argv) {
fprintf(fp,"};\n");
secp256k1_ecmult_gen_context_clear(&ctx);
free(base);

fprintf(fp, "#undef SC\n");
fprintf(fp, "#endif\n");
fclose(fp);

return 0;
}
36 changes: 18 additions & 18 deletions src/secp256k1.c
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@
**********************************************************************/

#include "include/secp256k1.h"
#include "include/secp256k1_prealloc.h"
#include "include/secp256k1_preallocated.h"

#include "util.h"
#include "num_impl.h"
Expand Down Expand Up @@ -65,7 +65,7 @@ static secp256k1_context secp256k1_context_no_precomp_ = {
};
secp256k1_context *secp256k1_context_no_precomp = &secp256k1_context_no_precomp_;

size_t secp256k1_context_prealloc_size(unsigned int flags) {
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)) {
Expand All @@ -76,34 +76,34 @@ size_t secp256k1_context_prealloc_size(unsigned int flags) {
}

if (flags & SECP256K1_FLAGS_BIT_CONTEXT_SIGN) {
ret += secp256k1_ecmult_gen_context_prealloc_size();
ret += secp256k1_ecmult_gen_context_preallocated_size();
}
if (flags & SECP256K1_FLAGS_BIT_CONTEXT_VERIFY) {
ret += secp256k1_ecmult_context_prealloc_size();
ret += secp256k1_ecmult_context_preallocated_size();
}
return ret;
}

size_t secp256k1_context_prealloc_size_for_clone(const secp256k1_context* ctx) {
size_t secp256k1_context_preallocated_size_for_clone(const secp256k1_context* ctx) {
size_t ret = ROUND_TO_ALIGN(sizeof(secp256k1_context));
VERIFY_CHECK(ctx != NULL);
if (secp256k1_ecmult_gen_context_is_built(&ctx->ecmult_gen_ctx)) {
ret += secp256k1_ecmult_gen_context_prealloc_size();
ret += secp256k1_ecmult_gen_context_preallocated_size();
}
if (secp256k1_ecmult_context_is_built(&ctx->ecmult_ctx)) {
ret += secp256k1_ecmult_context_prealloc_size();
ret += secp256k1_ecmult_context_preallocated_size();
}
return ret;
}

secp256k1_context* secp256k1_context_prealloc_create(void* prealloc, unsigned int flags) {
secp256k1_context* secp256k1_context_preallocated_create(void* prealloc, unsigned int flags) {
void* const base = prealloc;
size_t prealloc_size;
secp256k1_context* ret;

VERIFY_CHECK(prealloc != NULL);
prealloc_size = secp256k1_context_prealloc_size(flags);
ret = (secp256k1_context*)manual_alloc(&prealloc, sizeof(secp256k1_context), base, prealloc_size);
prealloc_size = secp256k1_context_preallocated_size(flags);
ret = (secp256k1_context*)manual_malloc(&prealloc, sizeof(secp256k1_context), base, prealloc_size);
ret->illegal_callback = default_illegal_callback;
ret->error_callback = default_error_callback;

Expand All @@ -128,23 +128,23 @@ secp256k1_context* secp256k1_context_prealloc_create(void* prealloc, unsigned in
}

secp256k1_context* secp256k1_context_create(unsigned int flags) {
size_t const prealloc_size = secp256k1_context_prealloc_size(flags);
size_t const prealloc_size = secp256k1_context_preallocated_size(flags);
secp256k1_context* ctx = (secp256k1_context*)checked_malloc(&default_error_callback, prealloc_size);
if (EXPECT(secp256k1_context_prealloc_create(ctx, flags) == NULL, 0)) {
if (EXPECT(secp256k1_context_preallocated_create(ctx, flags) == NULL, 0)) {
free(ctx);
return NULL;
}

return ctx;
}

secp256k1_context* secp256k1_context_prealloc_clone(const secp256k1_context* ctx, void* prealloc) {
secp256k1_context* secp256k1_context_preallocated_clone(const secp256k1_context* ctx, void* prealloc) {
size_t prealloc_size;
secp256k1_context* ret;
VERIFY_CHECK(ctx != NULL);
ARG_CHECK(prealloc != NULL);

prealloc_size = secp256k1_context_prealloc_size_for_clone(ctx);
prealloc_size = secp256k1_context_preallocated_size_for_clone(ctx);
ret = (secp256k1_context*)prealloc;
memcpy(ret, ctx, prealloc_size);
secp256k1_ecmult_gen_context_finalize_memcpy(&ret->ecmult_gen_ctx, &ctx->ecmult_gen_ctx);
Expand All @@ -157,13 +157,13 @@ secp256k1_context* secp256k1_context_clone(const secp256k1_context* ctx) {
size_t prealloc_size;

VERIFY_CHECK(ctx != NULL);
prealloc_size = secp256k1_context_prealloc_size_for_clone(ctx);
prealloc_size = secp256k1_context_preallocated_size_for_clone(ctx);
ret = (secp256k1_context*)checked_malloc(&ctx->error_callback, prealloc_size);
ret = secp256k1_context_prealloc_clone(ctx, ret);
ret = secp256k1_context_preallocated_clone(ctx, ret);
return ret;
}

void secp256k1_context_prealloc_destroy(secp256k1_context* ctx) {
void secp256k1_context_preallocated_destroy(secp256k1_context* ctx) {
if (ctx != NULL) {
secp256k1_ecmult_context_clear(&ctx->ecmult_ctx);
secp256k1_ecmult_gen_context_clear(&ctx->ecmult_gen_ctx);
Expand All @@ -172,7 +172,7 @@ void secp256k1_context_prealloc_destroy(secp256k1_context* ctx) {

void secp256k1_context_destroy(secp256k1_context* ctx) {
if (ctx != NULL) {
secp256k1_context_prealloc_destroy(ctx);
secp256k1_context_preallocated_destroy(ctx);
free(ctx);
}
}
Expand Down
Loading

0 comments on commit 856f880

Please sign in to comment.