diff options
author | lloyd <[email protected]> | 2014-01-18 17:12:30 +0000 |
---|---|---|
committer | lloyd <[email protected]> | 2014-01-18 17:12:30 +0000 |
commit | 4917f26a2b154e841cd27c1bcecdd41d2bdeb6ce (patch) | |
tree | 0456ae4efcd748ececc83a35a6353373778e1291 /src/lib/pbe | |
parent | 560b7671685317035e724b4c75030dc5cf86f461 (diff) |
Remove PBES1 entirely
Diffstat (limited to 'src/lib/pbe')
-rw-r--r-- | src/lib/pbe/get_pbe.cpp | 51 | ||||
-rw-r--r-- | src/lib/pbe/pbes1/info.txt | 10 | ||||
-rw-r--r-- | src/lib/pbe/pbes1/pbes1.cpp | 193 | ||||
-rw-r--r-- | src/lib/pbe/pbes1/pbes1.h | 69 |
4 files changed, 0 insertions, 323 deletions
diff --git a/src/lib/pbe/get_pbe.cpp b/src/lib/pbe/get_pbe.cpp index 4ec518776..5cb5ccc88 100644 --- a/src/lib/pbe/get_pbe.cpp +++ b/src/lib/pbe/get_pbe.cpp @@ -11,10 +11,6 @@ #include <botan/parsing.h> #include <botan/libstate.h> -#if defined(BOTAN_HAS_PBE_PKCS_V15) - #include <botan/pbes1.h> -#endif - #if defined(BOTAN_HAS_PBE_PKCS_V20) #include <botan/pbes2.h> #include <botan/hmac.h> @@ -59,15 +55,6 @@ PBE* get_pbe(const std::string& algo_spec, if(request.arg_count() != 2) throw Invalid_Algorithm_Name(algo_spec); -#if defined(BOTAN_HAS_PBE_PKCS_V15) - if(pbe == "PBE-PKCS5v15") - return new PBE_PKCS5v15(block_cipher->clone(), - hash_function->clone(), - passphrase, - msec, - rng); -#endif - #if defined(BOTAN_HAS_PBE_PKCS_V20) if(pbe == "PBE-PKCS5v20") return new PBE_PKCS5v20(block_cipher->clone(), @@ -91,44 +78,6 @@ PBE* get_pbe(const OID& pbe_oid, const std::string pbe = request.algo_name(); -#if defined(BOTAN_HAS_PBE_PKCS_V15) - if(pbe == "PBE-PKCS5v15") - { - if(request.arg_count() != 2) - throw Invalid_Algorithm_Name(request.as_string()); - - std::string digest_name = request.arg(0); - const std::string cipher = request.arg(1); - - std::vector<std::string> cipher_spec = split_on(cipher, '/'); - if(cipher_spec.size() != 2) - throw Invalid_Argument("PBE: Invalid cipher spec " + cipher); - - const std::string cipher_algo = SCAN_Name::deref_alias(cipher_spec[0]); - const std::string cipher_mode = cipher_spec[1]; - - if(cipher_mode != "CBC") - throw Invalid_Argument("PBE: Invalid cipher mode " + cipher); - - Algorithm_Factory& af = global_state().algorithm_factory(); - - const BlockCipher* block_cipher = af.prototype_block_cipher(cipher_algo); - if(!block_cipher) - throw Algorithm_Not_Found(cipher_algo); - - const HashFunction* hash_function = - af.prototype_hash_function(digest_name); - - if(!hash_function) - throw Algorithm_Not_Found(digest_name); - - return new PBE_PKCS5v15(block_cipher->clone(), - hash_function->clone(), - params, - passphrase); - } -#endif - #if defined(BOTAN_HAS_PBE_PKCS_V20) if(pbe == "PBE-PKCS5v20") return new PBE_PKCS5v20(params, passphrase); diff --git a/src/lib/pbe/pbes1/info.txt b/src/lib/pbe/pbes1/info.txt deleted file mode 100644 index 36d26ecc9..000000000 --- a/src/lib/pbe/pbes1/info.txt +++ /dev/null @@ -1,10 +0,0 @@ -define PBE_PKCS_V15 20131128 - -<requires> -asn1 -block -cbc -filters -hash -pbkdf1 -</requires> diff --git a/src/lib/pbe/pbes1/pbes1.cpp b/src/lib/pbe/pbes1/pbes1.cpp deleted file mode 100644 index a30f10a6c..000000000 --- a/src/lib/pbe/pbes1/pbes1.cpp +++ /dev/null @@ -1,193 +0,0 @@ -/* -* PKCS #5 PBES1 -* (C) 1999-2007 Jack Lloyd -* -* Distributed under the terms of the Botan license -*/ - -#include <botan/pbes1.h> -#include <botan/pbkdf1.h> -#include <botan/der_enc.h> -#include <botan/ber_dec.h> -#include <botan/lookup.h> -#include <algorithm> - -namespace Botan { - -/* -* Encrypt some bytes using PBES1 -*/ -void PBE_PKCS5v15::write(const byte input[], size_t length) - { - m_pipe.write(input, length); - flush_pipe(true); - } - -/* -* Start encrypting with PBES1 -*/ -void PBE_PKCS5v15::start_msg() - { - m_pipe.append(get_cipher(m_block_cipher->name() + "/CBC/PKCS7", - m_key, m_iv, m_direction)); - - m_pipe.start_msg(); - if(m_pipe.message_count() > 1) - m_pipe.set_default_msg(m_pipe.default_msg() + 1); - } - -/* -* Finish encrypting with PBES1 -*/ -void PBE_PKCS5v15::end_msg() - { - m_pipe.end_msg(); - flush_pipe(false); - m_pipe.reset(); - } - -/* -* Flush the pipe -*/ -void PBE_PKCS5v15::flush_pipe(bool safe_to_skip) - { - if(safe_to_skip && m_pipe.remaining() < 64) - return; - - secure_vector<byte> buffer(DEFAULT_BUFFERSIZE); - while(m_pipe.remaining()) - { - size_t got = m_pipe.read(&buffer[0], buffer.size()); - send(buffer, got); - } - } - -/* -* Encode PKCS#5 PBES1 parameters -*/ -std::vector<byte> PBE_PKCS5v15::encode_params() const - { - return DER_Encoder() - .start_cons(SEQUENCE) - .encode(m_salt, OCTET_STRING) - .encode(m_iterations) - .end_cons() - .get_contents_unlocked(); - } - -/* -* Return an OID for this PBES1 type -*/ -OID PBE_PKCS5v15::get_oid() const - { - const OID base_pbes1_oid("1.2.840.113549.1.5"); - - const std::string cipher = m_block_cipher->name(); - const std::string digest = m_hash_function->name(); - - if(cipher == "DES" && digest == "MD2") - return (base_pbes1_oid + 1); - else if(cipher == "DES" && digest == "MD5") - return (base_pbes1_oid + 3); - else if(cipher == "DES" && digest == "SHA-160") - return (base_pbes1_oid + 10); - else if(cipher == "RC2" && digest == "MD2") - return (base_pbes1_oid + 4); - else if(cipher == "RC2" && digest == "MD5") - return (base_pbes1_oid + 6); - else if(cipher == "RC2" && digest == "SHA-160") - return (base_pbes1_oid + 11); - else - throw Internal_Error("PBE-PKCS5 v1.5: get_oid() has run out of options"); - } - -std::string PBE_PKCS5v15::name() const - { - return "PBE-PKCS5v15(" + m_block_cipher->name() + "," + - m_hash_function->name() + ")"; - } - -PBE_PKCS5v15::PBE_PKCS5v15(BlockCipher* cipher, - HashFunction* hash, - const std::string& passphrase, - std::chrono::milliseconds msec, - RandomNumberGenerator& rng) : - m_direction(ENCRYPTION), - m_block_cipher(cipher), - m_hash_function(hash), - m_salt(rng.random_vec(8)) - { - if(cipher->name() != "DES" && cipher->name() != "RC2") - { - throw Invalid_Argument("PBE_PKCS5v1.5: Unknown cipher " + - cipher->name()); - } - - if(hash->name() != "MD2" && hash->name() != "MD5" && - hash->name() != "SHA-160") - { - throw Invalid_Argument("PBE_PKCS5v1.5: Unknown hash " + - hash->name()); - } - - PKCS5_PBKDF1 pbkdf(m_hash_function->clone()); - - secure_vector<byte> key_and_iv = - pbkdf.derive_key(16, passphrase, - &m_salt[0], m_salt.size(), - msec, m_iterations).bits_of(); - - m_key.assign(&key_and_iv[0], &key_and_iv[8]); - m_iv.assign(&key_and_iv[8], &key_and_iv[16]); - - } - -PBE_PKCS5v15::PBE_PKCS5v15(BlockCipher* cipher, - HashFunction* hash, - const std::vector<byte>& params, - const std::string& passphrase) : - m_direction(DECRYPTION), - m_block_cipher(cipher), - m_hash_function(hash) - { - if(cipher->name() != "DES" && cipher->name() != "RC2") - { - throw Invalid_Argument("PBE_PKCS5v1.5: Unknown cipher " + - cipher->name()); - } - - if(hash->name() != "MD2" && hash->name() != "MD5" && - hash->name() != "SHA-160") - { - throw Invalid_Argument("PBE_PKCS5v1.5: Unknown hash " + - hash->name()); - } - - BER_Decoder(params) - .start_cons(SEQUENCE) - .decode(m_salt, OCTET_STRING) - .decode(m_iterations) - .verify_end() - .end_cons(); - - if(m_salt.size() != 8) - throw Decoding_Error("PBES1: Encoded salt is not 8 octets"); - - PKCS5_PBKDF1 pbkdf(m_hash_function->clone()); - - secure_vector<byte> key_and_iv = - pbkdf.derive_key(16, passphrase, - &m_salt[0], m_salt.size(), - m_iterations).bits_of(); - - m_key.assign(&key_and_iv[0], &key_and_iv[8]); - m_iv.assign(&key_and_iv[8], &key_and_iv[16]); - } - -PBE_PKCS5v15::~PBE_PKCS5v15() - { - delete m_block_cipher; - delete m_hash_function; - } - -} diff --git a/src/lib/pbe/pbes1/pbes1.h b/src/lib/pbe/pbes1/pbes1.h deleted file mode 100644 index 8d1a6f877..000000000 --- a/src/lib/pbe/pbes1/pbes1.h +++ /dev/null @@ -1,69 +0,0 @@ -/* -* PKCS #5 v1.5 PBE -* (C) 1999-2007 Jack Lloyd -* -* Distributed under the terms of the Botan license -*/ - -#ifndef BOTAN_PBE_PKCS_V15_H__ -#define BOTAN_PBE_PKCS_V15_H__ - -#include <botan/pbe.h> -#include <botan/block_cipher.h> -#include <botan/hash.h> -#include <botan/pipe.h> -#include <chrono> - -namespace Botan { - -/** -* PKCS #5 v1.5 PBE -*/ -class BOTAN_DLL PBE_PKCS5v15 : public PBE - { - public: - OID get_oid() const; - - std::vector<byte> encode_params() const; - - std::string name() const; - - void write(const byte[], size_t); - void start_msg(); - void end_msg(); - - /** - * @param cipher the block cipher to use (DES or RC2) - * @param hash the hash function to use - * @param passphrase the passphrase to use - * @param msec how many milliseconds to run the PBKDF - * @param rng a random number generator - */ - PBE_PKCS5v15(BlockCipher* cipher, - HashFunction* hash, - const std::string& passphrase, - std::chrono::milliseconds msec, - RandomNumberGenerator& rng); - - PBE_PKCS5v15(BlockCipher* cipher, - HashFunction* hash, - const std::vector<byte>& params, - const std::string& passphrase); - - ~PBE_PKCS5v15(); - private: - - void flush_pipe(bool); - - Cipher_Dir m_direction; - BlockCipher* m_block_cipher; - HashFunction* m_hash_function; - - secure_vector<byte> m_salt, m_key, m_iv; - size_t m_iterations; - Pipe m_pipe; - }; - -} - -#endif |