Botan 3.13.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
17#include <memory>
18
19BOTAN_DEPRECATED_HEADER("mceliece.h")
20
21namespace Botan {
22
23typedef uint16_t gf2m;
24
25class polyn_gf2m;
26class McEliece_PublicKeyInternal;
27class McEliece_PrivateKeyInternal;
28
29class BOTAN_PUBLIC_API(2, 0) McEliece_PublicKey : public virtual Public_Key /* NOLINT(*-special-member-functions) */ {
30 public:
31 McEliece_PublicKey(const AlgorithmIdentifier& alg_id, std::span<const uint8_t> key_bits);
32
33 BOTAN_DEPRECATED("Use the constructor taking an AlgorithmIdentifier")
34 explicit McEliece_PublicKey(std::span<const uint8_t> key_bits);
35
36 McEliece_PublicKey(const std::vector<uint8_t>& pub_matrix, size_t t, size_t the_code_length);
37
38 McEliece_PublicKey(const McEliece_PublicKey& other) = default;
40 ~McEliece_PublicKey() override = default;
41
43
44 std::string algo_name() const override { return "McEliece"; }
45
47
48 size_t key_length() const override;
49 size_t estimated_strength() const override;
50
51 std::vector<uint8_t> raw_public_key_bits() const override;
52 std::vector<uint8_t> public_key_bits() const override;
53
54 bool check_key(RandomNumberGenerator& rng, bool strong) const override;
55
56 size_t get_t() const;
57
58 size_t get_code_length() const;
59
60 size_t get_message_word_bit_length() const;
61
62 const std::vector<uint8_t>& get_public_matrix() const;
63
64 bool operator==(const McEliece_PublicKey& other) const;
65
66 bool operator!=(const McEliece_PublicKey& other) const { return !(*this == other); }
67
68 std::unique_ptr<Private_Key> generate_another(RandomNumberGenerator& rng) const final;
69
70 bool supports_operation(PublicKeyOperation op) const override {
72 }
73
74 std::unique_ptr<PK_Ops::KEM_Encryption> create_kem_encryption_op(std::string_view params,
75 std::string_view provider) const override;
76
77 protected:
78 McEliece_PublicKey() = default;
79
80 std::shared_ptr<const McEliece_PublicKeyInternal> m_public; // NOLINT(*non-private-member-variable*)
81};
82
85
86class BOTAN_PUBLIC_API(2, 0) McEliece_PrivateKey final : public virtual McEliece_PublicKey,
87 public virtual Private_Key {
88 public:
89 /**
90 Generate a McEliece key pair
91
92 Supported parameters for a given security level (SL)
93
94 SL=80 n=1632 t=33 - 59 KB pubkey 140 KB privkey
95 SL=107 n=2480 t=45 - 128 KB pubkey 300 KB privkey
96 SL=128 n=2960 t=57 - 195 KB pubkey 459 KB privkey
97 SL=147 n=3408 t=67 - 265 KB pubkey 622 KB privkey
98 SL=191 n=4624 t=95 - 516 KB pubkey 1234 KB privkey
99 SL=256 n=6624 t=115 - 942 KB pubkey 2184 KB privkey
100 */
101 McEliece_PrivateKey(RandomNumberGenerator& rng, size_t code_length, size_t t);
102
103 McEliece_PrivateKey(const AlgorithmIdentifier& alg_id, std::span<const uint8_t> key_bits);
104
105 BOTAN_DEPRECATED("Use the constructor taking an AlgorithmIdentifier")
106 explicit McEliece_PrivateKey(std::span<const uint8_t> key_bits);
107
108 McEliece_PrivateKey(const polyn_gf2m& goppa_polyn,
109 const std::vector<uint32_t>& parity_check_matrix_coeffs,
110 const std::vector<polyn_gf2m>& square_root_matrix,
111 const std::vector<gf2m>& inverse_support,
112 const std::vector<uint8_t>& public_matrix);
113
115
118
121
122 bool check_key(RandomNumberGenerator& rng, bool strong) const override;
123
124 const polyn_gf2m& get_goppa_polyn() const;
125
126 const std::vector<uint32_t>& get_H_coeffs() const;
127
128 const std::vector<gf2m>& get_Linv() const;
129
130 const std::vector<polyn_gf2m>& get_sqrtmod() const;
131
132 size_t get_dimension() const;
133
134 size_t get_codimension() const;
135
136 secure_vector<uint8_t> private_key_bits() const override;
137
138 std::unique_ptr<Public_Key> public_key() const override;
139
140 bool operator==(const McEliece_PrivateKey& other) const;
141
142 bool operator!=(const McEliece_PrivateKey& other) const { return !(*this == other); }
143
144 std::unique_ptr<PK_Ops::KEM_Decryption> create_kem_decryption_op(RandomNumberGenerator& rng,
145 std::string_view params,
146 std::string_view provider) const override;
147
148 private:
149 std::shared_ptr<const McEliece_PrivateKeyInternal> m_private;
150};
151
153
154/**
155* Estimate work factor for McEliece
156* @return estimated security level for these key parameters
157*/
158BOTAN_PUBLIC_API(2, 0) size_t mceliece_work_factor(size_t code_size, size_t t);
159
160} // namespace Botan
161
162#endif
#define BOTAN_DEPRECATED_HEADER(hdr)
Definition api.h:100
#define BOTAN_DIAGNOSTIC_POP
Definition api.h:128
#define BOTAN_DIAGNOSTIC_PUSH
Definition api.h:125
#define BOTAN_DIAGNOSTIC_IGNORE_INHERITED_VIA_DOMINANCE
Definition api.h:127
#define BOTAN_PUBLIC_API(maj, min)
Definition api.h:21
#define BOTAN_DEPRECATED(msg)
Definition api.h:73
virtual bool check_key(RandomNumberGenerator &rng, bool strong) const =0
virtual std::unique_ptr< Private_Key > generate_another(RandomNumberGenerator &rng) const =0
virtual size_t estimated_strength() const =0
secure_vector< uint8_t > private_key_bits() const override
const std::vector< polyn_gf2m > & get_sqrtmod() const
McEliece_PrivateKey(RandomNumberGenerator &rng, size_t code_length, size_t t)
std::unique_ptr< Public_Key > public_key() const override
McEliece_PrivateKey(const McEliece_PrivateKey &)
McEliece_PrivateKey(McEliece_PrivateKey &&) noexcept
const polyn_gf2m & get_goppa_polyn() const
const std::vector< gf2m > & get_Linv() const
const std::vector< uint32_t > & get_H_coeffs() const
McEliece_PrivateKey & operator=(const McEliece_PrivateKey &)
bool check_key(RandomNumberGenerator &rng, bool strong) const override
secure_vector< uint8_t > random_plaintext_element(RandomNumberGenerator &rng) const
std::shared_ptr< const McEliece_PublicKeyInternal > m_public
Definition mceliece.h:80
std::string algo_name() const override
Definition mceliece.h:44
bool supports_operation(PublicKeyOperation op) const override
Definition mceliece.h:70
McEliece_PublicKey(const AlgorithmIdentifier &alg_id, std::span< const uint8_t > key_bits)
McEliece_PublicKey(const McEliece_PublicKey &other)=default
bool operator!=(const McEliece_PublicKey &other) const
Definition mceliece.h:66
~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:111
virtual size_t key_length() const =0
PublicKeyOperation
Definition pk_keys.h:46
std::vector< T, secure_allocator< T > > secure_vector
Definition secmem.h:128
bool operator==(const AlgorithmIdentifier &x, const AlgorithmIdentifier &y)
Definition alg_id.cpp:54
uint16_t gf2m