Botan 3.13.0
Crypto and TLS for C&
mce_internal.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_INTERNAL_H_
13#define BOTAN_MCELIECE_INTERNAL_H_
14
15#include <botan/mceliece.h>
16#include <botan/pk_ops.h>
17#include <botan/internal/polyn_gf2m.h>
18
19namespace Botan {
20
21struct McEliece_Params final {
23 size_t t;
24 size_t ext_deg;
26 size_t dimension;
29};
30
31McEliece_Params mceliece_validate_keygen_params(size_t code_length, size_t t);
32McEliece_Params mceliece_validate_key_encoding_params(size_t code_length, size_t t);
33
35 public:
36 McEliece_PublicKeyInternal(std::vector<uint8_t> public_matrix, size_t t, size_t code_length) :
37 m_public_matrix(std::move(public_matrix)), m_t(t), m_code_length(code_length) {}
38
39 const std::vector<uint8_t>& public_matrix() const { return m_public_matrix; }
40
41 size_t t() const { return m_t; }
42
43 size_t code_length() const { return m_code_length; }
44
45 size_t message_word_bit_length() const;
46
48
49 private:
50 std::vector<uint8_t> m_public_matrix;
51 size_t m_t;
52 size_t m_code_length;
53};
54
56 public:
57 McEliece_PrivateKeyInternal(std::vector<polyn_gf2m> g,
58 std::vector<polyn_gf2m> sqrtmod,
59 std::vector<gf2m> support_inverse,
60 std::vector<uint32_t> parity_check_coeffs,
61 size_t codimension,
62 size_t dimension) :
63 m_g(std::move(g)),
64 m_sqrtmod(std::move(sqrtmod)),
65 m_Linv(std::move(support_inverse)),
66 m_coeffs(std::move(parity_check_coeffs)),
67 m_codimension(codimension),
68 m_dimension(dimension) {}
69
70 const polyn_gf2m& goppa_polyn() const { return m_g[0]; }
71
72 const std::vector<polyn_gf2m>& goppa_polyn_vec() const { return m_g; }
73
74 const std::vector<polyn_gf2m>& sqrtmod() const { return m_sqrtmod; }
75
76 const std::vector<gf2m>& Linv() const { return m_Linv; }
77
78 const std::vector<uint32_t>& H_coeffs() const { return m_coeffs; }
79
80 size_t codimension() const { return m_codimension; }
81
82 size_t dimension() const { return m_dimension; }
83
84 size_t code_length() const { return m_dimension + m_codimension; }
85
86 size_t message_word_bit_length() const { return m_dimension; }
87
88 private:
89 std::vector<polyn_gf2m> m_g; // single element
90 std::vector<polyn_gf2m> m_sqrtmod;
91 std::vector<gf2m> m_Linv;
92 std::vector<uint32_t> m_coeffs;
93 size_t m_codimension;
94 size_t m_dimension;
95};
96
98 secure_vector<uint8_t>& error_mask_out,
99 const uint8_t ciphertext[],
100 size_t ciphertext_len,
101 const McEliece_PrivateKeyInternal& key);
102
103void mceliece_decrypt(secure_vector<uint8_t>& plaintext_out,
104 secure_vector<uint8_t>& error_mask_out,
105 const secure_vector<uint8_t>& ciphertext,
106 const McEliece_PrivateKeyInternal& key);
107
109 const uint8_t* ciphertext,
110 size_t ciphertext_len,
111 const McEliece_PrivateKeyInternal& key);
112
113void mceliece_encrypt(secure_vector<uint8_t>& ciphertext_out,
114 secure_vector<uint8_t>& error_mask_out,
115 const secure_vector<uint8_t>& plaintext,
116 const McEliece_PublicKeyInternal& key,
117 RandomNumberGenerator& rng);
118
119McEliece_PrivateKey generate_mceliece_key(RandomNumberGenerator& rng, size_t ext_deg, size_t code_length, size_t t);
120
121} // namespace Botan
122
123#endif
const std::vector< polyn_gf2m > & goppa_polyn_vec() const
const std::vector< polyn_gf2m > & sqrtmod() const
const std::vector< uint32_t > & H_coeffs() const
const std::vector< gf2m > & Linv() const
const polyn_gf2m & goppa_polyn() const
McEliece_PrivateKeyInternal(std::vector< polyn_gf2m > g, std::vector< polyn_gf2m > sqrtmod, std::vector< gf2m > support_inverse, std::vector< uint32_t > parity_check_coeffs, size_t codimension, size_t dimension)
McEliece_PublicKeyInternal(std::vector< uint8_t > public_matrix, size_t t, size_t code_length)
const std::vector< uint8_t > & public_matrix() const
secure_vector< uint8_t > random_plaintext_element(RandomNumberGenerator &rng) const
void mceliece_decrypt(secure_vector< uint8_t > &plaintext_out, secure_vector< uint8_t > &error_mask_out, const secure_vector< uint8_t > &ciphertext, const McEliece_PrivateKeyInternal &key)
McEliece_Params mceliece_validate_key_encoding_params(size_t code_length, size_t t)
McEliece_PrivateKey generate_mceliece_key(RandomNumberGenerator &rng, size_t ext_deg, size_t code_length, size_t t)
void mceliece_encrypt(secure_vector< uint8_t > &ciphertext_out, secure_vector< uint8_t > &error_mask_out, const secure_vector< uint8_t > &plaintext, const McEliece_PublicKeyInternal &key, RandomNumberGenerator &rng)
Definition mceliece.cpp:119
std::vector< T, secure_allocator< T > > secure_vector
Definition secmem.h:128
McEliece_Params mceliece_validate_keygen_params(size_t code_length, size_t t)