MCPcopy Create free account
hub / github.com/ElementsProject/lightning / cryptomsg_decrypt_header

Function cryptomsg_decrypt_header

common/cryptomsg.c:121–149  ·  view source on GitHub ↗

Source from the content-addressed store, hash-verified

119}
120
121bool cryptomsg_decrypt_header(struct crypto_state *cs, u8 hdr[18], u16 *lenp)
122{
123 unsigned char npub[crypto_aead_chacha20poly1305_ietf_NPUBBYTES];
124 unsigned long long mlen;
125 be16 len;
126
127 le64_nonce(npub, cs->rn++);
128
129 /* BOLT #8:
130 *
131 * 2. Let the encrypted length prefix be known as `lc`.
132 * 3. Decrypt `lc` (using `ChaCha20-Poly1305`, `rn`, and `rk`), to
133 * obtain the size of the encrypted packet `l`.
134 * * A zero-length byte slice is to be passed as the AD
135 * (associated data).
136 * * The nonce `rn` MUST be incremented after this step.
137 */
138 if (crypto_aead_chacha20poly1305_ietf_decrypt((unsigned char *)&len,
139 &mlen, NULL,
140 memcheck(hdr, 18), 18,
141 NULL, 0,
142 npub, cs->rk.data) != 0) {
143 /* FIXME: Report error! */
144 return false;
145 }
146 assert(mlen == sizeof(len));
147 *lenp = be16_to_cpu(len);
148 return true;
149}
150
151u8 *cryptomsg_encrypt_msg(const tal_t *ctx,
152 struct crypto_state *cs,

Callers 4

read_body_from_peerFunction · 0.85
peer_init_hdr_receivedFunction · 0.85
mainFunction · 0.85
sync_crypto_readFunction · 0.85

Calls 2

be16_to_cpuFunction · 0.85
le64_nonceFunction · 0.70

Tested by 1

mainFunction · 0.68