| 1 |
/* |
| 2 |
* FrodoKEM 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 |
#ifndef BOTAN_FRODOKEM_CONSTANTS_H_ |
| 12 |
#define BOTAN_FRODOKEM_CONSTANTS_H_ |
| 13 |
|
| 14 |
#include <botan/frodo_mode.h> |
| 15 |
#include <botan/internal/frodo_types.h> |
| 16 |
|
| 17 |
#include <memory> |
| 18 |
#include <string> |
| 19 |
#include <vector> |
| 20 |
|
| 21 |
namespace Botan { |
| 22 |
|
| 23 |
class XOF; |
| 24 |
|
| 25 |
class BOTAN_TEST_API FrodoKEMConstants final { |
| 26 |
public: |
| 27 |
explicit FrodoKEMConstants(FrodoKEMMode mode); |
| 28 |
|
| 29 |
~FrodoKEMConstants(); |
| 30 |
|
| 31 |
FrodoKEMConstants(const FrodoKEMConstants& other) : FrodoKEMConstants(other.m_mode) {} |
| 32 |
|
| 33 |
FrodoKEMConstants(FrodoKEMConstants&& other) = default; |
| 34 |
FrodoKEMConstants& operator=(const FrodoKEMConstants& other) = delete; |
| 35 |
FrodoKEMConstants& operator=(FrodoKEMConstants&& other) = default; |
| 36 |
|
| 37 |
FrodoKEMMode mode() const { return m_mode; } |
| 38 |
|
| 39 |
size_t cdf_table_len() const { return m_cdf_table.size(); } |
| 40 |
|
| 41 |
uint16_t cdf_table_at(size_t i) const { return m_cdf_table.at(i); } |
| 42 |
|
| 43 |
size_t estimated_strength() const { return m_nist_strength; } |
| 44 |
|
| 45 |
size_t n() const { return m_n; } |
| 46 |
|
| 47 |
size_t b() const { return m_b; } // extracted bits |
| 48 |
|
| 49 |
size_t d() const { return m_d; } // D = logq |
| 50 |
|
| 51 |
size_t n_bar() const { return m_n_bar; } |
| 52 |
|
| 53 |
size_t len_a_bytes() const { return m_len_a / 8; } // len of seed_a in bytes |
| 54 |
|
| 55 |
size_t len_se_bytes() const { return m_len_se / 8; } |
| 56 |
|
| 57 |
size_t len_sec_bytes() const { return m_nist_strength / 8; } |
| 58 |
|
| 59 |
size_t len_salt_bytes() const { return m_len_salt / 8; } |
| 60 |
|
| 61 |
size_t len_ct_bytes() const { |
| 62 |
return (m_d * m_n * m_n_bar + m_d * m_n_bar * m_n_bar + m_len_salt) / 8; |
| 63 |
} // Ciphertext length in bytes |
| 64 |
|
| 65 |
size_t len_public_key_bytes() const { return (m_len_a + (m_d * m_n * m_n_bar)) / 8; } |
| 66 |
|
| 67 |
size_t len_private_key_bytes() const { |
| 68 |
return (m_nist_strength + m_len_a + (m_d * m_n * m_n_bar) + (m_n_bar * m_n * 16) + m_nist_strength) / 8; |
| 69 |
} |
| 70 |
|
| 71 |
size_t len_packed_b_bytes() const { return (m_d * m_n * m_n_bar) / 8; } |
| 72 |
|
| 73 |
size_t len_packed_c_bytes() const { return (m_d * m_n_bar * m_n_bar) / 8; } |
| 74 |
|
| 75 |
FrodoDomainSeparator encapsulation_domain_separator() const { return FrodoDomainSeparator({0x96}); } |
| 76 |
|
| 77 |
FrodoDomainSeparator keygen_domain_separator() const { return FrodoDomainSeparator({0x5F}); } |
| 78 |
|
| 79 |
std::unique_ptr<XOF> create_xof() const; |
| 80 |
|
| 81 |
private: |
| 82 |
FrodoKEMMode m_mode; |
| 83 |
size_t m_nist_strength; |
| 84 |
size_t m_len_salt; |
| 85 |
size_t m_len_se; |
| 86 |
size_t m_len_a; |
| 87 |
size_t m_b; |
| 88 |
size_t m_n; |
| 89 |
size_t m_n_bar; |
| 90 |
size_t m_d; |
| 91 |
|
| 92 |
std::vector<uint16_t> m_cdf_table; // Distribution table T_chi |
| 93 |
|
| 94 |
std::unique_ptr<XOF> m_shake_xof; |
| 95 |
|
| 96 |
std::string m_shake; |
| 97 |
}; |
| 98 |
|
| 99 |
} // namespace Botan |
| 100 |
|
| 101 |
#endif |