8#include <botan/pbes1.h>
9#include <botan/pbkdf1.h>
10#include <botan/der_enc.h>
11#include <botan/ber_dec.h>
22 pipe.write(input, length);
41 if(pipe.message_count() > 1)
42 pipe.set_default_msg(pipe.default_msg() + 1);
58void PBE_PKCS5v15::flush_pipe(
bool safe_to_skip)
66 size_t got = pipe.
read(&buffer[0], buffer.size());
74void PBE_PKCS5v15::set_key(
const std::string& passphrase)
76 PKCS5_PBKDF1 pbkdf(hash_function->clone());
78 SecureVector<byte> key_and_iv = pbkdf.derive_key(16, passphrase,
79 &salt[0], salt.size(),
80 iterations).bits_of();
84 copy_mem(&key[0], &key_and_iv[0], 8);
94 salt = rng.random_vec(8);
113void PBE_PKCS5v15::decode_params(
DataSource& source)
131 const OID base_pbes1_oid(
"1.2.840.113549.1.5");
133 const std::string cipher = block_cipher->name();
134 const std::string digest = hash_function->name();
136 if(cipher ==
"DES" && digest ==
"MD2")
137 return (base_pbes1_oid + 1);
138 else if(cipher ==
"DES" && digest ==
"MD5")
139 return (base_pbes1_oid + 3);
140 else if(cipher ==
"DES" && digest ==
"SHA-160")
141 return (base_pbes1_oid + 10);
142 else if(cipher ==
"RC2" && digest ==
"MD2")
143 return (base_pbes1_oid + 4);
144 else if(cipher ==
"RC2" && digest ==
"MD5")
145 return (base_pbes1_oid + 6);
146 else if(cipher ==
"RC2" && digest ==
"SHA-160")
147 return (base_pbes1_oid + 11);
149 throw Internal_Error(
"PBE-PKCS5 v1.5: get_oid() has run out of options");
154 return "PBE-PKCS5v15(" + block_cipher->name() +
"," +
155 hash_function->name() +
")";
164 direction(dir), block_cipher(cipher), hash_function(hash), iterations(0)
166 if(cipher->
name() !=
"DES" && cipher->
name() !=
"RC2")
168 throw Invalid_Argument(
"PBE_PKCS5v1.5: Unknown cipher " +
172 if(hash->
name() !=
"MD2" && hash->
name() !=
"MD5" &&
173 hash->
name() !=
"SHA-160")
175 throw Invalid_Argument(
"PBE_PKCS5v1.5: Unknown hash " +
183 delete hash_function;
virtual std::string name() const =0
BER_Decoder(DataSource &)
CBC_Decryption(BlockCipher *cipher, BlockCipherModePaddingMethod *padding)
CBC_Encryption(BlockCipher *cipher, BlockCipherModePaddingMethod *padding)
void send(const byte in[], size_t length)
void write(const byte[], size_t)
PBE_PKCS5v15(BlockCipher *cipher, HashFunction *hash, Cipher_Dir direction)
virtual OID get_oid() const =0
virtual MemoryVector< byte > encode_params() const =0
size_t remaining(message_id msg=DEFAULT_MESSAGE) const
size_t read(byte output[], size_t length)
void copy_mem(T *out, const T *in, size_t n)
Decoding_Error(const std::string &name)
Internal_Error(const std::string &err)