Botan 3.4.0
Crypto and TLS for C&
mceliece.h
Go to the documentation of this file.
1/*
2 * (C) Copyright Projet SECRET, INRIA, Rocquencourt
3 * (C) Bhaskar Biswas and Nicolas Sendrier
4 *
5 * (C) 2014 cryptosource GmbH
6 * (C) 2014 Falko Strenzke fstrenzke@cryptosource.de
7 *
8 * Botan is released under the Simplified BSD License (see license.txt)
9 *
10 */
11
12#ifndef BOTAN_MCELIECE_KEY_H_
13#define BOTAN_MCELIECE_KEY_H_
14
15#include <botan/pk_keys.h>
16
17namespace Botan {
18
19typedef uint16_t gf2m;
20
21class polyn_gf2m;
22
23class BOTAN_PUBLIC_API(2, 0) McEliece_PublicKey : public virtual Public_Key {
24 public:
25 explicit McEliece_PublicKey(std::span<const uint8_t> key_bits);
26
27 McEliece_PublicKey(const std::vector<uint8_t>& pub_matrix, size_t t, size_t the_code_length) :
28 m_public_matrix(pub_matrix), m_t(t), m_code_length(the_code_length) {}
29
30 McEliece_PublicKey(const McEliece_PublicKey& other) = default;
32 ~McEliece_PublicKey() override = default;
33
34 secure_vector<uint8_t> random_plaintext_element(RandomNumberGenerator& rng) const;
35
36 std::string algo_name() const override { return "McEliece"; }
37
38 AlgorithmIdentifier algorithm_identifier() const override;
39
40 size_t key_length() const override;
41 size_t estimated_strength() const override;
42
43 std::vector<uint8_t> public_key_bits() const override;
44
45 bool check_key(RandomNumberGenerator&, bool) const override { return true; }
46
47 size_t get_t() const { return m_t; }
48
49 size_t get_code_length() const { return m_code_length; }
50
51 size_t get_message_word_bit_length() const;
52
53 const std::vector<uint8_t>& get_public_matrix() const { return m_public_matrix; }
54
55 bool operator==(const McEliece_PublicKey& other) const;
56
57 bool operator!=(const McEliece_PublicKey& other) const { return !(*this == other); }
58
59 std::unique_ptr<Private_Key> generate_another(RandomNumberGenerator& rng) const final;
60
61 bool supports_operation(PublicKeyOperation op) const override {
62 return (op == PublicKeyOperation::KeyEncapsulation);
63 }
64
65 std::unique_ptr<PK_Ops::KEM_Encryption> create_kem_encryption_op(std::string_view params,
66 std::string_view provider) const override;
67
68 protected:
69 McEliece_PublicKey() : m_t(0), m_code_length(0) {}
70
71 std::vector<uint8_t> m_public_matrix;
72 size_t m_t;
74};
75
78
80 public virtual Private_Key {
81 public:
82 /**
83 Generate a McEliece key pair
84
85 Suggested parameters for a given security level (SL)
86
87 SL=80 n=1632 t=33 - 59 KB pubkey 140 KB privkey
88 SL=107 n=2480 t=45 - 128 KB pubkey 300 KB privkey
89 SL=128 n=2960 t=57 - 195 KB pubkey 459 KB privkey
90 SL=147 n=3408 t=67 - 265 KB pubkey 622 KB privkey
91 SL=191 n=4624 t=95 - 516 KB pubkey 1234 KB privkey
92 SL=256 n=6624 t=115 - 942 KB pubkey 2184 KB privkey
93 */
94 McEliece_PrivateKey(RandomNumberGenerator& rng, size_t code_length, size_t t);
95
96 explicit McEliece_PrivateKey(std::span<const uint8_t> key_bits);
97
98 McEliece_PrivateKey(const polyn_gf2m& goppa_polyn,
99 const std::vector<uint32_t>& parity_check_matrix_coeffs,
100 const std::vector<polyn_gf2m>& square_root_matrix,
101 const std::vector<gf2m>& inverse_support,
102 const std::vector<uint8_t>& public_matrix);
103
105
108
111
112 bool check_key(RandomNumberGenerator& rng, bool strong) const override;
113
114 const polyn_gf2m& get_goppa_polyn() const;
115
116 const std::vector<uint32_t>& get_H_coeffs() const { return m_coeffs; }
117
118 const std::vector<gf2m>& get_Linv() const { return m_Linv; }
119
120 const std::vector<polyn_gf2m>& get_sqrtmod() const { return m_sqrtmod; }
121
122 inline size_t get_dimension() const { return m_dimension; }
123
124 inline size_t get_codimension() const { return m_codimension; }
125
126 secure_vector<uint8_t> private_key_bits() const override;
127
128 std::unique_ptr<Public_Key> public_key() const override;
129
130 bool operator==(const McEliece_PrivateKey& other) const;
131
132 bool operator!=(const McEliece_PrivateKey& other) const { return !(*this == other); }
133
134 std::unique_ptr<PK_Ops::KEM_Decryption> create_kem_decryption_op(RandomNumberGenerator& rng,
135 std::string_view params,
136 std::string_view provider) const override;
137
138 private:
139 std::vector<polyn_gf2m> m_g; // single element
140 std::vector<polyn_gf2m> m_sqrtmod;
141 std::vector<gf2m> m_Linv;
142 std::vector<uint32_t> m_coeffs;
143
144 size_t m_codimension;
145 size_t m_dimension;
146};
147
149
150/**
151* Estimate work factor for McEliece
152* @return estimated security level for these key parameters
153*/
154BOTAN_PUBLIC_API(2, 0) size_t mceliece_work_factor(size_t code_size, size_t t);
155
156} // namespace Botan
157
158#endif
const std::vector< polyn_gf2m > & get_sqrtmod() const
Definition mceliece.h:120
size_t get_codimension() const
Definition mceliece.h:124
size_t get_dimension() const
Definition mceliece.h:122
McEliece_PrivateKey(const McEliece_PrivateKey &)
McEliece_PrivateKey(McEliece_PrivateKey &&) noexcept
const std::vector< gf2m > & get_Linv() const
Definition mceliece.h:118
McEliece_PrivateKey & operator=(const McEliece_PrivateKey &)
bool operator!=(const McEliece_PrivateKey &other) const
Definition mceliece.h:132
McEliece_PublicKey(const std::vector< uint8_t > &pub_matrix, size_t t, size_t the_code_length)
Definition mceliece.h:27
bool check_key(RandomNumberGenerator &, bool) const override
Definition mceliece.h:45
size_t get_t() const
Definition mceliece.h:47
std::string algo_name() const override
Definition mceliece.h:36
bool supports_operation(PublicKeyOperation op) const override
Definition mceliece.h:61
McEliece_PublicKey(const McEliece_PublicKey &other)=default
std::vector< uint8_t > m_public_matrix
Definition mceliece.h:71
const std::vector< uint8_t > & get_public_matrix() const
Definition mceliece.h:53
bool operator!=(const McEliece_PublicKey &other) const
Definition mceliece.h:57
size_t get_code_length() const
Definition mceliece.h:49
~McEliece_PublicKey() override=default
McEliece_PublicKey & operator=(const McEliece_PublicKey &other)=default
int(* final)(unsigned char *, CTX *)
#define BOTAN_DIAGNOSTIC_POP
Definition compiler.h:191
#define BOTAN_DIAGNOSTIC_PUSH
Definition compiler.h:188
#define BOTAN_DIAGNOSTIC_IGNORE_INHERITED_VIA_DOMINANCE
Definition compiler.h:190
#define BOTAN_PUBLIC_API(maj, min)
Definition compiler.h:31
PublicKeyOperation
Definition pk_keys.h:45
size_t mceliece_work_factor(size_t n, size_t t)
bool operator==(const AlgorithmIdentifier &a1, const AlgorithmIdentifier &a2)
Definition alg_id.cpp:54
std::vector< T, secure_allocator< T > > secure_vector
Definition secmem.h:61
uint16_t gf2m