-
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.
Add ability to use a statically generated ecmult context.
This vastly shrinks the size of the context required for signing on devices with memory-mapped Flash. Tables are generated by the new gen_context tool into a header.
- Loading branch information
Showing
5 changed files
with
84 additions
and
2 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
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,49 @@ | ||
/********************************************************************** | ||
* Copyright (c) 2013, 2014, 2015 Pieter Wuille, Gregory Maxwell * | ||
* Distributed under the MIT software license, see the accompanying * | ||
* file COPYING or http://www.opensource.org/licenses/mit-license.php.* | ||
**********************************************************************/ | ||
|
||
#if defined HAVE_CONFIG_H | ||
#include "libsecp256k1-config.h" | ||
#endif | ||
|
||
#undef USE_ECMULT_STATIC_CONTEXT | ||
#include "secp256k1.c" | ||
|
||
int main(int argc, char **argv) { | ||
secp256k1_ecmult_gen_context_t ctx; | ||
uint8_t* ctx_bytes; | ||
int ctx_len; | ||
int i; | ||
FILE* fp; | ||
|
||
(void)argc; | ||
(void)argv; | ||
|
||
fp = fopen("src/ecmult_static_context.h","w"); | ||
|
||
fprintf(fp, "#ifndef _SECP256K1_ECMULT_STATIC_CONTEXT_\n"); | ||
fprintf(fp, "#define _SECP256K1_ECMULT_STATIC_CONTEXT_\n"); | ||
fprintf(fp, "static const uint8_t secp256k1_ecmult_static_context[] = {\n"); | ||
|
||
secp256k1_ecmult_gen_context_init(&ctx); | ||
secp256k1_ecmult_gen_context_build(&ctx); | ||
ctx_bytes = (uint8_t*)ctx.prec; | ||
ctx_len = sizeof(*ctx.prec); | ||
for (i = 0; i < ctx_len; i++) { | ||
fprintf(fp, "0x%02x", ctx_bytes[i]); | ||
if (i < (ctx_len - 1)) { | ||
fprintf(fp, ","); | ||
} | ||
if ((i % 20) == 19) { | ||
fprintf(fp, "\n"); | ||
} | ||
} | ||
|
||
fprintf(fp, "};\n"); | ||
fprintf(fp, "#endif\n"); | ||
fclose(fp); | ||
|
||
return 0; | ||
} |