Botan: Botan::OpenPGP_S2K Class Reference

Botan 1.10.16

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

`#include <pgp_s2k.h>`

Inheritance diagram for Botan::OpenPGP_S2K:

## 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
| OpenPGP_S2K (HashFunction *hash_in)
| ~OpenPGP_S2K ()

## Detailed Description

OpenPGP's S2K

Definition at line 19 of file pgp_s2k.h.

## Constructor & Destructor Documentation

## ◆ OpenPGP_S2K()

Botan::OpenPGP_S2K::OpenPGP_S2K | ( | HashFunction * | hash_in | ) |
| inline

Parameters

  hash_in | the hash function to use

Definition at line 25 of file pgp_s2k.h.

25 : hash(hash_in) {}

## ◆ ~OpenPGP_S2K()

Botan::OpenPGP_S2K::~OpenPGP_S2K | ( |  | ) |
| inline

Definition at line 27 of file pgp_s2k.h.

27 { 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::OpenPGP_S2K::clone | ( |  | ) | const
| inlinevirtual

Returns
  new instance of this same algorithm

Implements Botan::PBKDF.

Definition at line 34 of file pgp_s2k.h.

35 {
36 return new OpenPGP_S2K(hash->clone());
37 }
Botan::OpenPGP_S2K::OpenPGP_S2K
OpenPGP_S2K(HashFunction *hash_in)
Definition: pgp_s2k.h:25
Botan::HashFunction::clone
virtual HashFunction * clone() const =0

## ◆ derive_key()

OctetString Botan::OpenPGP_S2K::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 15 of file pgp_s2k.cpp.

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

19 {
20 SecureVector<byte> key(key_len), hash_buf;
21
22 size_t pass = 0, generated = 0,
23 total_size = passphrase.size() + salt_size;
24 size_t to_hash = std::max(iterations, total_size);
25
26 hash->clear();
27 while(key_len > generated)
28 {
29 for(size_t j = 0; j != pass; ++j)
30 hash->update(0);
31
32 size_t left = to_hash;
33 while(left >= total_size)
34 {
35 hash->update(salt_buf, salt_size);
36 hash->update(passphrase);
37 left -= total_size;
38 }
39 if(left <= salt_size)
40 hash->update(salt_buf, left);
41 else
42 {
43 hash->update(salt_buf, salt_size);
44 left -= salt_size;
45 hash->update(reinterpret_cast<const byte*>(passphrase.data()), left);
46 }
47
48 hash_buf = hash->final();
49 key.copy(generated, &hash_buf[0], hash->output_length());
50 generated += hash->output_length();
51 ++pass;
52 }
53
54 return key;
55 }
Botan::Algorithm::clear
virtual void clear()=0
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::max
T max(T a, T b)
Definition: ct_utils.h:120
Botan::Buffered_Computation::output_length
virtual size_t output_length() const =0

## ◆ name()

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

Returns
  name of this algorithm

Implements Botan::Algorithm.

Definition at line 29 of file pgp_s2k.h.

30 {
31 return "OpenPGP-S2K(" + hash->name() + ")";
32 }
Botan::Algorithm::name
virtual std::string name() const =0

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

- src/pbkdf/pgps2k/pgp_s2k.h
- src/pbkdf/pgps2k/pgp_s2k.cpp