6#ifndef SECP256K1_MODULE_ELLSWIFT_BENCH_H
7#define SECP256K1_MODULE_ELLSWIFT_BENCH_H
9#include "../../../include/secp256k1_ellswift.h"
14 unsigned char rnd64[64];
20 static const unsigned char init[64] = {
21 0x78, 0x1f, 0xb7, 0xd4, 0x67, 0x7f, 0x08, 0x68,
22 0xdb, 0xe3, 0x1d, 0x7f, 0x1b, 0xb0, 0xf6, 0x9e,
23 0x0a, 0x64, 0xca, 0x32, 0x9e, 0xc6, 0x20, 0x79,
24 0x03, 0xf3, 0xd0, 0x46, 0x7a, 0x0f, 0xd2, 0x21,
25 0xb0, 0x2c, 0x46, 0xd8, 0xba, 0xca, 0x26, 0x4f,
26 0x8f, 0x8c, 0xd4, 0xdd, 0x2d, 0x04, 0xbe, 0x30,
27 0x48, 0x51, 0x1e, 0xd4, 0x16, 0xfd, 0x42, 0x85,
28 0x62, 0xc9, 0x02, 0xf9, 0x89, 0x84, 0xff, 0xdc
31 for (i = 0; i < 256; ++i) {
34 for (j = 0; j < 64; ++j) {
45 for (i = 0; i < iters; i++) {
54 for (i = 0; i < iters; i++) {
55 unsigned char buf[64];
57 memcpy(
data->rnd64, buf, 64);
67 for (i = 0; i < iters; i++) {
78 for (i = 0; i < iters; i++) {
81 data->rnd64 + (i % 33),
84 data->rnd64 + ((i + 16) % 33),
98 if (d ||
have_flag(argc, argv,
"ellswift") ||
have_flag(argc, argv,
"encode") ||
have_flag(argc, argv,
"ellswift_encode"))
run_benchmark(
"ellswift_encode",
bench_ellswift_encode,
bench_ellswift_setup, NULL, &
data, 10, iters);
99 if (d ||
have_flag(argc, argv,
"ellswift") ||
have_flag(argc, argv,
"decode") ||
have_flag(argc, argv,
"ellswift_decode"))
run_benchmark(
"ellswift_decode",
bench_ellswift_decode,
bench_ellswift_setup, NULL, &
data, 10, iters);
100 if (d ||
have_flag(argc, argv,
"ellswift") ||
have_flag(argc, argv,
"keygen") ||
have_flag(argc, argv,
"ellswift_keygen"))
run_benchmark(
"ellswift_keygen",
bench_ellswift_create,
bench_ellswift_setup, NULL, &
data, 10, iters);
101 if (d ||
have_flag(argc, argv,
"ellswift") ||
have_flag(argc, argv,
"ecdh") ||
have_flag(argc, argv,
"ellswift_ecdh"))
run_benchmark(
"ellswift_ecdh",
bench_ellswift_xdh,
bench_ellswift_setup, NULL, &
data, 10, iters);
static void run_benchmark(char *name, void(*benchmark)(void *), void(*setup)(void *), void(*teardown)(void *), void *data, int count, int iter)
static void bench_ellswift_setup(void *arg)
static void bench_ellswift_decode(void *arg, int iters)
static void bench_ellswift_create(void *arg, int iters)
void run_ellswift_bench(int iters, int argc, char **argv)
static void bench_ellswift_encode(void *arg, int iters)
static void bench_ellswift_xdh(void *arg, int iters)
#define CHECK(cond)
Unconditional failure on condition failure.
static int have_flag(int argc, char **argv, char *flag)
SECP256K1_API void secp256k1_context_destroy(secp256k1_context *ctx) SECP256K1_ARG_NONNULL(1)
Destroy a secp256k1 context object (created in dynamically allocated memory).
SECP256K1_API int secp256k1_ec_pubkey_serialize(const secp256k1_context *ctx, unsigned char *output, size_t *outputlen, const secp256k1_pubkey *pubkey, unsigned int flags) SECP256K1_ARG_NONNULL(1) SECP256K1_ARG_NONNULL(2) SECP256K1_ARG_NONNULL(3) SECP256K1_ARG_NONNULL(4)
Serialize a pubkey object into a serialized byte sequence.
SECP256K1_API secp256k1_context * secp256k1_context_create(unsigned int flags) SECP256K1_WARN_UNUSED_RESULT
Create a secp256k1 context object (in dynamically allocated memory).
#define SECP256K1_CONTEXT_NONE
Context flags to pass to secp256k1_context_create, secp256k1_context_preallocated_size,...
#define SECP256K1_EC_COMPRESSED
Flag to pass to secp256k1_ec_pubkey_serialize.
SECP256K1_API SECP256K1_WARN_UNUSED_RESULT int secp256k1_ellswift_create(const secp256k1_context *ctx, unsigned char *ell64, const unsigned char *seckey32, const unsigned char *auxrnd32) SECP256K1_ARG_NONNULL(1) SECP256K1_ARG_NONNULL(2) SECP256K1_ARG_NONNULL(3)
Compute an ElligatorSwift public key for a secret key.
SECP256K1_API int secp256k1_ellswift_decode(const secp256k1_context *ctx, secp256k1_pubkey *pubkey, const unsigned char *ell64) SECP256K1_ARG_NONNULL(1) SECP256K1_ARG_NONNULL(2) SECP256K1_ARG_NONNULL(3)
Decode a 64-bytes ElligatorSwift encoded public key.
SECP256K1_API SECP256K1_WARN_UNUSED_RESULT int secp256k1_ellswift_xdh(const secp256k1_context *ctx, unsigned char *output, const unsigned char *ell_a64, const unsigned char *ell_b64, const unsigned char *seckey32, int party, secp256k1_ellswift_xdh_hash_function hashfp, void *data) SECP256K1_ARG_NONNULL(1) SECP256K1_ARG_NONNULL(2) SECP256K1_ARG_NONNULL(3) SECP256K1_ARG_NONNULL(4) SECP256K1_ARG_NONNULL(5) SECP256K1_ARG_NONNULL(7)
Given a private key, and ElligatorSwift public keys sent in both directions, compute a shared secret ...
SECP256K1_API const secp256k1_ellswift_xdh_hash_function secp256k1_ellswift_xdh_hash_function_bip324
An implementation of an secp256k1_ellswift_xdh_hash_function compatible with BIP324.
SECP256K1_API int secp256k1_ellswift_encode(const secp256k1_context *ctx, unsigned char *ell64, const secp256k1_pubkey *pubkey, const unsigned char *rnd32) SECP256K1_ARG_NONNULL(1) SECP256K1_ARG_NONNULL(2) SECP256K1_ARG_NONNULL(3) SECP256K1_ARG_NONNULL(4)
Construct a 64-byte ElligatorSwift encoding of a given pubkey.
Opaque data structure that holds a parsed and valid public key.