Botan  1.11.15
src/lib/pubkey/mce/mceliece_key.h
Go to the documentation of this file.
00001 /**
00002  * (C) Copyright Projet SECRET, INRIA, Rocquencourt
00003  * (C) Bhaskar Biswas and  Nicolas Sendrier
00004  *
00005  * (C) 2014 cryptosource GmbH
00006  * (C) 2014 Falko Strenzke fstrenzke@cryptosource.de
00007  *
00008  * Botan is released under the Simplified BSD License (see license.txt)
00009  *
00010  */
00011 
00012 #ifndef BOTAN_MCELIECE_KEY_H__
00013 #define BOTAN_MCELIECE_KEY_H__
00014 
00015 #include <botan/exceptn.h>
00016 #include <botan/pk_keys.h>
00017 #include <botan/polyn_gf2m.h>
00018 
00019 namespace Botan {
00020 
00021 class BOTAN_DLL McEliece_PublicKey : public virtual Public_Key
00022    {
00023    public:
00024 
00025       McEliece_PublicKey(const std::vector<byte>& key_bits);
00026 
00027       McEliece_PublicKey(std::vector<byte> const& pub_matrix, u32bit the_t, u32bit the_code_length) :
00028          m_public_matrix(pub_matrix),
00029          m_t(the_t),
00030          m_code_length(the_code_length)
00031             {}
00032 
00033       McEliece_PublicKey(const McEliece_PublicKey & other);
00034 
00035       std::string algo_name() const { return "McEliece"; }
00036 
00037       /**
00038       * Get the maximum number of bits allowed to be fed to this key.
00039       * This is the bitlength of the order of the base point.
00040       * @result the maximum number of input bits
00041       */
00042       size_t max_input_bits() const
00043          {
00044          return get_message_word_bit_length();
00045          };
00046 
00047       AlgorithmIdentifier algorithm_identifier() const;
00048 
00049       size_t estimated_strength() const;
00050 
00051       std::vector<byte> x509_subject_public_key() const;
00052 
00053       bool check_key(RandomNumberGenerator&, bool) const
00054          { return true; }
00055 
00056       u32bit get_t() const { return m_t; }
00057       u32bit get_code_length() const { return m_code_length; }
00058       u32bit get_message_word_bit_length() const;
00059       std::vector<byte> const& get_public_matrix() const { return m_public_matrix; }
00060 
00061       bool operator==(const McEliece_PublicKey& other) const;
00062       bool operator!=(const McEliece_PublicKey& other) const { return !(*this == other); }
00063 
00064    protected:
00065       McEliece_PublicKey() {}
00066 
00067       std::vector<byte> m_public_matrix;
00068       u32bit m_t;
00069       u32bit m_code_length;
00070    };
00071 
00072 class BOTAN_DLL McEliece_PrivateKey : public virtual McEliece_PublicKey,
00073                                       public virtual Private_Key
00074    {
00075    public:
00076       /**
00077       * Get the maximum number of bits allowed to be fed to this key.
00078       * This is the bitlength of the order of the base point.
00079       * @result the maximum number of input bits
00080       */
00081       size_t max_input_bits() const {
00082       return m_Linv.size();
00083       };
00084 
00085       McEliece_PrivateKey(const secure_vector<byte>& key_bits);
00086 
00087       McEliece_PrivateKey(polyn_gf2m const& goppa_polyn,
00088                           std::vector<u32bit> const& parity_check_matrix_coeffs,
00089                           std::vector<polyn_gf2m> const& square_root_matrix,
00090                           std::vector<gf2m> const& inverse_support,
00091                           std::vector<byte> const& public_matrix );
00092 
00093       McEliece_PrivateKey(RandomNumberGenerator& rng, size_t code_length, size_t t);
00094       bool check_key(RandomNumberGenerator& rng, bool strong) const;
00095 
00096       polyn_gf2m const& get_goppa_polyn() const { return m_g; };
00097       std::vector<u32bit> const& get_H_coeffs() const { return m_coeffs; };
00098       std::vector<gf2m> const& get_Linv() const { return m_Linv; };
00099       std::vector<polyn_gf2m> const& get_sqrtmod() const { return m_sqrtmod; };
00100 
00101       inline u32bit get_dimension() const
00102          { return m_dimension; };
00103 
00104       inline u32bit get_codimension() const
00105          { return m_codimension; };
00106 
00107 
00108       secure_vector<byte> pkcs8_private_key() const;
00109 
00110       bool operator==(const McEliece_PrivateKey & other) const;
00111 
00112       bool operator!=(const McEliece_PrivateKey& other) const { return !(*this == other); };
00113 
00114    private:
00115       polyn_gf2m m_g;
00116       std::vector<polyn_gf2m> m_sqrtmod;
00117       std::vector<gf2m> m_Linv;
00118       std::vector<u32bit> m_coeffs;
00119 
00120       u32bit m_codimension;
00121       u32bit m_dimension;
00122    };
00123 
00124 }
00125 
00126 #endif