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