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

Function decrypt

connectd/handshake.c:306–332  ·  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

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