Botan 3.10.0
Crypto and TLS for C&
ascon_hash256.cpp
Go to the documentation of this file.
1/*
2* Ascon-Hash256 (NIST SP.800-232)
3* (C) 2025 Jack Lloyd
4* 2025 René Meusel
5*
6* Botan is released under the Simplified BSD License (see license.txt)
7*/
8
9#include <botan/internal/ascon_hash256.h>
10
11namespace Botan {
12
13namespace {
14
15// NIST SP.800-232 Appendix A (Table 12)
16constexpr Ascon_p initial_state_of_ascon_hash_permutation({
17 .init_and_final_rounds = 12,
18 .processing_rounds = 12,
19 .bit_rate = 64,
20 .initial_state =
21 {
22 0x9b1e5494e934d681,
23 0x4bc3a01e333751d2,
24 0xae65396c6b34b81a,
25 0x3c7fd4a4d56a4db3,
26 0x1a5c464906c5976d,
27 },
28});
29
30} // namespace
31
32Ascon_Hash256::Ascon_Hash256() : m_ascon_p(initial_state_of_ascon_hash_permutation) {}
33
35 m_ascon_p = initial_state_of_ascon_hash_permutation;
36}
37
38std::unique_ptr<HashFunction> Ascon_Hash256::new_object() const {
39 return std::make_unique<Ascon_Hash256>();
40}
41
42std::unique_ptr<HashFunction> Ascon_Hash256::copy_state() const {
43 return std::make_unique<Ascon_Hash256>(*this);
44}
45
46void Ascon_Hash256::add_data(std::span<const uint8_t> input) {
47 m_ascon_p.absorb(input);
48}
49
50void Ascon_Hash256::final_result(std::span<uint8_t> out) {
51 m_ascon_p.finish();
52 m_ascon_p.squeeze(out);
53 clear();
54}
55
56} // namespace Botan
void clear() override
std::unique_ptr< HashFunction > copy_state() const override
std::unique_ptr< HashFunction > new_object() const override
void squeeze(std::span< uint8_t > output)
void absorb(std::span< const uint8_t > input, std::optional< uint8_t > permutation_rounds=std::nullopt)