Coverage Report

Created: 2020-10-17 06:46

/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
#include <botan/polyn_gf2m.h>
17
#include <botan/exceptn.h>
18
19
namespace Botan {
20
21
class BOTAN_PUBLIC_API(2,0) 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, size_t t, size_t the_code_length) :
27
         m_public_matrix(pub_matrix),
28
         m_t(t),
29
0
         m_code_length(the_code_length){}
30
31
      McEliece_PublicKey(const McEliece_PublicKey& other) = default;
32
0
      McEliece_PublicKey& operator=(const McEliece_PublicKey& other) = default;
33
0
      virtual ~McEliece_PublicKey()= default;
34
35
      secure_vector<uint8_t> random_plaintext_element(RandomNumberGenerator& rng) const;
36
37
0
      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
0
         { return true; }
48
49
0
      size_t get_t() const { return m_t; }
50
0
      size_t get_code_length() const { return m_code_length; }
51
      size_t get_message_word_bit_length() const;
52
0
      const std::vector<uint8_t>& get_public_matrix() const { return m_public_matrix; }
53
54
      bool operator==(const McEliece_PublicKey& other) const;
55
0
      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
0
      McEliece_PublicKey() : m_t(0), m_code_length(0) {}
64
65
      std::vector<uint8_t> m_public_matrix;
66
      size_t m_t;
67
      size_t m_code_length;
68
   };
69
70
class BOTAN_PUBLIC_API(2,0) McEliece_PrivateKey final : 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
0
      polyn_gf2m const& get_goppa_polyn() const { return m_g; }
100
0
      std::vector<uint32_t> const& get_H_coeffs() const { return m_coeffs; }
101
0
      std::vector<gf2m> const& get_Linv() const { return m_Linv; }
102
0
      std::vector<polyn_gf2m> const& get_sqrtmod() const { return m_sqrtmod; }
103
104
0
      inline size_t get_dimension() const { return m_dimension; }
105
106
0
      inline size_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
0
      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
      size_t m_codimension;
125
      size_t m_dimension;
126
   };
127
128
/**
129
* Estimate work factor for McEliece
130
* @return estimated security level for these key parameters
131
*/
132
BOTAN_PUBLIC_API(2,0) size_t mceliece_work_factor(size_t code_size, size_t t);
133
134
}
135
136
#endif