-
Notifications
You must be signed in to change notification settings - Fork 1k
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
ecmult_gen: Move table creation to new file and force static prec
- Loading branch information
1 parent
ea5e8a9
commit 22dc2c0
Showing
7 changed files
with
105 additions
and
97 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,16 @@ | ||
/*********************************************************************** | ||
* Copyright (c) 2013, 2014, 2015 Pieter Wuille, Gregory Maxwell * | ||
* Distributed under the MIT software license, see the accompanying * | ||
* file COPYING or https://www.opensource.org/licenses/mit-license.php.* | ||
***********************************************************************/ | ||
|
||
#ifndef SECP256K1_ECMULT_GEN_PREC_H | ||
#define SECP256K1_ECMULT_GEN_PREC_H | ||
|
||
#include "ecmult_gen.h" | ||
|
||
static const size_t ECMULT_GEN_PREC_TABLE_SIZE = ROUND_TO_ALIGN(sizeof(*((secp256k1_ecmult_gen_context*) NULL)->prec)); | ||
|
||
static void secp256k1_ecmult_gen_create_prec_table(secp256k1_ecmult_gen_context *ctx, void **prealloc); | ||
|
||
#endif /* SECP256K1_ECMULT_GEN_PREC_H */ |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,78 @@ | ||
/*********************************************************************** | ||
* Copyright (c) 2013, 2014, 2015 Pieter Wuille, Gregory Maxwell * | ||
* Distributed under the MIT software license, see the accompanying * | ||
* file COPYING or https://www.opensource.org/licenses/mit-license.php.* | ||
***********************************************************************/ | ||
|
||
#ifndef SECP256K1_ECMULT_GEN_PREC_IMPL_H | ||
#define SECP256K1_ECMULT_GEN_PREC_IMPL_H | ||
|
||
#include "ecmult_gen_prec.h" | ||
#include "group_impl.h" | ||
#include "field_impl.h" | ||
#include "ecmult_gen.h" | ||
|
||
static void secp256k1_ecmult_gen_create_prec_table(secp256k1_ecmult_gen_context *ctx, void **prealloc) { | ||
secp256k1_ge prec[ECMULT_GEN_PREC_N * ECMULT_GEN_PREC_G]; | ||
secp256k1_gej gj; | ||
secp256k1_gej nums_gej; | ||
int i, j; | ||
size_t const prealloc_size = ECMULT_GEN_PREC_TABLE_SIZE; | ||
void* const base = *prealloc; | ||
ctx->prec = (secp256k1_ge_storage (*)[ECMULT_GEN_PREC_N][ECMULT_GEN_PREC_G])manual_alloc(prealloc, prealloc_size, base, prealloc_size); | ||
|
||
/* get the generator */ | ||
secp256k1_gej_set_ge(&gj, &secp256k1_ge_const_g); | ||
|
||
/* Construct a group element with no known corresponding scalar (nothing up my sleeve). */ | ||
{ | ||
static const unsigned char nums_b32[33] = "The scalar for this x is unknown"; | ||
secp256k1_fe nums_x; | ||
secp256k1_ge nums_ge; | ||
int r; | ||
r = secp256k1_fe_set_b32(&nums_x, nums_b32); | ||
(void)r; | ||
VERIFY_CHECK(r); | ||
r = secp256k1_ge_set_xo_var(&nums_ge, &nums_x, 0); | ||
(void)r; | ||
VERIFY_CHECK(r); | ||
secp256k1_gej_set_ge(&nums_gej, &nums_ge); | ||
/* Add G to make the bits in x uniformly distributed. */ | ||
secp256k1_gej_add_ge_var(&nums_gej, &nums_gej, &secp256k1_ge_const_g, NULL); | ||
} | ||
|
||
/* compute prec. */ | ||
{ | ||
secp256k1_gej precj[ECMULT_GEN_PREC_N * ECMULT_GEN_PREC_G]; /* Jacobian versions of prec. */ | ||
secp256k1_gej gbase; | ||
secp256k1_gej numsbase; | ||
gbase = gj; /* PREC_G^j * G */ | ||
numsbase = nums_gej; /* 2^j * nums. */ | ||
for (j = 0; j < ECMULT_GEN_PREC_N; j++) { | ||
/* Set precj[j*PREC_G .. j*PREC_G+(PREC_G-1)] to (numsbase, numsbase + gbase, ..., numsbase + (PREC_G-1)*gbase). */ | ||
precj[j*ECMULT_GEN_PREC_G] = numsbase; | ||
for (i = 1; i < ECMULT_GEN_PREC_G; i++) { | ||
secp256k1_gej_add_var(&precj[j*ECMULT_GEN_PREC_G + i], &precj[j*ECMULT_GEN_PREC_G + i - 1], &gbase, NULL); | ||
} | ||
/* Multiply gbase by PREC_G. */ | ||
for (i = 0; i < ECMULT_GEN_PREC_B; i++) { | ||
secp256k1_gej_double_var(&gbase, &gbase, NULL); | ||
} | ||
/* Multiply numbase by 2. */ | ||
secp256k1_gej_double_var(&numsbase, &numsbase, NULL); | ||
if (j == ECMULT_GEN_PREC_N - 2) { | ||
/* In the last iteration, numsbase is (1 - 2^j) * nums instead. */ | ||
secp256k1_gej_neg(&numsbase, &numsbase); | ||
secp256k1_gej_add_var(&numsbase, &numsbase, &nums_gej, NULL); | ||
} | ||
} | ||
secp256k1_ge_set_all_gej_var(prec, precj, ECMULT_GEN_PREC_N * ECMULT_GEN_PREC_G); | ||
} | ||
for (j = 0; j < ECMULT_GEN_PREC_N; j++) { | ||
for (i = 0; i < ECMULT_GEN_PREC_G; i++) { | ||
secp256k1_ge_to_storage(&(*ctx->prec)[j][i], &prec[j*ECMULT_GEN_PREC_G + i]); | ||
} | ||
} | ||
} | ||
|
||
#endif /* SECP256K1_ECMULT_GEN_PREC_IMPL_H */ |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters