-
Notifications
You must be signed in to change notification settings - Fork 9
/
crypto.h
55 lines (41 loc) · 1.14 KB
/
crypto.h
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
#ifndef LNSOCKET_CRYPTO_H
#define LNSOCKET_CRYPTO_H
#include <secp256k1.h>
#include "typedefs.h"
#define PUBKEY_CMPR_LEN 33
struct secret {
u8 data[32];
};
struct node_id {
u8 k[PUBKEY_CMPR_LEN];
};
struct pubkey {
secp256k1_pubkey pubkey;
};
struct privkey {
struct secret secret;
};
struct keypair {
struct pubkey pub;
struct privkey priv;
};
struct crypto_state {
/* Received and sent nonces. */
u64 rn, sn;
/* Sending and receiving keys. */
struct secret sk, rk;
/* Chaining key for re-keying */
struct secret s_ck, r_ck;
};
void le64_nonce(unsigned char *npub, u64 nonce);
void hkdf_two_keys(struct secret *out1, struct secret *out2,
const struct secret *in1,
const struct secret *in2);
int cryptomsg_decrypt_body(struct crypto_state *cs, const u8 *in, size_t inlen, u8 *out, size_t outcap);
int cryptomsg_decrypt_header(struct crypto_state *cs, u8 hdr[18], u16 *lenp);
unsigned char *cryptomsg_encrypt_msg(struct crypto_state *cs, const u8 *msg, unsigned long long mlen, u8 *out, size_t *outlen, size_t outcap);
static inline int cryptomsg_decrypt_size(size_t inlen)
{
return inlen - 16;
}
#endif /* LNSOCKET_CRYPTO_H */