8 #include <botan/pbes1.h>
9 #include <botan/pbkdf1.h>
10 #include <botan/der_enc.h>
11 #include <botan/ber_dec.h>
12 #include <botan/cbc.h>
22 pipe.
write(input, length);
58 void PBE_PKCS5v15::flush_pipe(
bool safe_to_skip)
66 size_t got = pipe.
read(&buffer[0], buffer.size());
74 void 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);
91 void PBE_PKCS5v15::new_params(RandomNumberGenerator&
rng)
94 salt = rng.random_vec(8);
100 MemoryVector<byte> PBE_PKCS5v15::encode_params()
const
113 void PBE_PKCS5v15::decode_params(DataSource& source)
123 throw Decoding_Error(
"PBES1: Encoded salt is not 8 octets");
129 OID PBE_PKCS5v15::get_oid()
const
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")
172 if(hash->
name() !=
"MD2" && hash->
name() !=
"MD5" &&
173 hash->
name() !=
"SHA-160")
183 delete hash_function;
void append(Filter *filt)
size_t read(byte output[], size_t length)
void write(const byte in[], size_t length)
virtual BlockCipher * clone() const =0
std::invalid_argument Invalid_Argument
virtual HashFunction * clone() const =0
size_t remaining(message_id msg=DEFAULT_MESSAGE) const
void send(const byte in[], size_t length)
RandomNumberGenerator * rng
void copy_mem(T *out, const T *in, size_t n)
void write(const byte[], size_t)
virtual std::string name() const =0
PBE_PKCS5v15(BlockCipher *cipher, HashFunction *hash, Cipher_Dir direction)
size_t default_msg() const
void set_default_msg(message_id msg)
message_id message_count() const