Botan: Botan::PKCS5_PBKDF1 Class Reference

Botan 1.10.16

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

`#include <pbkdf1.h>`

Inheritance diagram for Botan::PKCS5_PBKDF1:

## Public Member Functions
void | clear ()
PBKDF * | clone () 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

## ◆ 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_in | pointer to a hash function object to use

Definition at line 28 of file pbkdf1.h.

28 : hash(hash_in) {}

## ◆ PKCS5_PBKDF1() [2/2]

Botan::PKCS5_PBKDF1::PKCS5_PBKDF1 | ( | const PKCS5_PBKDF1 & | other | ) |
| inline

Copy constructor

Parameters

  other | the object to copy

Definition at line 34 of file pbkdf1.h.

34 :
35 PBKDF(), hash(other.hash->clone()) {}

## ◆ ~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 }
Botan::HashFunction::clone
virtual HashFunction * clone() const =0
Botan::PKCS5_PBKDF1::PKCS5_PBKDF1
PKCS5_PBKDF1(HashFunction *hash_in)
Definition: pbkdf1.h:28

## ◆ 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_len | the desired length of the key to produce
  passphrase | the password to derive the key from
  salt | a randomly chosen salt
  salt_len | length of salt in bytes
  iterations | the 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 }
Botan::Invalid_Argument
std::invalid_argument Invalid_Argument
Definition: exceptn.h:20
Botan::Buffered_Computation::update
void update(const byte in[], size_t length)
Definition: buf_comp.h:33
Botan::Buffered_Computation::final
void final(byte out[])
Definition: buf_comp.h:80
Botan::Buffered_Computation::output_length
virtual size_t output_length() const =0

## ◆ 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 }
Botan::Algorithm::name
virtual std::string name() const =0

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

- src/pbkdf/pbkdf1/pbkdf1.h
- src/pbkdf/pbkdf1/pbkdf1.cpp