Crypto++ 8.0 Free C++ class library of cryptographic schemes

blowfish.h
Go to the documentation of this file.
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 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 &params);
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
BlockCipherDocumentation
Provides Encryption and Decryption typedefs used by derived classes to implement a block cipher...
Definition: seckey.h:398
Blowfish
Blowfish block cipher.
Definition: blowfish.h:24
secblock.h
Classes and functions for secure memory allocations.
FixedBlockSize
Inherited by algorithms with fixed block size.
Definition: seckey.h:40
seckey.h
Classes and functions for implementing secret key algorithms.
BlockCipherFinal
Provides class member functions to key a block cipher.
Definition: seckey.h:317
Blowfish_Info
Blowfish block cipher information.
Definition: blowfish.h:15
FixedSizeSecBlock< word32, ROUNDS+2 >
FixedRounds
Inherited by algorithms with fixed number of rounds.
Definition: seckey.h:52
VariableKeyLength
Inherited by keyed algorithms with variable key length.
Definition: seckey.h:165
FixedRounds< 16 >::ROUNDS
static const int ROUNDS
The number of rounds for the algorithm provided as a constant.
Definition: seckey.h:56
BlockCipherImpl
Provides a base implementation of Algorithm and SimpleKeyingInterface for block ciphers.
Definition: seckey.h:305
CryptoPP
Crypto++ library namespace.
NameValuePairs
Interface for retrieving values given their names.
Definition: cryptlib.h:293