Botan 3.5.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
17BOTAN_DEPRECATED_HEADER("mceliece.h")
18
19namespace Botan {
20
21typedef uint16_t gf2m;
22
23class polyn_gf2m;
24
25class BOTAN_PUBLIC_API(2, 0) McEliece_PublicKey : public virtual Public_Key {
26 public:
27 explicit McEliece_PublicKey(std::span<const uint8_t> key_bits);
28
29 McEliece_PublicKey(const std::vector<uint8_t>& pub_matrix, size_t t, size_t the_code_length) :
30 m_public_matrix(pub_matrix), m_t(t), m_code_length(the_code_length) {}
31
32 McEliece_PublicKey(const McEliece_PublicKey& other) = default;
34 ~McEliece_PublicKey() override = default;
35
36 secure_vector<uint8_t> random_plaintext_element(RandomNumberGenerator& rng) const;
37
38 std::string algo_name() const override { return "McEliece"; }
39
41
42 size_t key_length() const override;
43 size_t estimated_strength() const override;
44
45 std::vector<uint8_t> raw_public_key_bits() const override;
46 std::vector<uint8_t> public_key_bits() const override;
47
48 bool check_key(RandomNumberGenerator&, bool) const override { return true; }
49
50 size_t get_t() const { return m_t; }
51
52 size_t get_code_length() const { return m_code_length; }
53
54 size_t get_message_word_bit_length() const;
55
56 const std::vector<uint8_t>& get_public_matrix() const { return m_public_matrix; }
57
58 bool operator==(const McEliece_PublicKey& other) const;
59
60 bool operator!=(const McEliece_PublicKey& other) const { return !(*this == other); }
61
62 std::unique_ptr<Private_Key> generate_another(RandomNumberGenerator& rng) const final;
63
64 bool supports_operation(PublicKeyOperation op) const override {
65 return (op == PublicKeyOperation::KeyEncapsulation);
66 }
67
68 std::unique_ptr<PK_Ops::KEM_Encryption> create_kem_encryption_op(std::string_view params,
69 std::string_view provider) const override;
70
71 protected:
72 McEliece_PublicKey() : m_t(0), m_code_length(0) {}
73
74 std::vector<uint8_t> m_public_matrix;
75 size_t m_t;
77};
78
81
83 public virtual Private_Key {
84 public:
85 /**
86 Generate a McEliece key pair
87
88 Suggested parameters for a given security level (SL)
89
90 SL=80 n=1632 t=33 - 59 KB pubkey 140 KB privkey
91 SL=107 n=2480 t=45 - 128 KB pubkey 300 KB privkey
92 SL=128 n=2960 t=57 - 195 KB pubkey 459 KB privkey
93 SL=147 n=3408 t=67 - 265 KB pubkey 622 KB privkey
94 SL=191 n=4624 t=95 - 516 KB pubkey 1234 KB privkey
95 SL=256 n=6624 t=115 - 942 KB pubkey 2184 KB privkey
96 */
97 McEliece_PrivateKey(RandomNumberGenerator& rng, size_t code_length, size_t t);
98
99 explicit McEliece_PrivateKey(std::span<const uint8_t> key_bits);
100
101 McEliece_PrivateKey(const polyn_gf2m& goppa_polyn,
102 const std::vector<uint32_t>& parity_check_matrix_coeffs,
103 const std::vector<polyn_gf2m>& square_root_matrix,
104 const std::vector<gf2m>& inverse_support,
105 const std::vector<uint8_t>& public_matrix);
106
108
111
114
115 bool check_key(RandomNumberGenerator& rng, bool strong) const override;
116
117 const polyn_gf2m& get_goppa_polyn() const;
118
119 const std::vector<uint32_t>& get_H_coeffs() const { return m_coeffs; }
120
121 const std::vector<gf2m>& get_Linv() const { return m_Linv; }
122
123 const std::vector<polyn_gf2m>& get_sqrtmod() const { return m_sqrtmod; }
124
125 inline size_t get_dimension() const { return m_dimension; }
126
127 inline size_t get_codimension() const { return m_codimension; }
128
129 secure_vector<uint8_t> private_key_bits() const override;
130
131 std::unique_ptr<Public_Key> public_key() const override;
132
133 bool operator==(const McEliece_PrivateKey& other) const;
134
135 bool operator!=(const McEliece_PrivateKey& other) const { return !(*this == other); }
136
137 std::unique_ptr<PK_Ops::KEM_Decryption> create_kem_decryption_op(RandomNumberGenerator& rng,
138 std::string_view params,
139 std::string_view provider) const override;
140
141 private:
142 std::vector<polyn_gf2m> m_g; // single element
143 std::vector<polyn_gf2m> m_sqrtmod;
144 std::vector<gf2m> m_Linv;
145 std::vector<uint32_t> m_coeffs;
146
147 size_t m_codimension;
148 size_t m_dimension;
149};
150
152
153/**
154* Estimate work factor for McEliece
155* @return estimated security level for these key parameters
156*/
157BOTAN_PUBLIC_API(2, 0) size_t mceliece_work_factor(size_t code_size, size_t t);
158
159} // namespace Botan
160
161#endif
virtual std::unique_ptr< Private_Key > generate_another(RandomNumberGenerator &rng) const =0
virtual size_t estimated_strength() const =0
const std::vector< polyn_gf2m > & get_sqrtmod() const
Definition mceliece.h:123
size_t get_codimension() const
Definition mceliece.h:127
size_t get_dimension() const
Definition mceliece.h:125
McEliece_PrivateKey(const McEliece_PrivateKey &)
McEliece_PrivateKey(McEliece_PrivateKey &&) noexcept
const std::vector< gf2m > & get_Linv() const
Definition mceliece.h:121
McEliece_PrivateKey & operator=(const McEliece_PrivateKey &)
bool operator!=(const McEliece_PrivateKey &other) const
Definition mceliece.h:135
McEliece_PublicKey(const std::vector< uint8_t > &pub_matrix, size_t t, size_t the_code_length)
Definition mceliece.h:29
bool check_key(RandomNumberGenerator &, bool) const override
Definition mceliece.h:48
size_t get_t() const
Definition mceliece.h:50
std::string algo_name() const override
Definition mceliece.h:38
bool supports_operation(PublicKeyOperation op) const override
Definition mceliece.h:64
McEliece_PublicKey(const McEliece_PublicKey &other)=default
std::vector< uint8_t > m_public_matrix
Definition mceliece.h:74
const std::vector< uint8_t > & get_public_matrix() const
Definition mceliece.h:56
bool operator!=(const McEliece_PublicKey &other) const
Definition mceliece.h:60
size_t get_code_length() const
Definition mceliece.h:52
~McEliece_PublicKey() override=default
McEliece_PublicKey & operator=(const McEliece_PublicKey &other)=default
virtual AlgorithmIdentifier algorithm_identifier() const =0
virtual std::vector< uint8_t > public_key_bits() const =0
virtual std::vector< uint8_t > raw_public_key_bits() const =0
virtual std::unique_ptr< PK_Ops::KEM_Encryption > create_kem_encryption_op(std::string_view params, std::string_view provider) const
Definition pk_keys.cpp:96
virtual size_t key_length() const =0
int(* final)(unsigned char *, CTX *)
#define BOTAN_DEPRECATED_HEADER(hdr)
Definition compiler.h:146
#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
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