Browse Source
1897b8e Merge pull request #229 efc571c Add simple testcases for signing with rfc6979 extra entropy. 1573a10 Add ability to pass extra entropy to rfc6979 3087bc4 Merge pull request #228 d9b9f11 Merge pull request #218 0065a8f Eliminate multiple-returns from secp256k1.c. 354ffa3 Make secp256k1_ec_pubkey_create reject oversized secrets. 27bc131 Silence some warnings from pedantic static analysis tools, improve compatibility with C++. 3b7ea63 Merge pull request #221 f789c5b Merge pull request #215 4bc273b Merge pull request #222 137a8ec Merge pull request #216 7c3771d Disable overlength-strings warnings. 8956111 use 128-bit hex seed 02efd06 Use RFC6979 for test PRNGs ae55e85 Use faster byteswapping and avoid alignment-increasing casts. 443cd4b Get rid of hex format and some binary conversions 0bada0e Merge #214: Improve signing API documentation & specification 8030d7c Improve signing API documentation & specification 7b2fc1c Merge #213: Removed gotos, which are hard to trace and maintain. 11690d3 Removed gotos, which are hard to trace and maintain. 122a1ec Merge pull request #205 035406d Merge pull request #206 2d4cd53 Merge pull request #161 34b898d Additional comments for the testing PRNG and a seeding fix. 6efd6e7 Some comments explaining some of the constants in the code. ffccfd2 x86_64 assembly optimization for scalar_4x64 67cbdf0 Merge pull request #207 039723d Benchmarks for all internal operations 6cc8425 Include a comment on secp256k1_ecdsa_sign explaining low-s. f88343f Merge pull request #203 d61e899 Add group operation counts 2473f17 Merge pull request #202 b5bbce6 Some readme updates, e.g. removal of the GMP field. f0d851e Merge pull request #201 a0ea884 Merge pull request #200 f735446 Convert the rest of the codebase to C89. bf2e1ac Convert tests to C89. (also fixes a use of bare "inline" in field) fc8285f Merge pull request #199 fff412e Merge pull request #197 4be8d6f Centralize the definition of uint128_t and use it uniformly. d9543c9 Switch scalar code to C89. fcc48c4 Remove the non-storage cmov 55422b6 Switch ecmult_gen to use storage types 41f8455 Use group element storage type in EC multiplications e68d720 Add group element storage type ff889f7 Field storage type 7137be8 Merge pull request #196 0768bd5 Get rid of variable-length hex string conversions e84e761 Merge pull request #195 792bcdb Covert several more files to C89. 45cdf44 Merge pull request #193 17db09e Merge pull request #194 402878a fix ifdef/ifndef 25b35c7 Convert field code to strict C89 (+ long long, +__int128) 3627437 C89 nits and dead code removal. a9f350d Merge pull request #191 4732d26 Convert the field/group/ecdsa constant initialization to static consts 19f3e76 Remove unused secp256k1_fe_inner_{start, stop} functions f1ebfe3 Convert the scalar constant initialization to static consts git-subtree-dir: src/secp256k1 git-subtree-split: 1897b8e90bbbdcd919427c9a8ae35b420e919d8f0.14
Pieter Wuille
10 years ago
38 changed files with 2525 additions and 1465 deletions
@ -0,0 +1,318 @@
@@ -0,0 +1,318 @@
|
||||
/**********************************************************************
|
||||
* Copyright (c) 2014-2015 Pieter Wuille * |
||||
* Distributed under the MIT software license, see the accompanying * |
||||
* file COPYING or http://www.opensource.org/licenses/mit-license.php.*
|
||||
**********************************************************************/ |
||||
#include <stdio.h> |
||||
|
||||
#include "include/secp256k1.h" |
||||
|
||||
#include "util.h" |
||||
#include "hash_impl.h" |
||||
#include "num_impl.h" |
||||
#include "field_impl.h" |
||||
#include "group_impl.h" |
||||
#include "scalar_impl.h" |
||||
#include "ecmult_impl.h" |
||||
#include "bench.h" |
||||
|
||||
typedef struct { |
||||
secp256k1_scalar_t scalar_x, scalar_y; |
||||
secp256k1_fe_t fe_x, fe_y; |
||||
secp256k1_ge_t ge_x, ge_y; |
||||
secp256k1_gej_t gej_x, gej_y; |
||||
unsigned char data[32]; |
||||
int wnaf[256]; |
||||
} bench_inv_t; |
||||
|
||||
void bench_setup(void* arg) { |
||||
bench_inv_t *data = (bench_inv_t*)arg; |
||||
|
||||
static const unsigned char init_x[32] = { |
||||
0x02, 0x03, 0x05, 0x07, 0x0b, 0x0d, 0x11, 0x13, |
||||
0x17, 0x1d, 0x1f, 0x25, 0x29, 0x2b, 0x2f, 0x35, |
||||
0x3b, 0x3d, 0x43, 0x47, 0x49, 0x4f, 0x53, 0x59, |
||||
0x61, 0x65, 0x67, 0x6b, 0x6d, 0x71, 0x7f, 0x83 |
||||
}; |
||||
|
||||
static const unsigned char init_y[32] = { |
||||
0x82, 0x83, 0x85, 0x87, 0x8b, 0x8d, 0x81, 0x83, |
||||
0x97, 0xad, 0xaf, 0xb5, 0xb9, 0xbb, 0xbf, 0xc5, |
||||
0xdb, 0xdd, 0xe3, 0xe7, 0xe9, 0xef, 0xf3, 0xf9, |
||||
0x11, 0x15, 0x17, 0x1b, 0x1d, 0xb1, 0xbf, 0xd3 |
||||
}; |
||||
|
||||
secp256k1_scalar_set_b32(&data->scalar_x, init_x, NULL); |
||||
secp256k1_scalar_set_b32(&data->scalar_y, init_y, NULL); |
||||
secp256k1_fe_set_b32(&data->fe_x, init_x); |
||||
secp256k1_fe_set_b32(&data->fe_y, init_y); |
||||
CHECK(secp256k1_ge_set_xo_var(&data->ge_x, &data->fe_x, 0)); |
||||
CHECK(secp256k1_ge_set_xo_var(&data->ge_y, &data->fe_y, 1)); |
||||
secp256k1_gej_set_ge(&data->gej_x, &data->ge_x); |
||||
secp256k1_gej_set_ge(&data->gej_y, &data->ge_y); |
||||
memcpy(data->data, init_x, 32); |
||||
} |
||||
|
||||
void bench_scalar_add(void* arg) { |
||||
int i; |
||||
bench_inv_t *data = (bench_inv_t*)arg; |
||||
|
||||
for (i = 0; i < 2000000; i++) { |
||||
secp256k1_scalar_add(&data->scalar_x, &data->scalar_x, &data->scalar_y); |
||||
} |
||||
} |
||||
|
||||
void bench_scalar_negate(void* arg) { |
||||
int i; |
||||
bench_inv_t *data = (bench_inv_t*)arg; |
||||
|
||||
for (i = 0; i < 2000000; i++) { |
||||
secp256k1_scalar_negate(&data->scalar_x, &data->scalar_x); |
||||
} |
||||
} |
||||
|
||||
void bench_scalar_sqr(void* arg) { |
||||
int i; |
||||
bench_inv_t *data = (bench_inv_t*)arg; |
||||
|
||||
for (i = 0; i < 200000; i++) { |
||||
secp256k1_scalar_sqr(&data->scalar_x, &data->scalar_x); |
||||
} |
||||
} |
||||
|
||||
void bench_scalar_mul(void* arg) { |
||||
int i; |
||||
bench_inv_t *data = (bench_inv_t*)arg; |
||||
|
||||
for (i = 0; i < 200000; i++) { |
||||
secp256k1_scalar_mul(&data->scalar_x, &data->scalar_x, &data->scalar_y); |
||||
} |
||||
} |
||||
|
||||
#ifdef USE_ENDOMORPHISM |
||||
void bench_scalar_split(void* arg) { |
||||
int i; |
||||
bench_inv_t *data = (bench_inv_t*)arg; |
||||
|
||||
for (i = 0; i < 20000; i++) { |
||||
secp256k1_scalar_t l, r; |
||||
secp256k1_scalar_split_lambda_var(&l, &r, &data->scalar_x); |
||||
secp256k1_scalar_add(&data->scalar_x, &data->scalar_x, &data->scalar_y); |
||||
} |
||||
} |
||||
#endif |
||||
|
||||
void bench_scalar_inverse(void* arg) { |
||||
int i; |
||||
bench_inv_t *data = (bench_inv_t*)arg; |
||||
|
||||
for (i = 0; i < 2000; i++) { |
||||
secp256k1_scalar_inverse(&data->scalar_x, &data->scalar_x); |
||||
secp256k1_scalar_add(&data->scalar_x, &data->scalar_x, &data->scalar_y); |
||||
} |
||||
} |
||||
|
||||
void bench_scalar_inverse_var(void* arg) { |
||||
int i; |
||||
bench_inv_t *data = (bench_inv_t*)arg; |
||||
|
||||
for (i = 0; i < 2000; i++) { |
||||
secp256k1_scalar_inverse_var(&data->scalar_x, &data->scalar_x); |
||||
secp256k1_scalar_add(&data->scalar_x, &data->scalar_x, &data->scalar_y); |
||||
} |
||||
} |
||||
|
||||
void bench_field_normalize(void* arg) { |
||||
int i; |
||||
bench_inv_t *data = (bench_inv_t*)arg; |
||||
|
||||
for (i = 0; i < 2000000; i++) { |
||||
secp256k1_fe_normalize(&data->fe_x); |
||||
} |
||||
} |
||||
|
||||
void bench_field_normalize_weak(void* arg) { |
||||
int i; |
||||
bench_inv_t *data = (bench_inv_t*)arg; |
||||
|
||||
for (i = 0; i < 2000000; i++) { |
||||
secp256k1_fe_normalize_weak(&data->fe_x); |
||||
} |
||||
} |
||||
|
||||
void bench_field_mul(void* arg) { |
||||
int i; |
||||
bench_inv_t *data = (bench_inv_t*)arg; |
||||
|
||||
for (i = 0; i < 200000; i++) { |
||||
secp256k1_fe_mul(&data->fe_x, &data->fe_x, &data->fe_y); |
||||
} |
||||
} |
||||
|
||||
void bench_field_sqr(void* arg) { |
||||
int i; |
||||
bench_inv_t *data = (bench_inv_t*)arg; |
||||
|
||||
for (i = 0; i < 200000; i++) { |
||||
secp256k1_fe_sqr(&data->fe_x, &data->fe_x); |
||||
} |
||||
} |
||||
|
||||
void bench_field_inverse(void* arg) { |
||||
int i; |
||||
bench_inv_t *data = (bench_inv_t*)arg; |
||||
|
||||
for (i = 0; i < 20000; i++) { |
||||
secp256k1_fe_inv(&data->fe_x, &data->fe_x); |
||||
secp256k1_fe_add(&data->fe_x, &data->fe_y); |
||||
} |
||||
} |
||||
|
||||
void bench_field_inverse_var(void* arg) { |
||||
int i; |
||||
bench_inv_t *data = (bench_inv_t*)arg; |
||||
|
||||
for (i = 0; i < 20000; i++) { |
||||
secp256k1_fe_inv_var(&data->fe_x, &data->fe_x); |
||||
secp256k1_fe_add(&data->fe_x, &data->fe_y); |
||||
} |
||||
} |
||||
|
||||
void bench_field_sqrt_var(void* arg) { |
||||
int i; |
||||
bench_inv_t *data = (bench_inv_t*)arg; |
||||
|
||||
for (i = 0; i < 20000; i++) { |
||||
secp256k1_fe_sqrt_var(&data->fe_x, &data->fe_x); |
||||
secp256k1_fe_add(&data->fe_x, &data->fe_y); |
||||
} |
||||
} |
||||
|
||||
void bench_group_double_var(void* arg) { |
||||
int i; |
||||
bench_inv_t *data = (bench_inv_t*)arg; |
||||
|
||||
for (i = 0; i < 200000; i++) { |
||||
secp256k1_gej_double_var(&data->gej_x, &data->gej_x); |
||||
} |
||||
} |
||||
|
||||
void bench_group_add_var(void* arg) { |
||||
int i; |
||||
bench_inv_t *data = (bench_inv_t*)arg; |
||||
|
||||
for (i = 0; i < 200000; i++) { |
||||
secp256k1_gej_add_var(&data->gej_x, &data->gej_x, &data->gej_y); |
||||
} |
||||
} |
||||
|
||||
void bench_group_add_affine(void* arg) { |
||||
int i; |
||||
bench_inv_t *data = (bench_inv_t*)arg; |
||||
|
||||
for (i = 0; i < 200000; i++) { |
||||
secp256k1_gej_add_ge(&data->gej_x, &data->gej_x, &data->ge_y); |
||||
} |
||||
} |
||||
|
||||
void bench_group_add_affine_var(void* arg) { |
||||
int i; |
||||
bench_inv_t *data = (bench_inv_t*)arg; |
||||
|
||||
for (i = 0; i < 200000; i++) { |
||||
secp256k1_gej_add_ge_var(&data->gej_x, &data->gej_x, &data->ge_y); |
||||
} |
||||
} |
||||
|
||||
void bench_ecmult_wnaf(void* arg) { |
||||
int i; |
||||
bench_inv_t *data = (bench_inv_t*)arg; |
||||
|
||||
for (i = 0; i < 20000; i++) { |
||||
secp256k1_ecmult_wnaf(data->wnaf, &data->scalar_x, WINDOW_A); |
||||
secp256k1_scalar_add(&data->scalar_x, &data->scalar_x, &data->scalar_y); |
||||
} |
||||
} |
||||
|
||||
|
||||
void bench_sha256(void* arg) { |
||||
int i; |
||||
bench_inv_t *data = (bench_inv_t*)arg; |
||||
secp256k1_sha256_t sha; |
||||
|
||||
for (i = 0; i < 20000; i++) { |
||||
secp256k1_sha256_initialize(&sha); |
||||
secp256k1_sha256_write(&sha, data->data, 32); |
||||
secp256k1_sha256_finalize(&sha, data->data); |
||||
} |
||||
} |
||||
|
||||
void bench_hmac_sha256(void* arg) { |
||||
int i; |
||||
bench_inv_t *data = (bench_inv_t*)arg; |
||||
secp256k1_hmac_sha256_t hmac; |
||||
|
||||
for (i = 0; i < 20000; i++) { |
||||
secp256k1_hmac_sha256_initialize(&hmac, data->data, 32); |
||||
secp256k1_hmac_sha256_write(&hmac, data->data, 32); |
||||
secp256k1_hmac_sha256_finalize(&hmac, data->data); |
||||
} |
||||
} |
||||
|
||||
void bench_rfc6979_hmac_sha256(void* arg) { |
||||
int i; |
||||
bench_inv_t *data = (bench_inv_t*)arg; |
||||
secp256k1_rfc6979_hmac_sha256_t rng; |
||||
|
||||
for (i = 0; i < 20000; i++) { |
||||
secp256k1_rfc6979_hmac_sha256_initialize(&rng, data->data, 32, data->data, 32, NULL, 0); |
||||
secp256k1_rfc6979_hmac_sha256_generate(&rng, data->data, 32); |
||||
} |
||||
} |
||||
|
||||
|
||||
int have_flag(int argc, char** argv, char *flag) { |
||||
char** argm = argv + argc; |
||||
argv++; |
||||
if (argv == argm) { |
||||
return 1; |
||||
} |
||||
while (argv != NULL && argv != argm) { |
||||
if (strcmp(*argv, flag) == 0) return 1; |
||||
argv++; |
||||
} |
||||
return 0; |
||||
} |
||||
|
||||
int main(int argc, char **argv) { |
||||
bench_inv_t data; |
||||
if (have_flag(argc, argv, "scalar") || have_flag(argc, argv, "add")) run_benchmark("scalar_add", bench_scalar_add, bench_setup, NULL, &data, 10, 2000000); |
||||
if (have_flag(argc, argv, "scalar") || have_flag(argc, argv, "negate")) run_benchmark("scalar_negate", bench_scalar_negate, bench_setup, NULL, &data, 10, 2000000); |
||||
if (have_flag(argc, argv, "scalar") || have_flag(argc, argv, "sqr")) run_benchmark("scalar_sqr", bench_scalar_sqr, bench_setup, NULL, &data, 10, 200000); |
||||
if (have_flag(argc, argv, "scalar") || have_flag(argc, argv, "mul")) run_benchmark("scalar_mul", bench_scalar_mul, bench_setup, NULL, &data, 10, 200000); |
||||
#ifdef USE_ENDOMORPHISM |
||||
if (have_flag(argc, argv, "scalar") || have_flag(argc, argv, "split")) run_benchmark("scalar_split", bench_scalar_split, bench_setup, NULL, &data, 10, 20000); |
||||
#endif |
||||
if (have_flag(argc, argv, "scalar") || have_flag(argc, argv, "inverse")) run_benchmark("scalar_inverse", bench_scalar_inverse, bench_setup, NULL, &data, 10, 2000); |
||||
if (have_flag(argc, argv, "scalar") || have_flag(argc, argv, "inverse")) run_benchmark("scalar_inverse_var", bench_scalar_inverse_var, bench_setup, NULL, &data, 10, 2000); |
||||
|
||||
if (have_flag(argc, argv, "field") || have_flag(argc, argv, "normalize")) run_benchmark("field_normalize", bench_field_normalize, bench_setup, NULL, &data, 10, 2000000); |
||||
if (have_flag(argc, argv, "field") || have_flag(argc, argv, "normalize")) run_benchmark("field_normalize_weak", bench_field_normalize_weak, bench_setup, NULL, &data, 10, 2000000); |
||||
if (have_flag(argc, argv, "field") || have_flag(argc, argv, "sqr")) run_benchmark("field_sqr", bench_field_sqr, bench_setup, NULL, &data, 10, 200000); |
||||
if (have_flag(argc, argv, "field") || have_flag(argc, argv, "mul")) run_benchmark("field_mul", bench_field_mul, bench_setup, NULL, &data, 10, 200000); |
||||
if (have_flag(argc, argv, "field") || have_flag(argc, argv, "inverse")) run_benchmark("field_inverse", bench_field_inverse, bench_setup, NULL, &data, 10, 20000); |
||||
if (have_flag(argc, argv, "field") || have_flag(argc, argv, "inverse")) run_benchmark("field_inverse_var", bench_field_inverse_var, bench_setup, NULL, &data, 10, 20000); |
||||
if (have_flag(argc, argv, "field") || have_flag(argc, argv, "sqrt")) run_benchmark("field_sqrt_var", bench_field_sqrt_var, bench_setup, NULL, &data, 10, 20000); |
||||
|
||||
if (have_flag(argc, argv, "group") || have_flag(argc, argv, "double")) run_benchmark("group_double_var", bench_group_double_var, bench_setup, NULL, &data, 10, 200000); |
||||
if (have_flag(argc, argv, "group") || have_flag(argc, argv, "add")) run_benchmark("group_add_var", bench_group_add_var, bench_setup, NULL, &data, 10, 200000); |
||||
if (have_flag(argc, argv, "group") || have_flag(argc, argv, "add")) run_benchmark("group_add_affine", bench_group_add_affine, bench_setup, NULL, &data, 10, 200000); |
||||
if (have_flag(argc, argv, "group") || have_flag(argc, argv, "add")) run_benchmark("group_add_affine_var", bench_group_add_affine_var, bench_setup, NULL, &data, 10, 200000); |
||||
|
||||
if (have_flag(argc, argv, "ecmult") || have_flag(argc, argv, "wnaf")) run_benchmark("ecmult_wnaf", bench_ecmult_wnaf, bench_setup, NULL, &data, 10, 20000); |
||||
|
||||
if (have_flag(argc, argv, "hash") || have_flag(argc, argv, "sha256")) run_benchmark("hash_sha256", bench_sha256, bench_setup, NULL, &data, 10, 20000); |
||||
if (have_flag(argc, argv, "hash") || have_flag(argc, argv, "hmac")) run_benchmark("hash_hmac_sha256", bench_hmac_sha256, bench_setup, NULL, &data, 10, 20000); |
||||
if (have_flag(argc, argv, "hash") || have_flag(argc, argv, "rng6979")) run_benchmark("hash_rfc6979_hmac_sha256", bench_rfc6979_hmac_sha256, bench_setup, NULL, &data, 10, 20000); |
||||
return 0; |
||||
} |
@ -1,52 +0,0 @@
@@ -1,52 +0,0 @@
|
||||
/**********************************************************************
|
||||
* Copyright (c) 2014 Pieter Wuille * |
||||
* Distributed under the MIT software license, see the accompanying * |
||||
* file COPYING or http://www.opensource.org/licenses/mit-license.php.*
|
||||
**********************************************************************/ |
||||
#include <stdio.h> |
||||
|
||||
#include "include/secp256k1.h" |
||||
|
||||
#include "util.h" |
||||
#include "num_impl.h" |
||||
#include "field_impl.h" |
||||
#include "group_impl.h" |
||||
#include "scalar_impl.h" |
||||
#include "bench.h" |
||||
|
||||
typedef struct { |
||||
secp256k1_scalar_t base, x; |
||||
} bench_inv_t; |
||||
|
||||
void bench_inv_setup(void* arg) { |
||||
bench_inv_t *data = (bench_inv_t*)arg; |
||||
|
||||
static const unsigned char init[32] = { |
||||
0x02, 0x03, 0x05, 0x07, 0x0b, 0x0d, 0x11, 0x13, |
||||
0x17, 0x1d, 0x1f, 0x25, 0x29, 0x2b, 0x2f, 0x35, |
||||
0x3b, 0x3d, 0x43, 0x47, 0x49, 0x4f, 0x53, 0x59, |
||||
0x61, 0x65, 0x67, 0x6b, 0x6d, 0x71, 0x7f, 0x83 |
||||
}; |
||||
|
||||
secp256k1_scalar_set_b32(&data->base, init, NULL); |
||||
secp256k1_scalar_set_b32(&data->x, init, NULL); |
||||
} |
||||
|
||||
void bench_inv(void* arg) { |
||||
bench_inv_t *data = (bench_inv_t*)arg; |
||||
|
||||
for (int i=0; i<20000; i++) { |
||||
secp256k1_scalar_inverse(&data->x, &data->x); |
||||
secp256k1_scalar_add(&data->x, &data->x, &data->base); |
||||
} |
||||
} |
||||
|
||||
int main(void) { |
||||
secp256k1_ge_start(); |
||||
|
||||
bench_inv_t data; |
||||
run_benchmark(bench_inv, bench_inv_setup, NULL, &data, 10, 20000); |
||||
|
||||
secp256k1_ge_stop(); |
||||
return 0; |
||||
} |
Loading…
Reference in new issue