Line | Count | Source |
1 | | // blowfish.h - originally written and placed in the public domain by Wei Dai |
2 | | |
3 | | /// \file blowfish.h |
4 | | /// \brief Classes for the Blowfish block cipher |
5 | | |
6 | | #ifndef CRYPTOPP_BLOWFISH_H |
7 | | #define CRYPTOPP_BLOWFISH_H |
8 | | |
9 | | #include "seckey.h" |
10 | | #include "secblock.h" |
11 | | |
12 | | NAMESPACE_BEGIN(CryptoPP) |
13 | | |
14 | | /// \brief Blowfish block cipher information |
15 | | struct Blowfish_Info : public FixedBlockSize<8>, public VariableKeyLength<16, 4, 56>, public FixedRounds<16> |
16 | | { |
17 | 6 | CRYPTOPP_STATIC_CONSTEXPR const char* StaticAlgorithmName() {return "Blowfish";} |
18 | | }; |
19 | | |
20 | | // <a href="http://www.cryptopp.com/wiki/Blowfish">Blowfish</a> |
21 | | |
22 | | /// \brief Blowfish block cipher |
23 | | /// \since Crypto++ 1.0 |
24 | | class Blowfish : public Blowfish_Info, public BlockCipherDocumentation |
25 | | { |
26 | | /// \brief Class specific implementation and overrides used to operate the cipher. |
27 | | /// \details Implementations and overrides in \p Base apply to both \p ENCRYPTION and \p DECRYPTION directions |
28 | | class CRYPTOPP_NO_VTABLE Base : public BlockCipherImpl<Blowfish_Info> |
29 | | { |
30 | | public: |
31 | | void ProcessAndXorBlock(const byte *inBlock, const byte *xorBlock, byte *outBlock) const; |
32 | | void UncheckedSetKey(const byte *key_string, unsigned int keylength, const NameValuePairs ¶ms); |
33 | | |
34 | | private: |
35 | | void crypt_block(const word32 in[2], word32 out[2]) const; |
36 | | |
37 | | static const word32 p_init[ROUNDS+2]; |
38 | | static const word32 s_init[4*256]; |
39 | | |
40 | | FixedSizeSecBlock<word32, ROUNDS+2> pbox; |
41 | | FixedSizeSecBlock<word32, 4*256> sbox; |
42 | | }; |
43 | | |
44 | | public: |
45 | | typedef BlockCipherFinal<ENCRYPTION, Base> Encryption; |
46 | | typedef BlockCipherFinal<DECRYPTION, Base> Decryption; |
47 | | }; |
48 | | |
49 | | typedef Blowfish::Encryption BlowfishEncryption; |
50 | | typedef Blowfish::Decryption BlowfishDecryption; |
51 | | |
52 | | NAMESPACE_END |
53 | | |
54 | | #endif |