Botan 2.1.0 Crypto and TLS for C++11

- Main Page
- Namespaces
- Classes
- Files

- File List
- File Members

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 #include <botan/polyn_gf2m.h>
17 #include <botan/exceptn.h>
18
19 namespace Botan {
20
21 class BOTAN_DLL McEliece_PublicKey : public virtual Public_Key
22 {
23 public:
24 explicit McEliece_PublicKey(const std::vector<uint8_t>& key_bits);
25
26 McEliece_PublicKey(const std::vector<uint8_t>& pub_matrix, uint32_t the_t, uint32_t the_code_length) :
27 m_public_matrix(pub_matrix),
28 m_t(the_t),
29 m_code_length(the_code_length){}
30
31 McEliece_PublicKey(const McEliece_PublicKey& other) = default;
32 McEliece_PublicKey& operator=(const McEliece_PublicKey& other) = default;
33 virtual ~McEliece_PublicKey()= default;
34
35 secure_vector<uint8_t> random_plaintext_element(RandomNumberGenerator& rng) const;
36
37 std::string algo_name() const override { return "McEliece"; }
38
39 AlgorithmIdentifier algorithm_identifier() const override;
40
41 size_t key_length() const override;
42 size_t estimated_strength() const override;
43
44 std::vector<uint8_t> public_key_bits() const override;
45
46 bool check_key(RandomNumberGenerator&, bool) const override
47 { return true; }
48
49 uint32_t get_t() const { return m_t; }
50 uint32_t get_code_length() const { return m_code_length; }
51 uint32_t get_message_word_bit_length() const;
52 const std::vector<uint8_t>& get_public_matrix() const { return m_public_matrix; }
53
54 bool operator==(const McEliece_PublicKey& other) const;
55 bool operator!=(const McEliece_PublicKey& other) const { return !(*this == other); }
56
57 std::unique_ptr<PK_Ops::KEM_Encryption>
58 create_kem_encryption_op(RandomNumberGenerator& rng,
59 const std::string& params,
60 const std::string& provider) const override;
61
62 protected:
63 McEliece_PublicKey() : m_t(0), m_code_length(0) {}
64
65 std::vector<uint8_t> m_public_matrix;
66 uint32_t m_t;
67 uint32_t m_code_length;
68 };
69
70 class BOTAN_DLL McEliece_PrivateKey : public virtual McEliece_PublicKey,
71 public virtual Private_Key
72 {
73 public:
74
75 /**
76 Generate a McEliece key pair
77
78 Suggested parameters for a given security level (SL)
79
80 SL=80 n=1632 t=33 - 59 KB pubkey 140 KB privkey
81 SL=107 n=2480 t=45 - 128 KB pubkey 300 KB privkey
82 SL=128 n=2960 t=57 - 195 KB pubkey 459 KB privkey
83 SL=147 n=3408 t=67 - 265 KB pubkey 622 KB privkey
84 SL=191 n=4624 t=95 - 516 KB pubkey 1234 KB privkey
85 SL=256 n=6624 t=115 - 942 KB pubkey 2184 KB privkey
86 */
87 McEliece_PrivateKey(RandomNumberGenerator& rng, size_t code_length, size_t t);
88
89 explicit McEliece_PrivateKey(const secure_vector<uint8_t>& key_bits);
90
91 McEliece_PrivateKey(polyn_gf2m const& goppa_polyn,
92 std::vector<uint32_t> const& parity_check_matrix_coeffs,
93 std::vector<polyn_gf2m> const& square_root_matrix,
94 std::vector<gf2m> const& inverse_support,
95 std::vector<uint8_t> const& public_matrix );
96
97 bool check_key(RandomNumberGenerator& rng, bool strong) const override;
98
99 polyn_gf2m const& get_goppa_polyn() const { return m_g; }
100 std::vector<uint32_t> const& get_H_coeffs() const { return m_coeffs; }
101 std::vector<gf2m> const& get_Linv() const { return m_Linv; }
102 std::vector<polyn_gf2m> const& get_sqrtmod() const { return m_sqrtmod; }
103
104 inline uint32_t get_dimension() const { return m_dimension; }
105
106 inline uint32_t get_codimension() const { return m_codimension; }
107
108 secure_vector<uint8_t> private_key_bits() const override;
109
110 bool operator==(const McEliece_PrivateKey & other) const;
111
112 bool operator!=(const McEliece_PrivateKey& other) const { return !(*this == other); }
113
114 std::unique_ptr<PK_Ops::KEM_Decryption>
115 create_kem_decryption_op(RandomNumberGenerator& rng,
116 const std::string& params,
117 const std::string& provider) const override;
118 private:
119 polyn_gf2m m_g;
120 std::vector<polyn_gf2m> m_sqrtmod;
121 std::vector<gf2m> m_Linv;
122 std::vector<uint32_t> m_coeffs;
123
124 uint32_t m_codimension;
125 uint32_t m_dimension;
126 };
127
128 /**
129 * Estimate work factor for McEliece
130 * @return estimated security level for these key parameters
131 */
132 BOTAN_DLL size_t mceliece_work_factor(size_t code_size, size_t t);
133
134 }
135
136 #endif
Botan::McEliece_PublicKey::m_public_matrix
std::vector< uint8_t > m_public_matrix
Definition: mceliece.h:65
Botan::McEliece_PrivateKey
Definition: mceliece.h:70
Botan::McEliece_PublicKey::get_t
uint32_t get_t() const
Definition: mceliece.h:49
Botan::McEliece_PublicKey::m_code_length
uint32_t m_code_length
Definition: mceliece.h:67
Botan::RandomNumberGenerator
Definition: rng.h:25
Botan::McEliece_PrivateKey::get_goppa_polyn
polyn_gf2m const & get_goppa_polyn() const
Definition: mceliece.h:99
Botan::Private_Key
Definition: pk_keys.h:166
Botan::McEliece_PrivateKey::get_H_coeffs
std::vector< uint32_t > const & get_H_coeffs() const
Definition: mceliece.h:100
Botan::operator==
bool operator==(const AlgorithmIdentifier &a1, const AlgorithmIdentifier &a2)
Definition: alg_id.cpp:67
Botan::McEliece_PrivateKey::get_Linv
std::vector< gf2m > const & get_Linv() const
Definition: mceliece.h:101
Botan::McEliece_PrivateKey::get_dimension
uint32_t get_dimension() const
Definition: mceliece.h:104
Botan::McEliece_PublicKey::get_code_length
uint32_t get_code_length() const
Definition: mceliece.h:50
Botan::McEliece_PublicKey::m_t
uint32_t m_t
Definition: mceliece.h:66
Botan::secure_vector
std::vector< T, secure_allocator< T >> secure_vector
Definition: secmem.h:121
Botan::McEliece_PublicKey::McEliece_PublicKey
McEliece_PublicKey()
Definition: mceliece.h:63
Botan::McEliece_PublicKey::McEliece_PublicKey
McEliece_PublicKey(const std::vector< uint8_t > &pub_matrix, uint32_t the_t, uint32_t the_code_length)
Definition: mceliece.h:26
Botan::McEliece_PrivateKey::get_sqrtmod
std::vector< polyn_gf2m > const & get_sqrtmod() const
Definition: mceliece.h:102
Botan::McEliece_PublicKey::get_public_matrix
const std::vector< uint8_t > & get_public_matrix() const
Definition: mceliece.h:52
Botan
Definition: alg_id.cpp:13
Botan::Public_Key
Definition: pk_keys.h:24
Botan::polyn_gf2m
Definition: polyn_gf2m.h:24
code_length
uint32_t code_length
Definition: gf2m_rootfind_dcmp.cpp:48
Botan::AlgorithmIdentifier
Definition: alg_id.h:20
Botan::McEliece_PublicKey::algo_name
std::string algo_name() const override
Definition: mceliece.h:37
Botan::McEliece_PublicKey::operator!=
bool operator!=(const McEliece_PublicKey &other) const
Definition: mceliece.h:55
Botan::McEliece_PrivateKey::get_codimension
uint32_t get_codimension() const
Definition: mceliece.h:106
Botan::McEliece_PublicKey
Definition: mceliece.h:21
Botan::McEliece_PublicKey::check_key
bool check_key(RandomNumberGenerator &, bool) const override
Definition: mceliece.h:46
Botan::McEliece_PrivateKey::operator!=
bool operator!=(const McEliece_PrivateKey &other) const
Definition: mceliece.h:112
Botan::mceliece_work_factor
size_t mceliece_work_factor(size_t n, size_t t)
Definition: mce_workfactor.cpp:95