Botan 1.10.17
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 (const PKCS5_PBKDF1 &other)
 PKCS5_PBKDF1 (HashFunction *hash_in)
 ~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

◆ PKCS5_PBKDF1() [1/2]

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) {}

Referenced by clone(), Botan::Core_Engine::find_pbkdf(), and PKCS5_PBKDF1().

◆ PKCS5_PBKDF1() [2/2]

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()) {}

References clone(), and PKCS5_PBKDF1().

◆ ~PKCS5_PBKDF1()

Botan::PKCS5_PBKDF1::~PKCS5_PBKDF1 ( )
inline

Definition at line 37 of file pbkdf1.h.

37{ delete hash; }

Member Function Documentation

◆ clear()

void Botan::PBKDF::clear ( )
inlinevirtualinherited

Zeroize internal state

Implements Botan::Algorithm.

Definition at line 30 of file pbkdf.h.

30{}

◆ clone()

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 }
PKCS5_PBKDF1(HashFunction *hash_in)
Definition pbkdf1.h:28

References PKCS5_PBKDF1().

Referenced by PKCS5_PBKDF1().

◆ derive_key()

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.

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 }
OctetString(class RandomNumberGenerator &rng, size_t len)
Definition symkey.cpp:20
std::invalid_argument Invalid_Argument
Definition exceptn.h:20

References Botan::OctetString::OctetString(), and Botan::MemoryRegion< T >::size().

◆ name()

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 }

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