Botan 3.14.1
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 <span>
19
20namespace Botan {
21
23 BOTAN_ASSERT_NOMSG(constants.mode().is_aes());
24
25 const auto setup_aes = [](StrongSpan<const FrodoSeedA> seed) {
26 AES_128 aes;
27 aes.set_key(seed);
28 return aes;
29 };
30
31 return [n = static_cast<uint16_t>(constants.n()), aes = setup_aes(seed_a)](
32 std::span<uint8_t> out, uint16_t first_row, size_t nrows) {
33 BOTAN_DEBUG_ASSERT(out.size() == nrows * (n / (AES_128::BLOCK_SIZE / 2)) * AES_128::BLOCK_SIZE);
34
35 // Set up the to-be-encrypted 'b' values for in-place encryption:
36 // each block is le16(i) || le16(j) || 0000...
37 auto p = std::span{out};
38 for(size_t r = 0; r != nrows; ++r) {
39 const uint16_t i = static_cast<uint16_t>(first_row + r);
40 for(uint16_t j = 0; j < n; j += AES_128::BLOCK_SIZE / 2) {
41 constexpr uint16_t zero = 0;
42 store_le(p.first<AES_128::BLOCK_SIZE>(), i, j, zero, zero, zero, zero, zero, zero);
43 p = p.subspan(AES_128::BLOCK_SIZE);
44 }
45 }
46
47 aes.encrypt(out);
48 };
49}
50
51} // namespace Botan
52
53#endif
#define BOTAN_ASSERT_NOMSG(expr)
Definition assert.h:82
#define BOTAN_DEBUG_ASSERT(expr)
Definition assert.h:136
FrodoKEMMode mode() const
bool is_aes() const
Definition frodo_mode.h:61
void set_key(const OctetString &key)
Definition sym_algo.cpp:14
constexpr auto store_le(ParamTs &&... params)
Definition loadstor.h:736
auto create_aes_row_generator(const FrodoKEMConstants &constants, StrongSpan< const FrodoSeedA > seed_a)