Botan 1.10.17
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
11namespace Botan {
12
13/*
14* Return a PKCS#5 PBKDF1 derived key
15*/
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}
size_t size() const
Definition secmem.h:29
OctetString(class RandomNumberGenerator &rng, size_t len)
Definition symkey.cpp:20
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
std::invalid_argument Invalid_Argument
Definition exceptn.h:20