2020-04-03 05:21:22 +02:00
|
|
|
#include <common/ecdh_hsmd.h>
|
2020-05-15 12:32:43 +02:00
|
|
|
#include <common/utils.h>
|
2020-08-25 03:55:38 +02:00
|
|
|
#include <hsmd/hsmd_wiregen.h>
|
2020-04-03 05:21:22 +02:00
|
|
|
#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)
|
|
|
|
{
|
2020-08-25 03:55:38 +02:00
|
|
|
const u8 *msg = towire_hsmd_ecdh_req(NULL, point);
|
2020-04-03 05:21:22 +02:00
|
|
|
|
|
|
|
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");
|
|
|
|
|
2020-08-25 03:55:38 +02:00
|
|
|
if (!fromwire_hsmd_ecdh_resp(msg, ss))
|
2020-04-03 05:21:22 +02:00
|
|
|
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;
|
|
|
|
}
|