Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion configure.ac
Original file line number Diff line number Diff line change
Expand Up @@ -134,7 +134,7 @@ AM_CONDITIONAL([WITH_WALLET], [test "x$with_wallet" = "xyes"])
AM_CONDITIONAL([WITH_NET], [test "x$with_net" = "xyes"])
AM_CONDITIONAL([WITH_LOGDB], [test "x$with_tools" = "xyes" -o "x$with_wallet" = "xyes"])

ac_configure_args="${ac_configure_args} --enable-module-recovery"
ac_configure_args="${ac_configure_args} --enable-module-recovery --enable-module-ecdh"
AC_CONFIG_SUBDIRS([src/secp256k1])

dnl make sure nothing new is exported so that we don't break the cache
Expand Down
3 changes: 3 additions & 0 deletions include/btc/ecc.h
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@
The MIT License (MIT)

Copyright (c) 2015 Jonas Schnelli
Copyright (c) 2024 Mark Naughton <mark@marknaughton.com>

Permission is hereby granted, free of charge, to any person obtaining
a copy of this software and associated documentation files (the "Software"),
Expand Down Expand Up @@ -73,6 +74,8 @@ LIBBTC_API btc_bool btc_ecc_der_to_compact(unsigned char* sigder_in, size_t sigd
//!verify DER signature with public key
LIBBTC_API btc_bool btc_ecc_verify_sig(const uint8_t* public_key, btc_bool compressed, const uint256 hash, unsigned char* sigder, size_t siglen);

LIBBTC_API btc_bool btc_ecc_ecdh(const uint8_t* privkey, const uint8_t* public_key, btc_bool compressed, unsigned char* output);

LIBBTC_END_DECL

#endif // __LIBBTC_ECC_H__
18 changes: 18 additions & 0 deletions src/ecc_libsecp256k1.c
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
#include "secp256k1/include/secp256k1.h"
#include "secp256k1/include/secp256k1_ecdh.h"
#include "secp256k1/include/secp256k1_recovery.h"

#include <assert.h>
Expand Down Expand Up @@ -207,3 +208,20 @@ btc_bool btc_ecc_der_to_compact(unsigned char* sigder_in, size_t sigder_len, uns

return secp256k1_ecdsa_signature_serialize_compact(secp256k1_ctx, sigcomp_out, &sig);
}


btc_bool btc_ecc_ecdh(const uint8_t* privkey, const uint8_t* public_key, btc_bool compressed, unsigned char* output)
{
secp256k1_pubkey pubkey;

assert(secp256k1_ctx);
if (!secp256k1_ec_pubkey_parse(secp256k1_ctx, &pubkey, public_key, compressed ? 33 : 65)) {
return false;
}

if (!secp256k1_ecdh(secp256k1_ctx, output, &pubkey, privkey, NULL, NULL)) {
return false;
}

return true;
}