/src/botan/build/include/botan/internal/dilithium_modern.h
Line | Count | Source (jump to first uncovered line) |
1 | | /* |
2 | | * Asymmetric primitives for dilithium |
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 | | #ifndef BOTAN_DILITHIUM_COMMON_SYM_PRIMITIVES_H_ |
10 | | #define BOTAN_DILITHIUM_COMMON_SYM_PRIMITIVES_H_ |
11 | | |
12 | | #include <botan/internal/dilithium_symmetric_primitives.h> |
13 | | |
14 | | #include <botan/internal/shake.h> |
15 | | #include <botan/internal/shake_cipher.h> |
16 | | |
17 | | #include <array> |
18 | | #include <memory> |
19 | | #include <vector> |
20 | | |
21 | | namespace Botan { |
22 | | |
23 | | class Dilithium_Common_Symmetric_Primitives : public Dilithium_Symmetric_Primitives |
24 | | { |
25 | | public: |
26 | | std::unique_ptr<StreamCipher> XOF(const XofType type, std::span<const uint8_t> seed, |
27 | | uint16_t nonce) const override |
28 | 0 | { |
29 | | // Input is a concatination of seed | nonce used as input for shake128 |
30 | 0 | std::vector<uint8_t> input; |
31 | 0 | input.reserve(seed.size() + 2); |
32 | 0 | input.insert(input.end(), seed.begin(), seed.end()); |
33 | 0 | input.push_back(static_cast<uint8_t>(nonce)); |
34 | 0 | input.push_back(static_cast<uint8_t>(nonce >> 8)); |
35 | |
|
36 | 0 | std::unique_ptr<StreamCipher> cipher; |
37 | 0 | switch(type) |
38 | 0 | { |
39 | 0 | case XofType::k128: |
40 | 0 | cipher = std::make_unique<SHAKE_128_Cipher>(); |
41 | 0 | break; |
42 | 0 | case XofType::k256: |
43 | 0 | cipher = std::make_unique<SHAKE_256_Cipher>(); |
44 | 0 | break; |
45 | 0 | } |
46 | | |
47 | 0 | cipher->set_key(input); |
48 | |
|
49 | 0 | return cipher; |
50 | 0 | } |
51 | | }; |
52 | | |
53 | | } // namespace Botan |
54 | | |
55 | | #endif |