7#ifndef SECP256K1_MODULE_ECDH_TESTS_H
8#define SECP256K1_MODULE_ECDH_TESTS_H
15 memcpy(output, x, 32);
31 memcpy(output + 1, x, 32);
32 memcpy(output + 33, y, 32);
38 unsigned char res[32];
39 unsigned char s_one[32] = { 0 };
53 unsigned char s_one[32] = { 0 };
59 for (i = 0; i < 2 *
COUNT; ++i) {
61 unsigned char s_b32[32];
62 unsigned char output_ecdh[65];
63 unsigned char output_ser[32];
64 unsigned char point_ser[65];
65 size_t point_ser_len =
sizeof(point_ser);
68 testutil_random_scalar_order(&s);
69 secp256k1_scalar_get_b32(s_b32, &s);
94 unsigned char s_zero[32] = { 0 };
95 unsigned char s_overflow[32] = { 0 };
96 unsigned char s_rand[32] = { 0 };
97 unsigned char output[32];
102 testutil_random_scalar_order(&rand);
103 secp256k1_scalar_get_b32(s_rand, &rand);
107 memcpy(s_overflow, secp256k1_group_order_bytes, 32);
123 unsigned char s_inv[32];
124 unsigned char out[32];
125 unsigned char out_inv[32];
126 unsigned char out_base[32];
129 unsigned char s_one[32] = { 0 };
134 for (i = 0; i < 2 *
COUNT; i++) {
135 testutil_random_scalar_order(&rand);
136 secp256k1_scalar_get_b32(s, &rand);
137 secp256k1_scalar_inverse(&rand, &rand);
138 secp256k1_scalar_get_b32(s_inv, &rand);
156 const unsigned char *pk;
157 const unsigned char *sk;
158 const unsigned char *expected_shared_secret;
159 unsigned char output_ecdh[65] = { 0 };
163 memset(&point, 0,
sizeof(point));
164 pk = &wycheproof_ecdh_public_keys[testvectors[
t].pk_offset];
167 expected_result = testvectors[
t].expected_result;
168 CHECK(parsed_ok == expected_result);
173 sk = &wycheproof_ecdh_private_keys[testvectors[
t].sk_offset];
174 CHECK(testvectors[
t].sk_len == 32);
177 expected_shared_secret = &wycheproof_ecdh_shared_secrets[testvectors[
t].shared_offset];
static void test_ecdh_api(void)
static const struct tf_test_entry tests_ecdh[]
static void test_bad_scalar(void)
#define SECP256K1_ECDH_WYCHEPROOF_NUMBER_TESTVECTORS
static int ecdh_hash_function_test_fail(unsigned char *output, const unsigned char *x, const unsigned char *y, void *data)
static void test_result_basepoint(void)
Test that ECDH(sG, 1/s) == ECDH((1/s)G, s) == ECDH(G, 1) for a few random s.
static void test_ecdh_generator_basepoint(void)
static int ecdh_hash_function_custom(unsigned char *output, const unsigned char *x, const unsigned char *y, void *data)
static void test_ecdh_wycheproof(void)
static int ecdh_hash_function_test_xpassthru(unsigned char *output, const unsigned char *x, const unsigned char *y, void *data)
#define CHECK(cond)
Unconditional failure on condition failure.
static void secp256k1_sha256_initialize(secp256k1_sha256 *hash)
static void secp256k1_sha256_finalize(secp256k1_sha256 *hash, unsigned char *out32)
static void secp256k1_sha256_write(secp256k1_sha256 *hash, const unsigned char *data, size_t size)
static SECP256K1_INLINE int secp256k1_memcmp_var(const void *s1, const void *s2, size_t n)
Semantics like memcmp.
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_WARN_UNUSED_RESULT int secp256k1_ec_pubkey_parse(const secp256k1_context *ctx, secp256k1_pubkey *pubkey, const unsigned char *input, size_t inputlen) SECP256K1_ARG_NONNULL(1) SECP256K1_ARG_NONNULL(2) SECP256K1_ARG_NONNULL(3)
Parse a variable-length public key into the pubkey object.
SECP256K1_API SECP256K1_WARN_UNUSED_RESULT int secp256k1_ec_pubkey_create(const secp256k1_context *ctx, secp256k1_pubkey *pubkey, const unsigned char *seckey) SECP256K1_ARG_NONNULL(1) SECP256K1_ARG_NONNULL(2) SECP256K1_ARG_NONNULL(3)
Compute the public key for a secret key.
#define SECP256K1_EC_COMPRESSED
Flag to pass to secp256k1_ec_pubkey_serialize.
#define SECP256K1_EC_UNCOMPRESSED
SECP256K1_API SECP256K1_WARN_UNUSED_RESULT int secp256k1_ecdh(const secp256k1_context *ctx, unsigned char *output, const secp256k1_pubkey *pubkey, const unsigned char *seckey, secp256k1_ecdh_hash_function hashfp, void *data) SECP256K1_ARG_NONNULL(1) SECP256K1_ARG_NONNULL(2) SECP256K1_ARG_NONNULL(3) SECP256K1_ARG_NONNULL(4)
Compute an EC Diffie-Hellman secret in constant time.
Opaque data structure that holds a parsed and valid public key.
A scalar modulo the group order of the secp256k1 curve.
#define CHECK_ILLEGAL(ctx, expr)