diff options
Diffstat (limited to 'src/lib/pubkey/mce/mceliece_key.cpp')
-rw-r--r-- | src/lib/pubkey/mce/mceliece_key.cpp | 82 |
1 files changed, 41 insertions, 41 deletions
diff --git a/src/lib/pubkey/mce/mceliece_key.cpp b/src/lib/pubkey/mce/mceliece_key.cpp index 409688153..798f7a91f 100644 --- a/src/lib/pubkey/mce/mceliece_key.cpp +++ b/src/lib/pubkey/mce/mceliece_key.cpp @@ -21,10 +21,10 @@ namespace Botan { McEliece_PrivateKey::McEliece_PrivateKey(polyn_gf2m const& goppa_polyn, - std::vector<u32bit> const& parity_check_matrix_coeffs, + std::vector<uint32_t> const& parity_check_matrix_coeffs, std::vector<polyn_gf2m> const& square_root_matrix, std::vector<gf2m> const& inverse_support, - std::vector<byte> const& public_matrix) : + std::vector<uint8_t> const& public_matrix) : McEliece_PublicKey(public_matrix, goppa_polyn.get_degree(), inverse_support.size()), m_g(goppa_polyn), m_sqrtmod(square_root_matrix), @@ -37,27 +37,27 @@ McEliece_PrivateKey::McEliece_PrivateKey(polyn_gf2m const& goppa_polyn, McEliece_PrivateKey::McEliece_PrivateKey(RandomNumberGenerator& rng, size_t code_length, size_t t) { - u32bit ext_deg = ceil_log2(code_length); + uint32_t ext_deg = ceil_log2(code_length); *this = generate_mceliece_key(rng, ext_deg, code_length, t); } -u32bit McEliece_PublicKey::get_message_word_bit_length() const +uint32_t McEliece_PublicKey::get_message_word_bit_length() const { - u32bit codimension = ceil_log2(m_code_length) * m_t; + uint32_t codimension = ceil_log2(m_code_length) * m_t; return m_code_length - codimension; } -secure_vector<byte> McEliece_PublicKey::random_plaintext_element(RandomNumberGenerator& rng) const +secure_vector<uint8_t> McEliece_PublicKey::random_plaintext_element(RandomNumberGenerator& rng) const { const size_t bits = get_message_word_bit_length(); - secure_vector<byte> plaintext((bits+7)/8); + secure_vector<uint8_t> plaintext((bits+7)/8); rng.randomize(plaintext.data(), plaintext.size()); // unset unused bits in the last plaintext byte - if(u32bit used = bits % 8) + if(uint32_t used = bits % 8) { - const byte mask = (1 << used) - 1; + const uint8_t mask = (1 << used) - 1; plaintext[plaintext.size() - 1] &= mask; } @@ -66,10 +66,10 @@ secure_vector<byte> McEliece_PublicKey::random_plaintext_element(RandomNumberGen AlgorithmIdentifier McEliece_PublicKey::algorithm_identifier() const { - return AlgorithmIdentifier(get_oid(), std::vector<byte>()); + return AlgorithmIdentifier(get_oid(), std::vector<uint8_t>()); } -std::vector<byte> McEliece_PublicKey::public_key_bits() const +std::vector<uint8_t> McEliece_PublicKey::public_key_bits() const { return DER_Encoder() .start_cons(SEQUENCE) @@ -99,7 +99,7 @@ size_t McEliece_PublicKey::estimated_strength() const return mceliece_work_factor(m_code_length, m_t); } -McEliece_PublicKey::McEliece_PublicKey(const std::vector<byte>& key_bits) +McEliece_PublicKey::McEliece_PublicKey(const std::vector<uint8_t>& key_bits) { BER_Decoder dec(key_bits); size_t n; @@ -115,7 +115,7 @@ McEliece_PublicKey::McEliece_PublicKey(const std::vector<byte>& key_bits) m_code_length = n; } -secure_vector<byte> McEliece_PrivateKey::private_key_bits() const +secure_vector<uint8_t> McEliece_PrivateKey::private_key_bits() const { DER_Encoder enc; enc.start_cons(SEQUENCE) @@ -126,20 +126,20 @@ secure_vector<byte> McEliece_PrivateKey::private_key_bits() const .encode(m_public_matrix, OCTET_STRING) .encode(m_g.encode(), OCTET_STRING); // g as octet string enc.start_cons(SEQUENCE); - for(u32bit i = 0; i < m_sqrtmod.size(); i++) + for(uint32_t i = 0; i < m_sqrtmod.size(); i++) { enc.encode(m_sqrtmod[i].encode(), OCTET_STRING); } enc.end_cons(); - secure_vector<byte> enc_support; - for(u32bit i = 0; i < m_Linv.size(); i++) + secure_vector<uint8_t> enc_support; + for(uint32_t i = 0; i < m_Linv.size(); i++) { enc_support.push_back(m_Linv[i] >> 8); enc_support.push_back(m_Linv[i]); } enc.encode(enc_support, OCTET_STRING); - secure_vector<byte> enc_H; - for(u32bit i = 0; i < m_coeffs.size(); i++) + secure_vector<uint8_t> enc_H; + for(uint32_t i = 0; i < m_coeffs.size(); i++) { enc_H.push_back(m_coeffs[i] >> 24); enc_H.push_back(m_coeffs[i] >> 16); @@ -153,14 +153,14 @@ secure_vector<byte> McEliece_PrivateKey::private_key_bits() const bool McEliece_PrivateKey::check_key(RandomNumberGenerator& rng, bool) const { - const secure_vector<byte> plaintext = this->random_plaintext_element(rng); + const secure_vector<uint8_t> plaintext = this->random_plaintext_element(rng); - secure_vector<byte> ciphertext; - secure_vector<byte> errors; + secure_vector<uint8_t> ciphertext; + secure_vector<uint8_t> errors; mceliece_encrypt(ciphertext, errors, plaintext, *this, rng); - secure_vector<byte> plaintext_out; - secure_vector<byte> errors_out; + secure_vector<uint8_t> plaintext_out; + secure_vector<uint8_t> errors_out; mceliece_decrypt(plaintext_out, errors_out, ciphertext, *this); if(errors != errors_out || plaintext != plaintext_out) @@ -169,10 +169,10 @@ bool McEliece_PrivateKey::check_key(RandomNumberGenerator& rng, bool) const return true; } -McEliece_PrivateKey::McEliece_PrivateKey(const secure_vector<byte>& key_bits) +McEliece_PrivateKey::McEliece_PrivateKey(const secure_vector<uint8_t>& key_bits) { size_t n, t; - secure_vector<byte> g_enc; + secure_vector<uint8_t> g_enc; BER_Decoder dec_base(key_bits); BER_Decoder dec = dec_base.start_cons(SEQUENCE) .start_cons(SEQUENCE) @@ -185,7 +185,7 @@ McEliece_PrivateKey::McEliece_PrivateKey(const secure_vector<byte>& key_bits) if(t == 0 || n == 0) throw Decoding_Error("invalid McEliece parameters"); - u32bit ext_deg = ceil_log2(n); + uint32_t ext_deg = ceil_log2(n); m_code_length = n; m_t = t; m_codimension = (ext_deg * t); @@ -198,9 +198,9 @@ McEliece_PrivateKey::McEliece_PrivateKey(const secure_vector<byte>& key_bits) throw Decoding_Error("degree of decoded Goppa polynomial is incorrect"); } BER_Decoder dec2 = dec.start_cons(SEQUENCE); - for(u32bit i = 0; i < t/2; i++) + for(uint32_t i = 0; i < t/2; i++) { - secure_vector<byte> sqrt_enc; + secure_vector<uint8_t> sqrt_enc; dec2.decode(sqrt_enc, OCTET_STRING); while(sqrt_enc.size() < (t*2)) { @@ -214,7 +214,7 @@ McEliece_PrivateKey::McEliece_PrivateKey(const secure_vector<byte>& key_bits) } m_sqrtmod.push_back(polyn_gf2m(sqrt_enc, sp_field)); } - secure_vector<byte> enc_support; + secure_vector<uint8_t> enc_support; BER_Decoder dec3 = dec2.end_cons() .decode(enc_support, OCTET_STRING); if(enc_support.size() % 2) @@ -225,12 +225,12 @@ McEliece_PrivateKey::McEliece_PrivateKey(const secure_vector<byte>& key_bits) { throw Decoding_Error("encoded support has length different from code length"); } - for(u32bit i = 0; i < n*2; i+=2) + for(uint32_t i = 0; i < n*2; i+=2) { gf2m el = (enc_support[i] << 8) | enc_support[i+1]; m_Linv.push_back(el); } - secure_vector<byte> enc_H; + secure_vector<uint8_t> enc_H; dec3.decode(enc_H, OCTET_STRING) .end_cons(); if(enc_H.size() % 4) @@ -242,9 +242,9 @@ McEliece_PrivateKey::McEliece_PrivateKey(const secure_vector<byte>& key_bits) throw Decoding_Error("encoded parity check matrix has wrong length"); } - for(u32bit i = 0; i < enc_H.size(); i+=4) + for(uint32_t i = 0; i < enc_H.size(); i+=4) { - u32bit coeff = (enc_H[i] << 24) | (enc_H[i+1] << 16) | (enc_H[i+2] << 8) | enc_H[i+3]; + uint32_t coeff = (enc_H[i] << 24) | (enc_H[i+1] << 16) | (enc_H[i+2] << 8) | enc_H[i+3]; m_coeffs.push_back(coeff); } @@ -310,13 +310,13 @@ class MCE_KEM_Encryptor : public PK_Ops::KEM_Encryption_with_KDF KEM_Encryption_with_KDF(kdf), m_key(key) {} private: - void raw_kem_encrypt(secure_vector<byte>& out_encapsulated_key, - secure_vector<byte>& raw_shared_key, + void raw_kem_encrypt(secure_vector<uint8_t>& out_encapsulated_key, + secure_vector<uint8_t>& raw_shared_key, Botan::RandomNumberGenerator& rng) override { - secure_vector<byte> plaintext = m_key.random_plaintext_element(rng); + secure_vector<uint8_t> plaintext = m_key.random_plaintext_element(rng); - secure_vector<byte> ciphertext, error_mask; + secure_vector<uint8_t> ciphertext, error_mask; mceliece_encrypt(ciphertext, error_mask, plaintext, m_key, rng); raw_shared_key.clear(); @@ -338,13 +338,13 @@ class MCE_KEM_Decryptor : public PK_Ops::KEM_Decryption_with_KDF KEM_Decryption_with_KDF(kdf), m_key(key) {} private: - secure_vector<byte> - raw_kem_decrypt(const byte encap_key[], size_t len) override + secure_vector<uint8_t> + raw_kem_decrypt(const uint8_t encap_key[], size_t len) override { - secure_vector<byte> plaintext, error_mask; + secure_vector<uint8_t> plaintext, error_mask; mceliece_decrypt(plaintext, error_mask, encap_key, len, m_key); - secure_vector<byte> output; + secure_vector<uint8_t> output; output.reserve(plaintext.size() + error_mask.size()); output.insert(output.end(), plaintext.begin(), plaintext.end()); output.insert(output.end(), error_mask.begin(), error_mask.end()); |