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

Function cryptomsg_decrypt_header

common/cryptomsg.c:123–152  ·  view source on GitHub ↗

Source from the content-addressed store, hash-verified

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

Callers 7

read_body_from_peerFunction · 0.85
peer_init_hdr_receivedFunction · 0.85
test_decrypt_headerFunction · 0.85
encode_msgFunction · 0.85
mainFunction · 0.85
sync_crypto_readFunction · 0.85

Calls 2

be16_to_cpuFunction · 0.85
le64_nonceFunction · 0.70

Tested by 3

test_decrypt_headerFunction · 0.68
mainFunction · 0.68