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