MCPcopy Create free account
hub / github.com/bitcoin/bitcoin / NextPacket

Method NextPacket

src/crypto/chacha20poly1305.cpp:106–122  ·  view source on GitHub ↗

Source from the content-addressed store, hash-verified

104}
105
106void FSChaCha20Poly1305::NextPacket() noexcept
107{
108 if (++m_packet_counter == m_rekey_interval) {
109 // Generate a full block of keystream, to avoid needing the ChaCha20 buffer, even though
110 // we only need KEYLEN (32) bytes.
111 std::byte one_block[ChaCha20Aligned::BLOCKLEN];
112 m_aead.Keystream({0xFFFFFFFF, m_rekey_counter}, one_block);
113 // Switch keys.
114 m_aead.SetKey(std::span{one_block}.first(KEYLEN));
115 // Wipe the generated keystream (a copy remains inside m_aead, which will be cleaned up
116 // once it cycles again, or is destroyed).
117 memory_cleanse(one_block, sizeof(one_block));
118 // Update counters.
119 m_packet_counter = 0;
120 ++m_rekey_counter;
121 }
122}
123
124void FSChaCha20Poly1305::Encrypt(std::span<const std::byte> plain1, std::span<const std::byte> plain2, std::span<const std::byte> aad, std::span<std::byte> cipher) noexcept
125{

Callers

nothing calls this directly

Calls 3

memory_cleanseFunction · 0.85
KeystreamMethod · 0.45
SetKeyMethod · 0.45

Tested by

no test coverage detected