Botan 3.6.1
Crypto and TLS for C&
frodo_mode.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/frodo_mode.h>
12
13#include <botan/assert.h>
14#include <botan/internal/fmt.h>
15#include <botan/internal/loadstor.h>
16
17#include <memory>
18#include <tuple>
19#include <vector>
20
21namespace Botan {
22
23namespace {
24
25FrodoKEMMode::Mode FrodoKEM_mode_from_string(std::string_view str) {
26 if(str == "FrodoKEM-640-SHAKE") {
28 }
29 if(str == "FrodoKEM-976-SHAKE") {
31 }
32 if(str == "FrodoKEM-1344-SHAKE") {
34 }
35 if(str == "eFrodoKEM-640-SHAKE") {
37 }
38 if(str == "eFrodoKEM-976-SHAKE") {
40 }
41 if(str == "eFrodoKEM-1344-SHAKE") {
43 }
44
45 if(str == "FrodoKEM-640-AES") {
47 }
48 if(str == "FrodoKEM-976-AES") {
50 }
51 if(str == "FrodoKEM-1344-AES") {
53 }
54 if(str == "eFrodoKEM-640-AES") {
56 }
57 if(str == "eFrodoKEM-976-AES") {
59 }
60 if(str == "eFrodoKEM-1344-AES") {
62 }
63
64 throw Invalid_Argument(fmt("'{}' is not a valid FrodoKEM mode name", str));
65}
66
67} // anonymous namespace
68
69FrodoKEMMode::FrodoKEMMode(Mode mode) : m_mode(mode) {}
70
71FrodoKEMMode::FrodoKEMMode(const OID& oid) : m_mode(FrodoKEM_mode_from_string(oid.to_formatted_string())) {}
72
73FrodoKEMMode::FrodoKEMMode(std::string_view str) : m_mode(FrodoKEM_mode_from_string(str)) {}
74
78
79std::string FrodoKEMMode::to_string() const {
80 switch(m_mode) {
82 return "FrodoKEM-640-SHAKE";
84 return "FrodoKEM-976-SHAKE";
86 return "FrodoKEM-1344-SHAKE";
88 return "eFrodoKEM-640-SHAKE";
90 return "eFrodoKEM-976-SHAKE";
92 return "eFrodoKEM-1344-SHAKE";
93
94 case FrodoKEM640_AES:
95 return "FrodoKEM-640-AES";
96 case FrodoKEM976_AES:
97 return "FrodoKEM-976-AES";
99 return "FrodoKEM-1344-AES";
100 case eFrodoKEM640_AES:
101 return "eFrodoKEM-640-AES";
102 case eFrodoKEM976_AES:
103 return "eFrodoKEM-976-AES";
105 return "eFrodoKEM-1344-AES";
106 }
107
109}
110
111} // namespace Botan
#define BOTAN_ASSERT_UNREACHABLE()
Definition assert.h:137
std::string to_string() const
FrodoKEMMode(Mode mode)
OID object_identifier() const
static OID from_string(std::string_view str)
Definition asn1_oid.cpp:86
std::string fmt(std::string_view format, const T &... args)
Definition fmt.h:53