7#ifndef SECP256K1_MODULE_ECDH_TESTS_H
8#define SECP256K1_MODULE_ECDH_TESTS_H
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];
94 unsigned char s_zero[32] = { 0 };
96 unsigned char s_rand[32] = { 0 };
97 unsigned char output[32];
123 unsigned char s_inv[32];
124 unsigned char out[32];
129 unsigned char s_one[32] = { 0 };
134 for (i = 0; i < 2 *
COUNT; i++) {
156 const unsigned char *pk;
157 const unsigned char *sk;
163 memset(&point, 0,
sizeof(point));
static void test_ecdh_api(void)
static const struct tf_test_entry tests_ecdh[]
static void test_bad_scalar(void)
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)
static const unsigned char wycheproof_ecdh_public_keys[]
#define SECP256K1_ECDH_WYCHEPROOF_NUMBER_TESTVECTORS
static const wycheproof_ecdh_testvector testvectors[SECP256K1_ECDH_WYCHEPROOF_NUMBER_TESTVECTORS]
static const unsigned char wycheproof_ecdh_private_keys[]
static const unsigned char wycheproof_ecdh_shared_secrets[]
#define CHECK(cond)
Unconditional failure on condition failure.
static void secp256k1_scalar_get_b32(unsigned char *bin, const secp256k1_scalar *a)
Convert a scalar to a byte array.
static void secp256k1_scalar_inverse(secp256k1_scalar *r, const secp256k1_scalar *a)
Compute the inverse of a scalar (modulo the group order).
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)
static secp256k1_context * CTX
static const unsigned char secp256k1_group_order_bytes[32]
static void testutil_random_scalar_order(secp256k1_scalar *num)
constexpr auto Ticks(Dur2 d)
Helper to count the seconds of a duration/time_point.