Botan  1.11.15
src/lib/pbkdf/pbkdf2/pbkdf2.h
Go to the documentation of this file.
00001 /*
00002 * PBKDF2
00003 * (C) 1999-2007,2012 Jack Lloyd
00004 *
00005 * Botan is released under the Simplified BSD License (see license.txt)
00006 */
00007 
00008 #ifndef BOTAN_PBKDF2_H__
00009 #define BOTAN_PBKDF2_H__
00010 
00011 #include <botan/pbkdf.h>
00012 #include <botan/mac.h>
00013 #include <botan/hash.h>
00014 
00015 namespace Botan {
00016 
00017 BOTAN_DLL size_t pbkdf2(MessageAuthenticationCode& prf,
00018                         byte out[],
00019                         size_t out_len,
00020                         const std::string& passphrase,
00021                         const byte salt[], size_t salt_len,
00022                         size_t iterations,
00023                         std::chrono::milliseconds msec);
00024 
00025 /**
00026 * PKCS #5 PBKDF2
00027 */
00028 class BOTAN_DLL PKCS5_PBKDF2 : public PBKDF
00029    {
00030    public:
00031       std::string name() const override
00032          {
00033          return "PBKDF2(" + mac->name() + ")";
00034          }
00035 
00036       PBKDF* clone() const override
00037          {
00038          return new PKCS5_PBKDF2(mac->clone());
00039          }
00040 
00041       size_t pbkdf(byte output_buf[], size_t output_len,
00042                    const std::string& passphrase,
00043                    const byte salt[], size_t salt_len,
00044                    size_t iterations,
00045                    std::chrono::milliseconds msec) const override;
00046 
00047       /**
00048       * Create a PKCS #5 instance using the specified message auth code
00049       * @param mac_fn the MAC object to use as PRF
00050       */
00051       PKCS5_PBKDF2(MessageAuthenticationCode* mac_fn) : mac(mac_fn) {}
00052 
00053       static PKCS5_PBKDF2* make(const Spec& spec);
00054    private:
00055       std::unique_ptr<MessageAuthenticationCode> mac;
00056    };
00057 
00058 }
00059 
00060 #endif