|
17 | 17 |
|
18 | 18 | #include "examples_util.h" |
19 | 19 |
|
| 20 | +/* Identity hash function for ECDH, returns x coordinate directly */ |
| 21 | +int ecdh_hash(unsigned char *output, const unsigned char *x32, const unsigned char *y32, void *data) { |
| 22 | + (void)y32; |
| 23 | + (void)data; |
| 24 | + memcpy(output, x32, 32); |
| 25 | + return 1; |
| 26 | +} |
| 27 | + |
20 | 28 | int main(void) { |
21 | 29 | unsigned char seckey1[32]; |
22 | 30 | unsigned char seckey2[32]; |
@@ -79,12 +87,12 @@ int main(void) { |
79 | 87 |
|
80 | 88 | /* Perform ECDH with seckey1 and pubkey2. Should never fail with a verified |
81 | 89 | * seckey and valid pubkey */ |
82 | | - return_val = secp256k1_ecdh(ctx, shared_secret1, &pubkey2, seckey1, NULL, NULL); |
| 90 | + return_val = secp256k1_ecdh(ctx, shared_secret1, &pubkey2, seckey1, ecdh_hash, NULL); |
83 | 91 | assert(return_val); |
84 | 92 |
|
85 | 93 | /* Perform ECDH with seckey2 and pubkey1. Should never fail with a verified |
86 | 94 | * seckey and valid pubkey */ |
87 | | - return_val = secp256k1_ecdh(ctx, shared_secret2, &pubkey1, seckey2, NULL, NULL); |
| 95 | + return_val = secp256k1_ecdh(ctx, shared_secret2, &pubkey1, seckey2, ecdh_hash, NULL); |
88 | 96 | assert(return_val); |
89 | 97 |
|
90 | 98 | /* Both parties should end up with the same shared secret */ |
|
0 commit comments