| 104 | } |
| 105 | |
| 106 | void 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 | |
| 124 | void 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 | { |
nothing calls this directly
no test coverage detected