21 unsigned char seckey1[32];
22 unsigned char seckey2[32];
23 unsigned char compressed_pubkey1[33];
24 unsigned char compressed_pubkey2[33];
25 unsigned char shared_secret1[32];
26 unsigned char shared_secret2[32];
27 unsigned char randomize[32];
39 if (!fill_random(randomize,
sizeof(randomize))) {
40 printf(
"Failed to generate randomness\n");
55 if (!fill_random(seckey1,
sizeof(seckey1)) || !fill_random(seckey2,
sizeof(seckey2))) {
56 printf(
"Failed to generate randomness\n");
71 len =
sizeof(compressed_pubkey1);
75 assert(
len ==
sizeof(compressed_pubkey1));
78 len =
sizeof(compressed_pubkey2);
82 assert(
len ==
sizeof(compressed_pubkey2));
88 return_val =
secp256k1_ecdh(ctx, shared_secret1, &pubkey2, seckey1, NULL, NULL);
93 return_val =
secp256k1_ecdh(ctx, shared_secret2, &pubkey1, seckey2, NULL, NULL);
97 return_val = memcmp(shared_secret1, shared_secret2,
sizeof(shared_secret1));
98 assert(return_val == 0);
100 printf(
"Secret Key1: ");
101 print_hex(seckey1,
sizeof(seckey1));
102 printf(
"Compressed Pubkey1: ");
103 print_hex(compressed_pubkey1,
sizeof(compressed_pubkey1));
104 printf(
"\nSecret Key2: ");
105 print_hex(seckey2,
sizeof(seckey2));
106 printf(
"Compressed Pubkey2: ");
107 print_hex(compressed_pubkey2,
sizeof(compressed_pubkey2));
108 printf(
"\nShared Secret: ");
109 print_hex(shared_secret1,
sizeof(shared_secret1));
121 memset(seckey1, 0,
sizeof(seckey1));
122 memset(seckey2, 0,
sizeof(seckey2));
123 memset(shared_secret1, 0,
sizeof(shared_secret1));
124 memset(shared_secret2, 0,
sizeof(shared_secret2));
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)
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)