Botan 3.11.0
Crypto and TLS for C&
ascon_perm.h
Go to the documentation of this file.
1/*
2* Permutation Ascon_p[rounds] as specified in NIST SP.800-232, Section 3
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#ifndef BOTAN_ASCON_PERM_H_
10#define BOTAN_ASCON_PERM_H_
11
12#include <botan/internal/sponge.h>
13#include <optional>
14#include <span>
15#include <string>
16
17namespace Botan {
18
19/**
20 * Ascon_p as specified in NIST SP.800-232, Section 3
21 */
22class Ascon_p final : public Sponge<5, uint64_t> {
23 public:
30
31 public:
32 consteval explicit Ascon_p(Config config) :
33 Sponge({config.bit_rate, config.initial_state}),
34 m_init_final_rounds(config.init_and_final_rounds),
35 m_processing_rounds(config.processing_rounds) {
36 BOTAN_ARG_CHECK(m_init_final_rounds > 0 && m_init_final_rounds <= 16,
37 "Invalid Ascon initialization/finalization rounds");
38
39 BOTAN_ARG_CHECK(m_processing_rounds > 0 && m_processing_rounds <= 16, "Invalid Ascon processing rounds");
40 }
41
42 std::string provider() const { return "base"; }
43
44 void absorb(std::span<const uint8_t> input, std::optional<uint8_t> permutation_rounds = std::nullopt);
45 void squeeze(std::span<uint8_t> output);
46 void percolate_in(std::span<uint8_t> data);
47 void percolate_out(std::span<uint8_t> data);
48
49 void finish() { finish(m_init_final_rounds); }
50
51 void intermediate_finish() { finish(m_processing_rounds); }
52
53 void permute() { permute(m_processing_rounds); }
54
55 void initial_permute() { permute(m_init_final_rounds); }
56
57 template <size_t offset, size_t count>
58 requires(offset + count <= state_bytes())
59 constexpr auto range_of_state() {
60 return std::span{state()}.template subspan<offset, count>();
61 }
62
63 private:
64 void finish(uint8_t rounds);
65 void permute(uint8_t rounds);
66
67 private:
68 uint8_t m_init_final_rounds;
69 uint8_t m_processing_rounds;
70};
71
72} // namespace Botan
73
74#endif
#define BOTAN_ARG_CHECK(expr, msg)
Definition assert.h:33
consteval Ascon_p(Config config)
Definition ascon_perm.h:32
constexpr auto range_of_state()
Definition ascon_perm.h:59
void squeeze(std::span< uint8_t > output)
void absorb(std::span< const uint8_t > input, std::optional< uint8_t > permutation_rounds=std::nullopt)
void percolate_in(std::span< uint8_t > data)
void percolate_out(std::span< uint8_t > data)
void intermediate_finish()
Definition ascon_perm.h:51
void initial_permute()
Definition ascon_perm.h:55
std::string provider() const
Definition ascon_perm.h:42
static constexpr size_t state_bytes()
Definition sponge.h:43
constexpr auto & state()
Definition sponge.h:55
std::array< word, words > state_t
Definition sponge.h:29
constexpr Sponge(Config config)
Definition sponge.h:39
uint8_t init_and_final_rounds
Definition ascon_perm.h:25