2020-12-09 04:57:50 +01:00
|
|
|
#ifndef LIGHTNING_COMMON_BLINDEDPATH_H
|
|
|
|
#define LIGHTNING_COMMON_BLINDEDPATH_H
|
|
|
|
#include "config.h"
|
2021-09-21 23:17:16 +02:00
|
|
|
#include <ccan/compiler/compiler.h>
|
|
|
|
#include <ccan/short_types/short_types.h>
|
2020-12-09 04:57:50 +01:00
|
|
|
#include <ccan/tal/tal.h>
|
|
|
|
|
|
|
|
struct route_info;
|
|
|
|
struct pubkey;
|
2021-09-21 23:17:16 +02:00
|
|
|
struct privkey;
|
|
|
|
struct secret;
|
2022-10-17 02:43:08 +02:00
|
|
|
struct short_channel_id;
|
2022-11-09 02:30:10 +01:00
|
|
|
struct tlv_encrypted_data_tlv;
|
2022-10-17 02:43:08 +02:00
|
|
|
struct tlv_encrypted_data_tlv_payment_constraints;
|
|
|
|
struct tlv_encrypted_data_tlv_payment_relay;
|
2020-12-09 04:57:50 +01:00
|
|
|
|
2021-09-21 23:17:16 +02:00
|
|
|
/**
|
2022-11-09 02:30:10 +01:00
|
|
|
* encrypt_tlv_encrypted_data - Encrypt a tlv_encrypted_data_tlv.
|
2021-09-21 23:17:16 +02:00
|
|
|
* @ctx: tal context
|
2024-10-14 18:03:49 +02:00
|
|
|
* @path_privkey: e(i), the path key
|
2021-09-21 23:17:16 +02:00
|
|
|
* @node: the pubkey of the node to encrypt for
|
2022-11-09 02:30:10 +01:00
|
|
|
* @tlv: the message to encrypt.
|
2024-10-14 18:03:49 +02:00
|
|
|
* @next_path_privkey: (out) e(i+1), the next blinding secret (optional)
|
2021-09-21 23:17:16 +02:00
|
|
|
* @node_alias: (out) the blinded pubkey of the node to tell the recipient.
|
|
|
|
*
|
2022-11-09 02:30:10 +01:00
|
|
|
* You create a blinding secret using randombytes_buf(), then call this
|
|
|
|
* iteratively for each node in the path.
|
2021-09-21 23:17:16 +02:00
|
|
|
*/
|
2022-11-09 02:30:10 +01:00
|
|
|
u8 *encrypt_tlv_encrypted_data(const tal_t *ctx,
|
2024-10-14 18:03:49 +02:00
|
|
|
const struct privkey *path_privkey,
|
2022-11-09 02:30:10 +01:00
|
|
|
const struct pubkey *node,
|
|
|
|
const struct tlv_encrypted_data_tlv *tlv,
|
2024-10-14 18:03:49 +02:00
|
|
|
struct privkey *next_path_privkey,
|
2022-11-09 02:30:10 +01:00
|
|
|
struct pubkey *node_alias)
|
|
|
|
NON_NULL_ARGS(2, 3, 4, 6);
|
2021-09-21 23:17:16 +02:00
|
|
|
|
2021-09-21 23:17:24 +02:00
|
|
|
/**
|
|
|
|
* unblind_onion - tweak onion epheremeral key so we can decode it with ours.
|
2024-10-14 18:03:49 +02:00
|
|
|
* @path_key: E(i), the blinding pubkey the previous peer gave us.
|
2021-09-21 23:17:24 +02:00
|
|
|
* @ecdh: the ecdh routine (usually ecdh from common/ecdh_hsmd).
|
|
|
|
* @onion_key: (in, out) the onionpacket->ephemeralkey to tweak.
|
|
|
|
* @ss: (out) the shared secret we gained from blinding pubkey.
|
|
|
|
*
|
|
|
|
* The shared secret is needed to decrypt the enctlv we expect to find, too.
|
|
|
|
*/
|
2024-10-14 18:03:49 +02:00
|
|
|
bool unblind_onion(const struct pubkey *path_key,
|
2021-09-21 23:17:24 +02:00
|
|
|
void (*ecdh)(const struct pubkey *point, struct secret *ss),
|
|
|
|
struct pubkey *onion_key,
|
|
|
|
struct secret *ss)
|
|
|
|
NO_NULL_ARGS;
|
|
|
|
|
|
|
|
/**
|
2022-10-17 02:43:07 +02:00
|
|
|
* blindedpath_get_alias - tweak our id to see alias they used.
|
|
|
|
* @ss: the shared secret from unblind_onion
|
|
|
|
* @my_id: my node_id
|
|
|
|
* @alias: (out) the alias.
|
2021-09-21 23:17:24 +02:00
|
|
|
*
|
2022-10-17 02:43:07 +02:00
|
|
|
* Returns false on ECDH fail.
|
2021-09-21 23:17:24 +02:00
|
|
|
*/
|
2022-10-17 02:43:07 +02:00
|
|
|
bool blindedpath_get_alias(const struct secret *ss,
|
|
|
|
const struct pubkey *my_id,
|
|
|
|
struct pubkey *alias);
|
2021-09-21 23:17:24 +02:00
|
|
|
|
|
|
|
/**
|
2022-10-17 02:43:07 +02:00
|
|
|
* decrypt_encrypted_data - Decrypt an encmsg to form an tlv_encrypted_data_tlv.
|
|
|
|
* @ctx: the context to allocate off.
|
2021-09-21 23:17:24 +02:00
|
|
|
* @ss: the blinding secret from unblind_onion().
|
|
|
|
* @enctlv: the enctlv from the onion (tal, may be NULL).
|
|
|
|
*
|
2022-10-17 02:43:07 +02:00
|
|
|
* Returns NULL if decryption failed or encmsg was malformed.
|
|
|
|
*/
|
|
|
|
struct tlv_encrypted_data_tlv *decrypt_encrypted_data(const tal_t *ctx,
|
|
|
|
const struct secret *ss,
|
|
|
|
const u8 *enctlv)
|
|
|
|
NON_NULL_ARGS(2, 3);
|
|
|
|
|
2024-07-17 11:00:11 +02:00
|
|
|
/* Low-level accessor */
|
|
|
|
u8 *decrypt_encmsg_raw(const tal_t *ctx,
|
|
|
|
const struct secret *ss,
|
|
|
|
const u8 *enctlv);
|
|
|
|
|
2022-10-17 02:43:07 +02:00
|
|
|
/**
|
2024-10-14 18:03:49 +02:00
|
|
|
* blindedpath_next_path_key - Calculate or extract next blinding pubkey
|
2021-09-21 23:17:24 +02:00
|
|
|
*/
|
2024-10-14 18:03:49 +02:00
|
|
|
void blindedpath_next_path_key(const struct tlv_encrypted_data_tlv *enc,
|
|
|
|
const struct pubkey *path_key,
|
2022-10-17 02:43:07 +02:00
|
|
|
const struct secret *ss,
|
2024-10-14 18:03:49 +02:00
|
|
|
struct pubkey *next_path_key);
|
2021-11-30 04:06:04 +01:00
|
|
|
|
2020-12-09 04:57:50 +01:00
|
|
|
#endif /* LIGHTNING_COMMON_BLINDEDPATH_H */
|