Botan 1.10.17

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

`#include <prf_x942.h>`

Inheritance diagram for Botan::X942_PRF:

## 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
std::string | name () const
| X942_PRF (const std::string &oid)

## Detailed Description

PRF from ANSI X9.42

Definition at line 18 of file prf_x942.h.

## Constructor & Destructor Documentation

## ◆ X942_PRF()

Botan::X942_PRF::X942_PRF | ( | const std::string & | oid | ) |

Definition at line 84 of file prf_x942.cpp.

References Botan::OIDS::have_oid(), Botan::OIDS::lookup(), and oid.

85 {
86 if(OIDS::have_oid(oid))
87 key_wrap_oid = OIDS::lookup(oid).as_string();
88 else
89 key_wrap_oid = oid;
90 }
Botan::OIDS::lookup
std::string lookup(const OID &oid)
Definition: oids.cpp:31
Botan::OIDS::have_oid
bool have_oid(const std::string &name)
Definition: oids.cpp:61
oid
OID oid
Definition: x509_ext.cpp:446

## Member Function Documentation

## ◆ clear()

void Botan::KDF::clear | ( |  | ) |
| inline virtual inherited

Zeroize internal state

Implements Botan::Algorithm.

Definition at line 81 of file kdf.h.

81 {}

## ◆ clone()

KDF* Botan::X942_PRF::clone | ( |  | ) | const
| inline virtual

Implements Botan::KDF.

Definition at line 25 of file prf_x942.h.

25 { return new X942_PRF(key_wrap_oid); }
Botan::X942_PRF::X942_PRF
X942_PRF(const std::string &oid)
Definition: prf_x942.cpp:84

## ◆ derive()

SecureVector< byte > Botan::X942_PRF::derive | ( | size_t | key_len,
|  | const byte | secret[],
|  | size_t | secret_len,
|  | const byte | salt[],
|  | size_t | salt_len
| ) |  | const
| virtual

Implements Botan::KDF.

Definition at line 35 of file prf_x942.cpp.

References Botan::PEM_Code::encode(), Botan::Buffered_Computation::final(), Botan::CT::min(), Botan::OCTET_STRING, Botan::SEQUENCE, Botan::MemoryRegion< T >::size(), and Botan::Buffered_Computation::update().

38 {
39 SHA_160 hash;
40 const OID kek_algo(key_wrap_oid);
41
42 SecureVector<byte> key;
43 u32bit counter = 1;
44
45 while(key.size() != key_len && counter)
46 {
47 hash.update(secret, secret_len);
48
49 hash.update(
50 DER_Encoder().start_cons(SEQUENCE)
51
52 .start_cons(SEQUENCE)
53 .encode(kek_algo)
54 .raw_bytes(encode_x942_int(counter))
55 .end_cons()
56
57 .encode_if(salt_len != 0,
58 DER_Encoder()
59 .start_explicit(0)
60 .encode(salt, salt_len, OCTET_STRING)
61 .end_explicit()
62 )
63
64 .start_explicit(2)
65 .raw_bytes(encode_x942_int(static_cast<u32bit>(8 * key_len)))
66 .end_explicit()
67
68 .end_cons().get_contents()
69 );
70
71 SecureVector<byte> digest = hash.final();
72 const size_t needed = std::min(digest.size(), key_len - key.size());
73 key += std::make_pair(&digest[0], needed);
74
75 ++counter;
76 }
77
78 return key;
79 }
Botan::OCTET_STRING
Definition: asn1_int.h:31
Botan::SEQUENCE
Definition: asn1_int.h:35
Botan::PEM_Code::encode
std::string encode(const byte der[], size_t length, const std::string &label, size_t width)
Definition: pem.cpp:19
Botan::CT::min
T min(T a, T b)
Definition: ct_utils.h:127
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::X942_PRF::name | ( |  | ) | const
| inline virtual

Returns
  name of this algorithm

Implements Botan::Algorithm.

Definition at line 24 of file prf_x942.h.

24 { return "X942_PRF(" + key_wrap_oid + ")"; }

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

- src/kdf/prf_x942/prf_x942.h
- src/kdf/prf_x942/prf_x942.cpp