Browse Source
common/onion is going to need to use this for the case where it finds a blinding seed inside the TLV. But how it does ecdh is daemon-specific. We already had this problem for devtools/gossipwith, which supplied a special hsm_do_ecdh(). This just makes it more general. So we create a generic ecdh() interface, with a specific implementation which subdaemons and lightningd can use. Signed-off-by: Rusty Russell <rusty@rustcorp.com.au>travis-debug
Rusty Russell
5 years ago
21 changed files with 126 additions and 77 deletions
@ -0,0 +1,13 @@ |
|||||
|
#ifndef LIGHTNING_COMMON_ECDH_H |
||||
|
#define LIGHTNING_COMMON_ECDH_H |
||||
|
#include "config.h" |
||||
|
|
||||
|
struct pubkey; |
||||
|
struct secret; |
||||
|
|
||||
|
/* This function is implemented differently in various daemons and tools:
|
||||
|
* subdaemons need to talk to the HSM via hsm_fd, lightningd needs to use |
||||
|
* its HSM interface, and tools can implement this directly. */ |
||||
|
void ecdh(const struct pubkey *point, struct secret *ss); |
||||
|
|
||||
|
#endif /* LIGHTNING_COMMON_ECDH_H */ |
@ -0,0 +1,29 @@ |
|||||
|
#include <common/ecdh_hsmd.h> |
||||
|
#include <hsmd/gen_hsm_wire.h> |
||||
|
#include <wire/wire_sync.h> |
||||
|
|
||||
|
static int stashed_hsm_fd = -1; |
||||
|
static void (*stashed_failed)(enum status_failreason, const char *fmt, ...); |
||||
|
|
||||
|
void ecdh(const struct pubkey *point, struct secret *ss) |
||||
|
{ |
||||
|
const u8 *msg = towire_hsm_ecdh_req(NULL, point); |
||||
|
|
||||
|
if (!wire_sync_write(stashed_hsm_fd, take(msg))) |
||||
|
stashed_failed(STATUS_FAIL_HSM_IO, "Write ECDH to hsmd failed"); |
||||
|
|
||||
|
msg = wire_sync_read(tmpctx, stashed_hsm_fd); |
||||
|
if (!msg) |
||||
|
stashed_failed(STATUS_FAIL_HSM_IO, "No hsmd ECDH response"); |
||||
|
|
||||
|
if (!fromwire_hsm_ecdh_resp(msg, ss)) |
||||
|
stashed_failed(STATUS_FAIL_HSM_IO, "Invalid hsmd ECDH response"); |
||||
|
} |
||||
|
|
||||
|
void ecdh_hsmd_setup(int hsm_fd, |
||||
|
void (*failed)(enum status_failreason, |
||||
|
const char *fmt, ...)) |
||||
|
{ |
||||
|
stashed_hsm_fd = hsm_fd; |
||||
|
stashed_failed = failed; |
||||
|
} |
@ -0,0 +1,13 @@ |
|||||
|
#ifndef LIGHTNING_COMMON_ECDH_HSMD_H |
||||
|
#define LIGHTNING_COMMON_ECDH_HSMD_H |
||||
|
#include "config.h" |
||||
|
#include <common/ecdh.h> |
||||
|
#include <common/status_levels.h> |
||||
|
|
||||
|
/* The via-the-hsmd implementation of ecdh(). */ |
||||
|
|
||||
|
/* You must call this before calling ecdh(). */ |
||||
|
void ecdh_hsmd_setup(int hsm_fd, |
||||
|
void (*failed)(enum status_failreason, |
||||
|
const char *fmt, ...)); |
||||
|
#endif /* LIGHTNING_COMMON_ECDH_HSMD_H */ |
Loading…
Reference in new issue