20 unsigned char seckey1[32];
21 unsigned char seckey2[32];
22 unsigned char compressed_pubkey1[33];
23 unsigned char compressed_pubkey2[33];
24 unsigned char shared_secret1[32];
25 unsigned char shared_secret2[32];
26 unsigned char randomize[32];
35 printf(
"Failed to generate randomness\n");
51 printf(
"Failed to generate randomness\n");
66 len =
sizeof(compressed_pubkey1);
70 assert(len ==
sizeof(compressed_pubkey1));
73 len =
sizeof(compressed_pubkey2);
77 assert(len ==
sizeof(compressed_pubkey2));
83 return_val =
secp256k1_ecdh(ctx, shared_secret1, &pubkey2, seckey1, NULL, NULL);
88 return_val =
secp256k1_ecdh(ctx, shared_secret2, &pubkey1, seckey2, NULL, NULL);
92 return_val = memcmp(shared_secret1, shared_secret2,
sizeof(shared_secret1));
97 printf(
"Compressed Pubkey1: ");
98 print_hex(compressed_pubkey1,
sizeof(compressed_pubkey1));
101 printf(
"Compressed Pubkey2: ");
102 print_hex(compressed_pubkey2,
sizeof(compressed_pubkey2));
103 printf(
"\nShared Secret: ");
104 print_hex(shared_secret1,
sizeof(shared_secret1));
static int fill_random(unsigned char *data, size_t size)
static void print_hex(unsigned char *data, size_t size)
static SECP256K1_INLINE void secure_erase(void *ptr, size_t len)
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 SECP256K1_WARN_UNUSED_RESULT int secp256k1_context_randomize(secp256k1_context *ctx, const unsigned char *seed32) SECP256K1_ARG_NONNULL(1)
Randomizes the context to provide enhanced protection against side-channel leakage.
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_seckey_verify(const secp256k1_context *ctx, const unsigned char *seckey) SECP256K1_ARG_NONNULL(1) SECP256K1_ARG_NONNULL(2)
Verify an ECDSA secret key.
#define SECP256K1_CONTEXT_NONE
Context flags to pass to secp256k1_context_create, secp256k1_context_preallocated_size,...
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.
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_EC_COMPRESSED
Flag to pass to secp256k1_ec_pubkey_serialize.
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.