Botan 3.5.0
Crypto and TLS for C&
frodo_aes_generator.h
Go to the documentation of this file.
1/*
2 * FrodoKEM matrix generator based on AES
3 *
4 * The Fellowship of the FrodoKEM:
5 * (C) 2023 Jack Lloyd
6 * 2023 René Meusel, Amos Treiber - Rohde & Schwarz Cybersecurity
7 *
8 * Botan is released under the Simplified BSD License (see license.txt)
9 */
10
11#ifndef BOTAN_FRODOKEM_AES_GENERATOR_H_
12#define BOTAN_FRODOKEM_AES_GENERATOR_H_
13
14#include <botan/internal/aes.h>
15#include <botan/internal/frodo_constants.h>
16#include <botan/internal/frodo_types.h>
17#include <botan/internal/loadstor.h>
18#include <botan/internal/stl_util.h>
19
20#include <functional>
21#include <span>
22
23namespace Botan {
24
26 BOTAN_ASSERT_NOMSG(constants.mode().is_aes());
27
28 auto setup_aes = [](StrongSpan<const FrodoSeedA> seed) {
29 AES_128 aes;
30 aes.set_key(seed);
31 return aes;
32 };
33
34 return [n = static_cast<uint16_t>(constants.n()), aes = setup_aes(seed_a)](std::span<uint8_t> out, uint16_t i) {
35 BufferStuffer out_bs(out);
36
38
39 for(uint16_t j = 0; j < n; j += AES_128::BLOCK_SIZE / 2) {
40 // set up the to-be-encrypted 'b' value in the out variable
41 // for in-place encryption of the block cipher
42 // b = i || j || 0000...
43 out_bs.append(store_le(i, j));
44 clear_mem(out_bs.next<AES_128::BLOCK_SIZE - sizeof(i) - sizeof(j)>());
45 }
46
47 BOTAN_DEBUG_ASSERT(out_bs.full());
48
49 aes.encrypt(out);
50 };
51}
52
53} // namespace Botan
54
55#endif
#define BOTAN_ASSERT_NOMSG(expr)
Definition assert.h:59
#define BOTAN_DEBUG_ASSERT(expr)
Definition assert.h:98
Helper class to ease in-place marshalling of concatenated fixed-length values.
Definition stl_util.h:142
constexpr void append(std::span< const uint8_t > buffer)
Definition stl_util.h:177
constexpr size_t remaining_capacity() const
Definition stl_util.h:189
constexpr std::span< uint8_t > next(size_t bytes)
Definition stl_util.h:150
constexpr bool full() const
Definition stl_util.h:187
FrodoKEMMode mode() const
bool is_aes() const
Definition frodo_mode.h:61
void set_key(const SymmetricKey &key)
Definition sym_algo.h:113
constexpr auto store_le(ParamTs &&... params)
Definition loadstor.h:698
auto create_aes_row_generator(const FrodoKEMConstants &constants, StrongSpan< const FrodoSeedA > seed_a)
constexpr void clear_mem(T *ptr, size_t n)
Definition mem_ops.h:120