Botan: Botan::KDF2 Class Reference

Botan 1.10.17

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

`#include <kdf2.h>`

Inheritance diagram for Botan::KDF2:

## Public Member Functions
void | clear ()
KDF * | clone () const
SecureVector< byte > | derive (size_t, const byte[], size_t, const byte[], size_t) const
SecureVector< byte > | derive_key (size_t key_len, const MemoryRegion< byte > &secret, const std::string &salt="") const
SecureVector< byte > | derive_key (size_t key_len, const MemoryRegion< byte > &secret, const MemoryRegion< byte > &salt) const
SecureVector< byte > | derive_key (size_t key_len, const MemoryRegion< byte > &secret, const byte salt[], size_t salt_len) const
SecureVector< byte > | derive_key (size_t key_len, const byte secret[], size_t secret_len, const std::string &salt="") const
SecureVector< byte > | derive_key (size_t key_len, const byte secret[], size_t secret_len, const byte salt[], size_t salt_len) const
| KDF2 (HashFunction *h)
| KDF2 (const KDF2 &other)
std::string | name () const
| ~KDF2 ()

## Detailed Description

KDF2, from IEEE 1363

Definition at line 19 of file kdf2.h.

## Constructor & Destructor Documentation

## ◆ KDF2() [1/2]

Botan::KDF2::KDF2 | ( | HashFunction * | h | ) |
| inline

Definition at line 28 of file kdf2.h.

28 : hash(h) {}

## ◆ KDF2() [2/2]

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

Definition at line 29 of file kdf2.h.

29 : KDF(), hash(other.hash->clone()) {}

## ◆ ~KDF2()

Botan::KDF2::~KDF2 | ( |  | ) |
| inline

Definition at line 30 of file kdf2.h.

30 { delete hash; }

## Member Function Documentation

## ◆ clear()

void Botan::KDF::clear | ( |  | ) |
| inlinevirtualinherited

Zeroize internal state

Implements Botan::Algorithm.

Definition at line 81 of file kdf.h.

81 {}

## ◆ clone()

KDF* Botan::KDF2::clone | ( |  | ) | const
| inlinevirtual

Implements Botan::KDF.

Definition at line 26 of file kdf2.h.

26 { return new KDF2(hash->clone()); }
Botan::HashFunction::clone
virtual HashFunction * clone() const =0
Botan::KDF2::KDF2
KDF2(HashFunction *h)
Definition: kdf2.h:28

## ◆ derive()

SecureVector< byte > Botan::KDF2::derive | ( | size_t | out_len,
|  | const byte | secret[],
|  | size_t | secret_len,
|  | const byte | P[],
|  | size_t | P_len
| ) |  | const
| virtual

Implements Botan::KDF.

Definition at line 15 of file kdf2.cpp.

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

18 {
19 SecureVector<byte> output;
20 u32bit counter = 1;
21
22 while(out_len && counter)
23 {
24 hash->update(secret, secret_len);
25 hash->update_be(counter);
26 hash->update(P, P_len);
27
28 SecureVector<byte> hash_result = hash->final();
29
30 size_t added = std::min(hash_result.size(), out_len);
31 output += std::make_pair(&hash_result[0], added);
32 out_len -= added;
33
34 ++counter;
35 }
36
37 return output;
38 }
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::CT::min
T min(T a, T b)
Definition: ct_utils.h:127
Botan::Buffered_Computation::update_be
void update_be(const T in)
Definition: buf_comp.h:48
Botan::u32bit
unsigned int u32bit
Definition: types.h:32

## ◆ derive_key() [1/5]

SecureVector< byte > Botan::KDF::derive_key | ( | size_t | key_len,
|  | const MemoryRegion< byte > & | secret,
|  | const std::string & | salt = `""`
| ) |  | const
| inherited

Derive a key

Parameters

  key_len | the desired output length in bytes
  secret | the secret input
  salt | a diversifier

Definition at line 15 of file kdf.cpp.

References Botan::MemoryRegion< T >::size().

Referenced by Botan::KDF::derive_key(), and Botan::PK_Key_Agreement::derive_key().

