Botan  1.11.15
src/lib/block/blowfish/blowfish.h
Go to the documentation of this file.
00001 /*
00002 * Blowfish
00003 * (C) 1999-2011 Jack Lloyd
00004 *
00005 * Botan is released under the Simplified BSD License (see license.txt)
00006 */
00007 
00008 #ifndef BOTAN_BLOWFISH_H__
00009 #define BOTAN_BLOWFISH_H__
00010 
00011 #include <botan/block_cipher.h>
00012 
00013 namespace Botan {
00014 
00015 /**
00016 * Blowfish
00017 */
00018 class BOTAN_DLL Blowfish : public Block_Cipher_Fixed_Params<8, 1, 56>
00019    {
00020    public:
00021       void encrypt_n(const byte in[], byte out[], size_t blocks) const;
00022       void decrypt_n(const byte in[], byte out[], size_t blocks) const;
00023 
00024       /**
00025       * Modified EKSBlowfish key schedule, used for bcrypt password hashing
00026       */
00027       void eks_key_schedule(const byte key[], size_t key_length,
00028                             const byte salt[16], size_t workfactor);
00029 
00030       void clear();
00031       std::string name() const { return "Blowfish"; }
00032       BlockCipher* clone() const { return new Blowfish; }
00033    private:
00034       void key_schedule(const byte key[], size_t length);
00035 
00036       void key_expansion(const byte key[],
00037                          size_t key_length,
00038                          const byte salt[16]);
00039 
00040       void generate_sbox(secure_vector<u32bit>& box,
00041                          u32bit& L, u32bit& R,
00042                          const byte salt[16],
00043                          size_t salt_off) const;
00044 
00045       static const u32bit P_INIT[18];
00046       static const u32bit S_INIT[1024];
00047 
00048       secure_vector<u32bit> S, P;
00049    };
00050 
00051 }
00052 
00053 #endif