Botan 3.11.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 std::unique_ptr<Botan::XOF> XOF128(std::span<const uint8_t> seed, uint16_t nonce) const override {
23 return create_xof(seed, nonce);
24 }
25
26 std::unique_ptr<Botan::XOF> XOF256(std::span<const uint8_t> seed, uint16_t nonce) const override {
27 return create_xof(seed, nonce);
28 }
29
30 private:
31 // AES mode always uses AES-256, regardless of the XofType
32 static std::unique_ptr<Botan::XOF> create_xof(std::span<const uint8_t> seed, uint16_t nonce) {
33 // Algorithm Spec V. 3.1 Section 5.3
34 // In the AES variant, the first 32 bytes of rhoprime are used as
35 // the key and i is extended to a 12 byte nonce for AES-256 in
36 // counter mode.
37 //
38 // I.e. when the XOF is used in "ExpandS" `seed` (aka rhoprime) will be
39 // 64 bytes long and must be truncated to the 32 most significant bytes.
40 BOTAN_ASSERT_NOMSG(seed.size() >= 32);
41
42 const std::array<uint8_t, 12> iv{get_byte<1>(nonce), get_byte<0>(nonce), 0};
43 const auto key = seed.first(32);
44
45 auto xof = std::make_unique<AES_256_CTR_XOF>();
46 xof->start(iv, key);
47 return xof;
48 }
49};
50
51} // namespace
52
55
56} // namespace Botan
#define BOTAN_ASSERT_NOMSG(expr)
Definition assert.h:75
Dilithium_AES_Symmetric_Primitives(const DilithiumConstants &mode)
constexpr uint8_t get_byte(T input)
Definition loadstor.h:79