Botan 3.6.1
Crypto and TLS for C&
frodo_constants.cpp
Go to the documentation of this file.
1/*
2 * FrodoKEM modes and constants
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#include <botan/internal/frodo_constants.h>
12
13#include <botan/xof.h>
14
15namespace Botan {
16
17FrodoKEMConstants::FrodoKEMConstants(FrodoKEMMode mode) : m_mode(mode), m_len_a(128), m_n_bar(8) {
18 if(!mode.is_available()) {
19 throw Not_Implemented("FrodoKEM mode " + mode.to_string() + " is not available");
20 }
21
22 if(mode.is_ephemeral()) {
23 m_len_salt = 0;
24 }
25
26 switch(mode.mode()) {
27 case FrodoKEMMode::FrodoKEM640_SHAKE:
28 case FrodoKEMMode::FrodoKEM640_AES:
29 case FrodoKEMMode::eFrodoKEM640_SHAKE:
30 case FrodoKEMMode::eFrodoKEM640_AES:
31 m_nist_strength = 128;
32 m_d = 15;
33 m_n = 640;
34 m_b = 2;
35 if(mode.is_static()) {
36 m_len_salt = 256;
37 m_len_se = 256;
38 } else if(mode.is_ephemeral()) {
39 m_len_se = 128;
40 } else {
41 BOTAN_ASSERT_UNREACHABLE();
42 }
43
44 m_cdf_table = {4643, 13363, 20579, 25843, 29227, 31145, 32103, 32525, 32689, 32745, 32762, 32766, 32767};
45
46 m_shake = "SHAKE-128";
47 break;
48
53 m_nist_strength = 192;
54 m_d = 16;
55 m_n = 976;
56 m_b = 3;
57 if(mode.is_static()) {
58 m_len_salt = 384;
59 m_len_se = 384;
60 } else if(mode.is_ephemeral()) {
61 m_len_se = 192;
62 } else {
63 BOTAN_ASSERT_UNREACHABLE();
64 }
65
66 m_cdf_table = {5638, 15915, 23689, 28571, 31116, 32217, 32613, 32731, 32760, 32766, 32767};
67
68 m_shake = "SHAKE-256";
69 break;
70
75 m_nist_strength = 256;
76 m_d = 16;
77 m_n = 1344;
78 m_b = 4;
79 if(mode.is_static()) {
80 m_len_salt = 512;
81 m_len_se = 512;
82 } else if(mode.is_ephemeral()) {
83 m_len_se = 256;
84 } else {
85 BOTAN_ASSERT_UNREACHABLE();
86 }
87
88 m_cdf_table = {9142, 23462, 30338, 32361, 32725, 32765, 32767};
89
90 m_shake = "SHAKE-256";
91 break;
92 }
93
94 m_shake_xof = XOF::create_or_throw(m_shake);
95}
96
97FrodoKEMConstants::~FrodoKEMConstants() = default;
98
99XOF& FrodoKEMConstants::SHAKE_XOF() const {
100 m_shake_xof->clear();
101 return *m_shake_xof;
102}
103
104} // namespace Botan
FrodoKEMMode mode() const
FrodoKEMConstants(FrodoKEMMode mode)
bool is_static() const
Definition frodo_mode.h:51
bool is_available() const
Definition frodo_mode.h:66
Mode mode() const
Definition frodo_mode.h:44
bool is_ephemeral() const
Definition frodo_mode.h:46
void clear()
Definition xof.h:66
static std::unique_ptr< XOF > create_or_throw(std::string_view algo_spec, std::string_view provider="")
Definition xof.cpp:42