Botan
3.5.0
Crypto and TLS for C&
src
lib
pubkey
kyber
kyber_common
kyber_constants.cpp
Go to the documentation of this file.
1
/*
2
* Crystals Kyber Constants
3
*
4
* (C) 2021-2024 Jack Lloyd
5
* (C) 2021-2022 Manuel Glaser and Michael Boric, Rohde & Schwarz Cybersecurity
6
* (C) 2021-2022 René Meusel and Hannes Rantzsch, neXenio GmbH
7
* (C) 2024 René Meusel, Rohde & Schwarz Cybersecurity
8
*
9
* Botan is released under the Simplified BSD License (see license.txt)
10
*/
11
12
#include <botan/internal/kyber_constants.h>
13
14
#if defined(BOTAN_HAS_KYBER)
15
#include <botan/internal/kyber_modern.h>
16
#endif
17
18
#if defined(BOTAN_HAS_KYBER_90S)
19
#include <botan/internal/kyber_90s.h>
20
#endif
21
22
namespace
Botan
{
23
24
KyberConstants::KyberConstants
(
KyberMode
mode) : m_mode(mode) {
25
switch
(
mode
.
mode
()) {
26
case
KyberMode::Kyber512_R3
:
27
case
KyberMode::Kyber512_90s
:
28
m_nist_strength = 128;
29
m_k = 2;
30
m_eta1 = 3;
31
break
;
32
33
case
KyberMode::Kyber768_R3
:
34
case
KyberMode::Kyber768_90s
:
35
m_nist_strength = 192;
36
m_k = 3;
37
m_eta1 = 2;
38
break
;
39
40
case
KyberMode::Kyber1024_R3
:
41
case
KyberMode::Kyber1024_90s
:
42
m_nist_strength = 256;
43
m_k = 4;
44
m_eta1 = 2;
45
break
;
46
47
default
:
48
BOTAN_ASSERT_UNREACHABLE
();
49
}
50
51
#ifdef BOTAN_HAS_KYBER_90S
52
if
(
mode
.
is_kyber_round3
() &&
mode
.
is_90s
()) {
53
m_symmetric_primitives = std::make_unique<Kyber_90s_Symmetric_Primitives>();
54
}
55
#endif
56
57
#ifdef BOTAN_HAS_KYBER
58
if
(
mode
.
is_kyber_round3
() &&
mode
.
is_modern
()) {
59
m_symmetric_primitives = std::make_unique<Kyber_Modern_Symmetric_Primitives>();
60
}
61
#endif
62
63
if
(!m_symmetric_primitives) {
64
throw
Not_Implemented
(
"requested Kyber mode is not enabled in this build"
);
65
}
66
}
67
68
KyberConstants::~KyberConstants
() =
default
;
69
70
}
// namespace Botan
BOTAN_ASSERT_UNREACHABLE
#define BOTAN_ASSERT_UNREACHABLE()
Definition
assert.h:137
Botan::KyberConstants::KyberConstants
KyberConstants(KyberMode mode)
Definition
kyber_constants.cpp:24
Botan::KyberConstants::~KyberConstants
~KyberConstants()
Botan::KyberConstants::mode
KyberMode mode() const
Definition
kyber_constants.h:66
Botan::KyberMode
Definition
kyber.h:30
Botan::KyberMode::Kyber1024_90s
@ Kyber1024_90s
Definition
kyber.h:46
Botan::KyberMode::Kyber768_R3
@ Kyber768_R3
Definition
kyber.h:36
Botan::KyberMode::Kyber1024_R3
@ Kyber1024_R3
Definition
kyber.h:38
Botan::KyberMode::Kyber768_90s
@ Kyber768_90s
Definition
kyber.h:45
Botan::KyberMode::Kyber512_90s
@ Kyber512_90s
Definition
kyber.h:44
Botan::KyberMode::Kyber512_R3
@ Kyber512_R3
Definition
kyber.h:34
Botan::KyberMode::is_kyber_round3
bool is_kyber_round3() const
Definition
kyber.cpp:112
Botan::KyberMode::is_modern
bool is_modern() const
Definition
kyber.cpp:108
Botan::KyberMode::is_90s
bool is_90s() const
Definition
kyber.cpp:104
Botan::KyberMode::mode
Mode mode() const
Definition
kyber.h:56
Botan::Not_Implemented
Definition
exceptn.h:334
Botan
Definition
alg_id.cpp:13
Generated by
1.11.0