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

Function encrypt_ad

connectd/handshake.c:280–306  ·  view source on GitHub ↗

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

Source from the content-addressed store, hash-verified

278 * variant) with the passed arguments, with nonce `n`
279 */
280static void encrypt_ad(const struct secret *k, u64 nonce,
281 const void *additional_data, size_t additional_data_len,
282 const void *plaintext, size_t plaintext_len,
283 void *output, size_t outputlen)
284{
285 unsigned char npub[crypto_aead_chacha20poly1305_ietf_NPUBBYTES];
286 unsigned long long clen;
287 int ret;
288
289 assert(outputlen == plaintext_len + crypto_aead_chacha20poly1305_ietf_ABYTES);
290 le64_nonce(npub, nonce);
291 BUILD_ASSERT(sizeof(*k) == crypto_aead_chacha20poly1305_ietf_KEYBYTES);
292 SUPERVERBOSE("# encryptWithAD(0x%s, 0x%s, 0x%s, %s%s)",
293 tal_hexstr(tmpctx, k, sizeof(*k)),
294 tal_hexstr(tmpctx, npub, sizeof(npub)),
295 tal_hexstr(tmpctx, additional_data, additional_data_len),
296 plaintext_len ? "0x" : "<empty>",
297 tal_hexstr(tmpctx, plaintext, plaintext_len));
298
299 ret = crypto_aead_chacha20poly1305_ietf_encrypt(output, &clen,
300 memcheck(plaintext, plaintext_len),
301 plaintext_len,
302 additional_data, additional_data_len,
303 NULL, npub, k->data);
304 assert(ret == 0);
305 assert(clen == plaintext_len + crypto_aead_chacha20poly1305_ietf_ABYTES);
306}
307
308/* BOLT #8:
309 * * `decryptWithAD(k, n, ad, ciphertext)`: outputs `decrypt(k, n, ad,

Callers 3

act_three_initiatorFunction · 0.85
act_one_initiatorFunction · 0.85
act_two_responderFunction · 0.85

Calls 2

tal_hexstrFunction · 0.85
le64_nonceFunction · 0.70

Tested by

no test coverage detected