Botan 3.6.0
Crypto and TLS for C&
dilithium_aes.cpp
Go to the documentation of this file.
1/*
2* Symmetric primitives for dilithium AES
3* (C) 2022 Jack Lloyd
4* (C) 2022 Manuel Glaser, Michael Boric, René Meusel - Rohde & Schwarz Cybersecurity
5*
6* Botan is released under the Simplified BSD License (see license.txt)
7*/
8
9#include <botan/internal/dilithium_aes.h>
10
11#include <botan/internal/aes_crystals_xof.h>
12#include <botan/internal/loadstor.h>
13
14#include <array>
15
16namespace Botan {
17
18namespace {
19
20class AES_XOF final : public DilithiumXOF {
21 public:
22 Botan::XOF& XOF128(std::span<const uint8_t> seed, uint16_t nonce) const override {
23 return XOF(m_aes_xof, seed, nonce);
24 }
25
26 Botan::XOF& XOF256(std::span<const uint8_t> seed, uint16_t nonce) const override {
27 return XOF(m_aes_xof, seed, nonce);
28 }
29
30 // AES mode always uses AES-256, regardless of the XofType
31 static Botan::XOF& XOF(Botan::XOF& xof, std::span<const uint8_t> seed, uint16_t nonce) {
32 // Algorithm Spec V. 3.1 Section 5.3
33 // In the AES variant, the first 32 bytes of rhoprime are used as
34 // the key and i is extended to a 12 byte nonce for AES-256 in
35 // counter mode.
36 //
37 // I.e. when the XOF is used in "ExpandS" `seed` (aka rhoprime) will be
38 // 64 bytes long and must be truncated to the 32 most significant bytes.
39 BOTAN_ASSERT_NOMSG(seed.size() >= 32);
40
41 const std::array<uint8_t, 12> iv{get_byte<1>(nonce), get_byte<0>(nonce), 0};
42 const auto key = seed.first(32);
43
44 xof.clear();
45 xof.start(iv, key);
46 return xof;
47 }
48
49 private:
50 mutable AES_256_CTR_XOF m_aes_xof;
51};
52
53} // namespace
54
57
58} // namespace Botan
#define BOTAN_ASSERT_NOMSG(expr)
Definition assert.h:59
Dilithium_AES_Symmetric_Primitives(const DilithiumConstants &mode)
void clear()
Definition xof.h:66
void start(std::span< const uint8_t > salt={}, std::span< const uint8_t > key={})
Definition xof.cpp:58
int(* final)(unsigned char *, CTX *)
constexpr uint8_t get_byte(T input)
Definition loadstor.h:75