18 {
19 return derive_key(key_len, &secret[0], secret.size(),
20 reinterpret_cast<const byte*>(salt.data()),
21 salt.length());
22 }
Botan::KDF::derive_key
SecureVector< byte > derive_key(size_t key_len, const MemoryRegion< byte > &secret, const std::string &salt="") const
Definition: kdf.cpp:15
Botan::byte
unsigned char byte
Definition: types.h:22
Botan::MemoryRegion::size
size_t size() const
Definition: secmem.h:29

## ◆ derive_key() [2/5]

SecureVector< byte > Botan::KDF::derive_key | ( | size_t | key_len,
|  | const MemoryRegion< byte > & | secret,
|  | const MemoryRegion< byte > & | salt
| ) |  | const
| inherited

Derive a key

Parameters

  key_len | the desired output length in bytes
  secret | the secret input
  salt | a diversifier

Definition at line 38 of file kdf.cpp.

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

41 {
42 return derive_key(key_len, &secret[0], secret.size(),
43 &salt[0], salt.size());
44 }
Botan::KDF::derive_key
SecureVector< byte > derive_key(size_t key_len, const MemoryRegion< byte > &secret, const std::string &salt="") const
Definition: kdf.cpp:15
Botan::MemoryRegion::size
size_t size() const
Definition: secmem.h:29

## ◆ derive_key() [3/5]

SecureVector< byte > Botan::KDF::derive_key | ( | size_t | key_len,
|  | const MemoryRegion< byte > & | secret,
|  | const byte | salt[],
|  | size_t | salt_len
| ) |  | const
| inherited

Derive a key

Parameters

  key_len | the desired output length in bytes
  secret | the secret input
  salt | a diversifier
  salt_len | size of salt in bytes

Definition at line 27 of file kdf.cpp.

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

30 {
31 return derive_key(key_len, &secret[0], secret.size(),
32 salt, salt_len);
33 }
Botan::KDF::derive_key
SecureVector< byte > derive_key(size_t key_len, const MemoryRegion< byte > &secret, const std::string &salt="") const
Definition: kdf.cpp:15
Botan::MemoryRegion::size
size_t size() const
Definition: secmem.h:29

## ◆ derive_key() [4/5]

SecureVector< byte > Botan::KDF::derive_key | ( | size_t | key_len,
|  | const byte | secret[],
|  | size_t | secret_len,
|  | const std::string & | salt = `""`
| ) |  | const
| inherited

Derive a key

Parameters

  key_len | the desired output length in bytes
  secret | the secret input
  secret_len | size of secret in bytes
  salt | a diversifier

Definition at line 49 of file kdf.cpp.

References Botan::KDF::derive_key().

52 {
53 return derive_key(key_len, secret, secret_len,
54 reinterpret_cast<const byte*>(salt.data()),
55 salt.length());
56 }
Botan::KDF::derive_key
SecureVector< byte > derive_key(size_t key_len, const MemoryRegion< byte > &secret, const std::string &salt="") const
Definition: kdf.cpp:15

## ◆ derive_key() [5/5]

SecureVector< byte > Botan::KDF::derive_key | ( | size_t | key_len,
|  | const byte | secret[],
|  | size_t | secret_len,
|  | const byte | salt[],
|  | size_t | salt_len
| ) |  | const
| inherited

Derive a key

Parameters

  key_len | the desired output length in bytes
  secret | the secret input
  secret_len | size of secret in bytes
  salt | a diversifier
  salt_len | size of salt in bytes

Definition at line 61 of file kdf.cpp.

64 {
65 return derive(key_len, secret, secret_len, salt, salt_len);
66 }

## ◆ name()

std::string Botan::KDF2::name | ( |  | ) | const
| inlinevirtual

Returns
  name of this algorithm

Implements Botan::Algorithm.

Definition at line 25 of file kdf2.h.

25 { return "KDF2(" + hash->name() + ")"; }
Botan::Algorithm::name
virtual std::string name() const =0

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

- src/kdf/kdf2/kdf2.h
- src/kdf/kdf2/kdf2.cpp