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

#include <prf_x942.h>

Inheritance diagram for Botan::X942_PRF:
Botan::KDF Botan::Algorithm

Public Member Functions

void clear ()
 
KDFclone () const
 
SecureVector< bytederive (size_t, const byte[], size_t, const byte[], size_t) const
 
SecureVector< bytederive_key (size_t key_len, const MemoryRegion< byte > &secret, const std::string &salt="") const
 
SecureVector< bytederive_key (size_t key_len, const MemoryRegion< byte > &secret, const MemoryRegion< byte > &salt) const
 
SecureVector< bytederive_key (size_t key_len, const MemoryRegion< byte > &secret, const byte salt[], size_t salt_len) const
 
SecureVector< bytederive_key (size_t key_len, const byte secret[], size_t secret_len, const std::string &salt="") const
 
SecureVector< bytederive_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

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  }
std::string lookup(const OID &oid)
Definition: oids.cpp:31
bool have_oid(const std::string &name)
Definition: oids.cpp:61
OID oid
Definition: x509_ext.cpp:446

Member Function Documentation

void Botan::KDF::clear ( )
inlinevirtualinherited

Zeroize internal state

Implements Botan::Algorithm.

Definition at line 81 of file kdf.h.

81 {}
KDF* Botan::X942_PRF::clone ( ) const
inlinevirtual

Implements Botan::KDF.

Definition at line 25 of file prf_x942.h.

25 { return new X942_PRF(key_wrap_oid); }
X942_PRF(const std::string &oid)
Definition: prf_x942.cpp:84
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::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  }
std::string encode(const byte der[], size_t length, const std::string &label, size_t width)
Definition: pem.cpp:19
unsigned int u32bit
Definition: types.h:32
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_lenthe desired output length in bytes
secretthe secret input
salta 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  }
unsigned char byte
Definition: types.h:22
SecureVector< byte > derive_key(size_t key_len, const MemoryRegion< byte > &secret, const std::string &salt="") const
Definition: kdf.cpp:15
size_t size() const
Definition: secmem.h:29
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_lenthe desired output length in bytes
secretthe secret input
salta 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  }
SecureVector< byte > derive_key(size_t key_len, const MemoryRegion< byte > &secret, const std::string &salt="") const
Definition: kdf.cpp:15
size_t size() const
Definition: secmem.h:29
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_lenthe desired output length in bytes
secretthe secret input
salta diversifier
salt_lensize 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  }
SecureVector< byte > derive_key(size_t key_len, const MemoryRegion< byte > &secret, const std::string &salt="") const
Definition: kdf.cpp:15
size_t size() const
Definition: secmem.h:29
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_lenthe desired output length in bytes
secretthe secret input
secret_lensize of secret in bytes
salta 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  }
SecureVector< byte > derive_key(size_t key_len, const MemoryRegion< byte > &secret, const std::string &salt="") const
Definition: kdf.cpp:15
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_lenthe desired output length in bytes
secretthe secret input
secret_lensize of secret in bytes
salta diversifier
salt_lensize 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  }
std::string Botan::X942_PRF::name ( ) const
inlinevirtual
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: