-
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.
72ae443 Improve perf. of cmov-based table lookup (Peter Dettman) 92e53fc Implement endomorphism optimization for secp256k1_ecmult_const (Andrew Poelstra) ed35d43 Make `secp256k1_scalar_add_bit` conditional; make `secp256k1_scalar_split_lambda_var` constant time (Andrew Poelstra) 91c0ce9 Add benchmarks for ECDH and const-time multiplication (Andrew Poelstra) 0739bbb Add ECDH module which works by hashing the output of ecmult_const (Andrew Poelstra) 4401500 Add constant-time multiply `secp256k1_ecmult_const` for ECDH (Andrew Poelstra) baa75da tests: add a couple tests (Andrew Poelstra)
- Loading branch information
Showing
22 changed files
with
886 additions
and
19 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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,4 +1,5 @@ | ||
bench_inv | ||
bench_ecdh | ||
bench_sign | ||
bench_verify | ||
bench_recover | ||
|
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,30 @@ | ||
#ifndef _SECP256K1_ECDH_ | ||
# define _SECP256K1_ECDH_ | ||
|
||
# include "secp256k1.h" | ||
|
||
# ifdef __cplusplus | ||
extern "C" { | ||
# endif | ||
|
||
/** Compute an EC Diffie-Hellman secret in constant time | ||
* Returns: 1: exponentiation was successful | ||
* 0: scalar was invalid (zero or overflow) | ||
* In: ctx: pointer to a context object (cannot be NULL) | ||
* point: pointer to a public point | ||
* scalar: a 32-byte scalar with which to multiply the point | ||
* Out: result: a 32-byte array which will be populated by an ECDH | ||
* secret computed from the point and scalar | ||
*/ | ||
SECP256K1_WARN_UNUSED_RESULT int secp256k1_ecdh( | ||
const secp256k1_context_t* ctx, | ||
unsigned char *result, | ||
const secp256k1_pubkey_t *point, | ||
const unsigned char *scalar | ||
) SECP256K1_ARG_NONNULL(1) SECP256K1_ARG_NONNULL(2) SECP256K1_ARG_NONNULL(3) SECP256K1_ARG_NONNULL(4); | ||
|
||
# ifdef __cplusplus | ||
} | ||
# endif | ||
|
||
#endif |
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,51 @@ | ||
/********************************************************************** | ||
* Copyright (c) 2015 Pieter Wuille, Andrew Poelstra * | ||
* Distributed under the MIT software license, see the accompanying * | ||
* file COPYING or http://www.opensource.org/licenses/mit-license.php.* | ||
**********************************************************************/ | ||
|
||
#include <string.h> | ||
|
||
#include "include/secp256k1.h" | ||
#include "include/secp256k1_ecdh.h" | ||
#include "util.h" | ||
#include "bench.h" | ||
|
||
typedef struct { | ||
secp256k1_context_t *ctx; | ||
secp256k1_pubkey_t point; | ||
unsigned char scalar[32]; | ||
} bench_ecdh_t; | ||
|
||
static void bench_ecdh_setup(void* arg) { | ||
int i; | ||
bench_ecdh_t *data = (bench_ecdh_t*)arg; | ||
const unsigned char point[] = { | ||
0x03, | ||
0x54, 0x94, 0xc1, 0x5d, 0x32, 0x09, 0x97, 0x06, | ||
0xc2, 0x39, 0x5f, 0x94, 0x34, 0x87, 0x45, 0xfd, | ||
0x75, 0x7c, 0xe3, 0x0e, 0x4e, 0x8c, 0x90, 0xfb, | ||
0xa2, 0xba, 0xd1, 0x84, 0xf8, 0x83, 0xc6, 0x9f | ||
}; | ||
|
||
data->ctx = secp256k1_context_create(0); | ||
for (i = 0; i < 32; i++) data->scalar[i] = i + 1; | ||
CHECK(secp256k1_ec_pubkey_parse(data->ctx, &data->point, point, sizeof(point)) == 1); | ||
} | ||
|
||
static void bench_ecdh(void* arg) { | ||
int i; | ||
unsigned char res[32]; | ||
bench_ecdh_t *data = (bench_ecdh_t*)arg; | ||
|
||
for (i = 0; i < 20000; i++) { | ||
CHECK(secp256k1_ecdh(data->ctx, res, &data->point, data->scalar) == 1); | ||
} | ||
} | ||
|
||
int main(void) { | ||
bench_ecdh_t data; | ||
|
||
run_benchmark("ecdh", bench_ecdh, bench_ecdh_setup, NULL, &data, 10, 20000); | ||
return 0; | ||
} |
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,15 @@ | ||
/********************************************************************** | ||
* Copyright (c) 2015 Andrew Poelstra * | ||
* Distributed under the MIT software license, see the accompanying * | ||
* file COPYING or http://www.opensource.org/licenses/mit-license.php.* | ||
**********************************************************************/ | ||
|
||
#ifndef _SECP256K1_ECMULT_CONST_ | ||
#define _SECP256K1_ECMULT_CONST_ | ||
|
||
#include "scalar.h" | ||
#include "group.h" | ||
|
||
static void secp256k1_ecmult_const(secp256k1_gej_t *r, const secp256k1_ge_t *a, const secp256k1_scalar_t *q); | ||
|
||
#endif |
Oops, something went wrong.