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

Function decrypt

connectd/handshake.c:314–340  ·  view source on GitHub ↗

BOLT #8: * * `decryptWithAD(k, n, ad, ciphertext)`: outputs `decrypt(k, n, ad, * ciphertext)` * * Where `decrypt` is an evaluation of `ChaCha20-Poly1305` (IETF * variant) with the passed arguments, with nonce `n` */

Source from the content-addressed store, hash-verified

312 * variant) with the passed arguments, with nonce `n`
313 */
314static bool decrypt(const struct secret *k, u64 nonce,
315 const void *additional_data, size_t additional_data_len,
316 const void *ciphertext, size_t ciphertext_len,
317 void *output, size_t outputlen)
318{
319 unsigned char npub[crypto_aead_chacha20poly1305_ietf_NPUBBYTES];
320 unsigned long long mlen;
321
322 assert(outputlen == ciphertext_len - crypto_aead_chacha20poly1305_ietf_ABYTES);
323
324 le64_nonce(npub, nonce);
325 BUILD_ASSERT(sizeof(*k) == crypto_aead_chacha20poly1305_ietf_KEYBYTES);
326 SUPERVERBOSE("# decryptWithAD(0x%s, 0x%s, 0x%s, 0x%s)",
327 tal_hexstr(tmpctx, k, sizeof(*k)),
328 tal_hexstr(tmpctx, npub, sizeof(npub)),
329 tal_hexstr(tmpctx, additional_data, additional_data_len),
330 tal_hexstr(tmpctx, ciphertext, ciphertext_len));
331 if (crypto_aead_chacha20poly1305_ietf_decrypt(output, &mlen, NULL,
332 memcheck(ciphertext, ciphertext_len),
333 ciphertext_len,
334 additional_data, additional_data_len,
335 npub, k->data) != 0)
336 return false;
337
338 assert(mlen == ciphertext_len - crypto_aead_chacha20poly1305_ietf_ABYTES);
339 return true;
340}
341
342static struct io_plan *handshake_failed_(struct io_conn *conn,
343 struct handshake *h,

Callers 3

act_two_initiator2Function · 0.85
act_three_responder2Function · 0.85
act_one_responder2Function · 0.85

Calls 2

tal_hexstrFunction · 0.85
le64_nonceFunction · 0.70

Tested by

no test coverage detected