Botan 3.4.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 = constants.n(), aes = setup_aes(seed_a)](std::span<uint8_t> out, uint16_t i) {
35 BufferStuffer out_bs(out);
36
37 for(size_t j = 0; j < n; j += 8) {
38 // set up the to-be-encrypted 'b' value in the out variable
39 // for in-place encryption of the block cipher
40 auto out_coefs = out_bs.next(aes.block_size());
41
42 // b = i || j || 0000...
43 store_le(static_cast<uint16_t>(i), out_coefs.data());
44 store_le(static_cast<uint16_t>(j), out_coefs.data() + sizeof(uint16_t));
45 for(size_t ii = 4; ii < out_coefs.size(); ++ii) {
46 out_coefs[ii] = 0;
47 }
48
49 aes.encrypt(out_coefs);
50 }
51 };
52}
53
54} // namespace Botan
55
56#endif
#define BOTAN_ASSERT_NOMSG(expr)
Definition assert.h:59
Helper class to ease in-place marshalling of concatenated fixed-length values.
Definition stl_util.h:200
constexpr std::span< uint8_t > next(size_t bytes)
Definition stl_util.h:208
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:702
auto create_aes_row_generator(const FrodoKEMConstants &constants, StrongSpan< const FrodoSeedA > seed_a)