Botan: src/pbkdf/pbkdf1/pbkdf1.cpp Source File

Botan 1.10.12

- Main Page
- Related Pages
- Namespaces
- Classes
- Files

- File List
- File Members

pbkdf1.cpp
Go to the documentation of this file.
1 /*
2 * PBKDF1
3 * (C) 1999-2007 Jack Lloyd
4 *
5 * Distributed under the terms of the Botan license
6 */
7
8 #include <botan/pbkdf1.h>
9 #include <botan/exceptn.h>
10
11 namespace Botan {
12
13 /*
14 * Return a PKCS#5 PBKDF1 derived key
15 */
16 OctetString PKCS5_PBKDF1::derive_key(size_t key_len,
17 const std::string& passphrase,
18 const byte salt[], size_t salt_size,
19 size_t iterations) const
20 {
21 if(iterations == 0)
22 throw Invalid_Argument("PKCS5_PBKDF1: Invalid iteration count");
23
24 if(key_len > hash->output_length())
25 throw Invalid_Argument("PKCS5_PBKDF1: Requested output length too long");
26
27 hash->update(passphrase);
28 hash->update(salt, salt_size);
29 SecureVector<byte> key = hash->final();
30
31 for(size_t j = 1; j != iterations; ++j)
32 {
33 hash->update(key);
34 hash->final(&key[0]);
35 }
36
37 return OctetString(&key[0], std::min<size_t>(key_len, key.size()));
38 }
39
40 }
Botan::OctetString
Definition: symkey.h:19
Botan::PKCS5_PBKDF1::derive_key
OctetString derive_key(size_t output_len, const std::string &passphrase, const byte salt[], size_t salt_len, size_t iterations) const
Definition: pbkdf1.cpp:16
Botan::Invalid_Argument
std::invalid_argument Invalid_Argument
Definition: exceptn.h:20
Botan::Buffered_Computation::output_length
virtual size_t output_length() const =0
Botan::byte
unsigned char byte
Definition: types.h:22
Botan::Buffered_Computation::update
void update(const byte in[], size_t length)
Definition: buf_comp.h:33
Botan::MemoryRegion::size
size_t size() const
Definition: secmem.h:29
Botan
Definition: algo_base.h:14
Botan::Buffered_Computation::final
void final(byte out[])
Definition: buf_comp.h:80
Botan::SecureVector< byte >