Botan 3.0.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
24 {
25 public:
26 explicit McEliece_PublicKey(std::span<const 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 m_code_length(the_code_length){}
32
33 McEliece_PublicKey(const McEliece_PublicKey& other) = default;
35 virtual ~McEliece_PublicKey()= default;
36
37 secure_vector<uint8_t> random_plaintext_element(RandomNumberGenerator& rng) const;
38
39 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 { return true; }
50
51 size_t get_t() const { return m_t; }
52 size_t get_code_length() const { return m_code_length; }
53 size_t get_message_word_bit_length() const;
54 const std::vector<uint8_t>& get_public_matrix() const { return m_public_matrix; }
55
56 bool operator==(const McEliece_PublicKey& other) const;
57 bool operator!=(const McEliece_PublicKey& other) const { return !(*this == other); }
58
59 bool supports_operation(PublicKeyOperation op) const override
60 {
61 return (op == PublicKeyOperation::KeyEncapsulation);
62 }
63
64 std::unique_ptr<PK_Ops::KEM_Encryption>
65 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 {
82 public:
83
84 /**
85 Generate a McEliece key pair
86
87 Suggested parameters for a given security level (SL)
88
89 SL=80 n=1632 t=33 - 59 KB pubkey 140 KB privkey
90 SL=107 n=2480 t=45 - 128 KB pubkey 300 KB privkey
91 SL=128 n=2960 t=57 - 195 KB pubkey 459 KB privkey
92 SL=147 n=3408 t=67 - 265 KB pubkey 622 KB privkey
93 SL=191 n=4624 t=95 - 516 KB pubkey 1234 KB privkey
94 SL=256 n=6624 t=115 - 942 KB pubkey 2184 KB privkey
95 */
96 McEliece_PrivateKey(RandomNumberGenerator& rng, size_t code_length, size_t t);
97
98 explicit McEliece_PrivateKey(std::span<const uint8_t> key_bits);
99
100 McEliece_PrivateKey(polyn_gf2m const& goppa_polyn,
101 std::vector<uint32_t> const& parity_check_matrix_coeffs,
102 std::vector<polyn_gf2m> const& square_root_matrix,
103 std::vector<gf2m> const& inverse_support,
104 std::vector<uint8_t> const& public_matrix );
105
107
110
113
114 bool check_key(RandomNumberGenerator& rng, bool strong) const override;
115
116 polyn_gf2m const& get_goppa_polyn() const;
117 std::vector<uint32_t> const& get_H_coeffs() const { return m_coeffs; }
118 std::vector<gf2m> const& get_Linv() const { return m_Linv; }
119 std::vector<polyn_gf2m> const& get_sqrtmod() const { return m_sqrtmod; }
120
121 inline size_t get_dimension() const { return m_dimension; }
122
123 inline size_t get_codimension() const { return m_codimension; }
124
125 secure_vector<uint8_t> private_key_bits() const override;
126
127 std::unique_ptr<Public_Key> public_key() const override;
128
129 bool operator==(const McEliece_PrivateKey & other) const;
130
131 bool operator!=(const McEliece_PrivateKey& other) const { return !(*this == other); }
132
133 std::unique_ptr<PK_Ops::KEM_Decryption>
134 create_kem_decryption_op(RandomNumberGenerator& rng,
135 std::string_view params,
136 std::string_view provider) const override;
137 private:
138 std::vector<polyn_gf2m> m_g; // single element
139 std::vector<polyn_gf2m> m_sqrtmod;
140 std::vector<gf2m> m_Linv;
141 std::vector<uint32_t> m_coeffs;
142
143 size_t m_codimension;
144 size_t m_dimension;
145 };
146
148
149/**
150* Estimate work factor for McEliece
151* @return estimated security level for these key parameters
152*/
153BOTAN_PUBLIC_API(2,0) size_t mceliece_work_factor(size_t code_size, size_t t);
154
155}
156
157#endif
std::vector< gf2m > const & get_Linv() const
Definition: mceliece.h:118
size_t get_codimension() const
Definition: mceliece.h:123
size_t get_dimension() const
Definition: mceliece.h:121
McEliece_PrivateKey(const McEliece_PrivateKey &)
McEliece_PrivateKey(McEliece_PrivateKey &&) noexcept
std::vector< polyn_gf2m > const & get_sqrtmod() const
Definition: mceliece.h:119
McEliece_PrivateKey & operator=(const McEliece_PrivateKey &)
bool operator!=(const McEliece_PrivateKey &other) const
Definition: mceliece.h:131
McEliece_PublicKey(const std::vector< uint8_t > &pub_matrix, size_t t, size_t the_code_length)
Definition: mceliece.h:28
bool check_key(RandomNumberGenerator &, bool) const override
Definition: mceliece.h:48
size_t get_t() const
Definition: mceliece.h:51
virtual ~McEliece_PublicKey()=default
std::string algo_name() const override
Definition: mceliece.h:39
bool supports_operation(PublicKeyOperation op) const override
Definition: mceliece.h:59
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:54
bool operator!=(const McEliece_PublicKey &other) const
Definition: mceliece.h:57
size_t get_code_length() const
Definition: mceliece.h:52
McEliece_PublicKey & operator=(const McEliece_PublicKey &other)=default
int(* final)(unsigned char *, CTX *)
#define BOTAN_DIAGNOSTIC_POP
Definition: compiler.h:204
#define BOTAN_DIAGNOSTIC_PUSH
Definition: compiler.h:201
#define BOTAN_DIAGNOSTIC_IGNORE_INHERITED_VIA_DOMINANCE
Definition: compiler.h:203
#define BOTAN_PUBLIC_API(maj, min)
Definition: compiler.h:31
Definition: alg_id.cpp:12
PublicKeyOperation
Definition: pk_keys.h:43
size_t mceliece_work_factor(size_t n, size_t t)
bool operator==(const AlgorithmIdentifier &a1, const AlgorithmIdentifier &a2)
Definition: alg_id.cpp:64
std::vector< T, secure_allocator< T > > secure_vector
Definition: secmem.h:64
uint16_t gf2m
Definition: gf2m_small_m.h:20
Definition: bigint.h:1092