Botan  1.11.15
Public Types | Public Member Functions
Botan::X942_PRF Class Reference

#include <prf_x942.h>

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

List of all members.

Public Types

typedef SCAN_Name Spec

Public Member Functions

KDFclone () const
secure_vector< bytederive_key (size_t key_len, const byte secret[], size_t secret_len, const byte salt[], size_t salt_len) const
secure_vector< bytederive_key (size_t key_len, const secure_vector< byte > &secret, const std::string &salt="") const
template<typename Alloc , typename Alloc2 >
secure_vector< bytederive_key (size_t key_len, const std::vector< byte, Alloc > &secret, const std::vector< byte, Alloc2 > &salt) const
secure_vector< bytederive_key (size_t key_len, const secure_vector< byte > &secret, const byte salt[], size_t salt_len) const
secure_vector< bytederive_key (size_t key_len, const byte secret[], size_t secret_len, const std::string &salt="") const
size_t kdf (byte key[], size_t key_len, const byte secret[], size_t secret_len, const byte salt[], size_t salt_len) const override
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.


Member Typedef Documentation

typedef SCAN_Name Botan::KDF::Spec [inherited]

Definition at line 119 of file kdf.h.


Constructor & Destructor Documentation

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

Definition at line 85 of file prf_x942.cpp.

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

   {
   if(OIDS::have_oid(oid))
      m_key_wrap_oid = OIDS::lookup(oid).as_string();
   else
      m_key_wrap_oid = oid;
   }

Member Function Documentation

KDF* Botan::X942_PRF::clone ( ) const [inline, virtual]

Implements Botan::KDF.

Definition at line 23 of file prf_x942.h.

{ return new X942_PRF(m_key_wrap_oid); }
secure_vector<byte> Botan::KDF::derive_key ( size_t  key_len,
const byte  secret[],
size_t  secret_len,
const byte  salt[],
size_t  salt_len 
) const [inline, 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 41 of file kdf.h.

         {
         secure_vector<byte> key(key_len);
         key.resize(kdf(&key[0], key.size(), secret, secret_len, salt, salt_len));
         return key;
         }
secure_vector<byte> Botan::KDF::derive_key ( size_t  key_len,
const secure_vector< byte > &  secret,
const std::string &  salt = "" 
) const [inline, inherited]

Derive a key

Parameters:
key_lenthe desired output length in bytes
secretthe secret input
salta diversifier

Definition at line 58 of file kdf.h.

         {
         return derive_key(key_len, &secret[0], secret.size(),
                           reinterpret_cast<const byte*>(salt.data()),
                           salt.length());
         }
template<typename Alloc , typename Alloc2 >
secure_vector<byte> Botan::KDF::derive_key ( size_t  key_len,
const std::vector< byte, Alloc > &  secret,
const std::vector< byte, Alloc2 > &  salt 
) const [inline, inherited]

Derive a key

Parameters:
key_lenthe desired output length in bytes
secretthe secret input
salta diversifier

Definition at line 74 of file kdf.h.

         {
         return derive_key(key_len,
                           &secret[0], secret.size(),
                           &salt[0], salt.size());
         }
secure_vector<byte> Botan::KDF::derive_key ( size_t  key_len,
const secure_vector< byte > &  secret,
const byte  salt[],
size_t  salt_len 
) const [inline, 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 90 of file kdf.h.

         {
         return derive_key(key_len,
                           &secret[0], secret.size(),
                           salt, salt_len);
         }
secure_vector<byte> Botan::KDF::derive_key ( size_t  key_len,
const byte  secret[],
size_t  secret_len,
const std::string &  salt = "" 
) const [inline, 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 107 of file kdf.h.

         {
         return derive_key(key_len, secret, secret_len,
                           reinterpret_cast<const byte*>(salt.data()),
                           salt.length());
         }
size_t Botan::X942_PRF::kdf ( byte  key[],
size_t  key_len,
const byte  secret[],
size_t  secret_len,
const byte  salt[],
size_t  salt_len 
) const [override, virtual]

Implements Botan::KDF.

Definition at line 34 of file prf_x942.cpp.

References Botan::copy_mem(), Botan::PEM_Code::encode(), Botan::OCTET_STRING, and Botan::SEQUENCE.

   {
   std::unique_ptr<HashFunction> hash(make_a<HashFunction>("SHA-160"));
   const OID kek_algo(m_key_wrap_oid);

   secure_vector<byte> h;
   size_t offset = 0;
   u32bit counter = 1;

   while(offset != key_len && counter)
      {
      hash->update(secret, secret_len);

      hash->update(
         DER_Encoder().start_cons(SEQUENCE)

            .start_cons(SEQUENCE)
               .encode(kek_algo)
               .raw_bytes(encode_x942_int(counter))
            .end_cons()

            .encode_if(salt_len != 0,
               DER_Encoder()
                  .start_explicit(0)
                     .encode(salt, salt_len, OCTET_STRING)
                  .end_explicit()
               )

            .start_explicit(2)
               .raw_bytes(encode_x942_int(static_cast<u32bit>(8 * key_len)))
            .end_explicit()

         .end_cons().get_contents()
         );

      hash->final(h);
      const size_t copied = std::min(h.size(), key_len - offset);
      copy_mem(&key[offset], &h[0], copied);
      offset += copied;

      ++counter;
      }

   return offset;
   }
std::string Botan::X942_PRF::name ( ) const [inline, virtual]

Implements Botan::KDF.

Definition at line 21 of file prf_x942.h.

{ return "X942_PRF(" + m_key_wrap_oid + ")"; }

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