Botan  1.10.9
Public Member Functions | List of all members
Botan::PKCS5_PBKDF1 Class Reference

#include <pbkdf1.h>

Inheritance diagram for Botan::PKCS5_PBKDF1:
Botan::PBKDF Botan::Algorithm

Public Member Functions

void clear ()
 
PBKDFclone () const
 
OctetString derive_key (size_t output_len, const std::string &passphrase, const byte salt[], size_t salt_len, size_t iterations) const
 
std::string name () const
 
 PKCS5_PBKDF1 (HashFunction *hash_in)
 
 PKCS5_PBKDF1 (const PKCS5_PBKDF1 &other)
 
 ~PKCS5_PBKDF1 ()
 

Detailed Description

PKCS #5 v1 PBKDF, aka PBKDF1 Can only generate a key up to the size of the hash output. Unless needed for backwards compatability, use PKCS5_PBKDF2

Definition at line 21 of file pbkdf1.h.

Constructor & Destructor Documentation

Botan::PKCS5_PBKDF1::PKCS5_PBKDF1 ( HashFunction hash_in)
inline

Create a PKCS #5 instance using the specified hash function.

Parameters
hash_inpointer to a hash function object to use

Definition at line 28 of file pbkdf1.h.

28 : hash(hash_in) {}
Botan::PKCS5_PBKDF1::PKCS5_PBKDF1 ( const PKCS5_PBKDF1 other)
inline

Copy constructor

Parameters
otherthe object to copy

Definition at line 34 of file pbkdf1.h.

34  :
35  PBKDF(), hash(other.hash->clone()) {}
Botan::PKCS5_PBKDF1::~PKCS5_PBKDF1 ( )
inline

Definition at line 37 of file pbkdf1.h.

37 { delete hash; }

Member Function Documentation

void Botan::PBKDF::clear ( )
inlinevirtualinherited

Zeroize internal state

Implements Botan::Algorithm.

Definition at line 30 of file pbkdf.h.

30 {}
PBKDF* Botan::PKCS5_PBKDF1::clone ( ) const
inlinevirtual
Returns
new instance of this same algorithm

Implements Botan::PBKDF.

Definition at line 44 of file pbkdf1.h.

45  {
46  return new PKCS5_PBKDF1(hash->clone());
47  }
virtual HashFunction * clone() const =0
PKCS5_PBKDF1(HashFunction *hash_in)
Definition: pbkdf1.h:28
OctetString Botan::PKCS5_PBKDF1::derive_key ( size_t  output_len,
const std::string &  passphrase,
const byte  salt[],
size_t  salt_len,
size_t  iterations 
) const
virtual

Derive a key from a passphrase

Parameters
output_lenthe desired length of the key to produce
passphrasethe password to derive the key from
salta randomly chosen salt
salt_lenlength of salt in bytes
iterationsthe number of iterations to use (use 10K or more)

Implements Botan::PBKDF.

Definition at line 16 of file pbkdf1.cpp.

References Botan::Buffered_Computation::final(), Botan::Buffered_Computation::output_length(), Botan::MemoryRegion< T >::size(), and Botan::Buffered_Computation::update().

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  }
std::invalid_argument Invalid_Argument
Definition: exceptn.h:20
void update(const byte in[], size_t length)
Definition: buf_comp.h:33
void final(byte out[])
Definition: buf_comp.h:80
virtual size_t output_length() const =0
std::string Botan::PKCS5_PBKDF1::name ( ) const
inlinevirtual
Returns
name of this algorithm

Implements Botan::Algorithm.

Definition at line 39 of file pbkdf1.h.

40  {
41  return "PBKDF1(" + hash->name() + ")";
42  }
virtual std::string name() const =0

The documentation for this class was generated from the following files: