Botan 3.10.0
Crypto and TLS for C&
ascon_xof128.cpp
Go to the documentation of this file.
1/*
2 * Ascon-XOF128 (NIST SP.800-232 Section 5.2)
3 *
4 * (C) 2025 Jack Lloyd
5 * 2025 René Meusel
6 *
7 * Botan is released under the Simplified BSD License (see license.txt)
8 */
9
10#include <botan/internal/ascon_xof128.h>
11
12#include <botan/assert.h>
13
14namespace Botan {
15
16namespace {
17
18// NIST SP.800-232 Appendix A (Table 12)
19constexpr Ascon_p initial_state_of_ascon_xof_permutation({
20 .init_and_final_rounds = 12,
21 .processing_rounds = 12,
22 .bit_rate = 64,
23 .initial_state =
24 {
25 0xda82ce768d9447eb,
26 0xcc7ce6c75f1ef969,
27 0xe7508fd780085631,
28 0x0ee0ea53416b58cc,
29 0xe0547524db6f0bde,
30 },
31});
32
33} // namespace
34
35Ascon_XOF128::Ascon_XOF128() : m_ascon_p(initial_state_of_ascon_xof_permutation) {}
36
37std::unique_ptr<XOF> Ascon_XOF128::copy_state() const {
38 return std::make_unique<Ascon_XOF128>(*this);
39}
40
41std::unique_ptr<XOF> Ascon_XOF128::new_object() const {
42 return std::make_unique<Ascon_XOF128>();
43}
44
45void Ascon_XOF128::add_data(std::span<const uint8_t> input) {
46 BOTAN_STATE_CHECK(!m_output_generated);
47 m_ascon_p.absorb(input);
48}
49
50void Ascon_XOF128::generate_bytes(std::span<uint8_t> output) {
51 if(!m_output_generated) {
52 m_output_generated = true;
53 m_ascon_p.finish();
54 }
55
56 m_ascon_p.squeeze(output);
57}
58
59void Ascon_XOF128::reset() {
60 m_ascon_p = initial_state_of_ascon_xof_permutation;
61 m_output_generated = false;
62}
63
64} // namespace Botan
#define BOTAN_STATE_CHECK(expr)
Definition assert.h:49
std::unique_ptr< XOF > copy_state() const override
std::unique_ptr< XOF > new_object() const override
void absorb(std::span< const uint8_t > input, std::optional< uint8_t > permutation_rounds=std::nullopt)
T output(size_t bytes)
Definition xof.h:153