1#ifndef CRYPTOPP_TWOFISH_H
2#define CRYPTOPP_TWOFISH_H
3
4/** \file
5*/
6
7#include "seckey.h"
8#include "secblock.h"
9
10NAMESPACE_BEGIN(CryptoPP)
11
12//! _
13struct Twofish_Info : public FixedBlockSize<16>, public VariableKeyLength<16, 0, 32>, FixedRounds<16>
14{
15	static const char *StaticAlgorithmName() {return "Twofish";}
16};
17
18/// <a href="http://www.weidai.com/scan-mirror/cs.html#Twofish">Twofish</a>
19class Twofish : public Twofish_Info, public BlockCipherDocumentation
20{
21	class CRYPTOPP_NO_VTABLE Base : public BlockCipherImpl<Twofish_Info>
22	{
23	public:
24		void UncheckedSetKey(const byte *userKey, unsigned int length, const NameValuePairs &params);
25
26	protected:
27		static word32 h0(word32 x, const word32 *key, unsigned int kLen);
28		static word32 h(word32 x, const word32 *key, unsigned int kLen);
29
30		static const byte q[2][256];
31		static const word32 mds[4][256];
32
33		FixedSizeSecBlock<word32, 40> m_k;
34		FixedSizeSecBlock<word32[256], 4> m_s;
35	};
36
37	class CRYPTOPP_NO_VTABLE Enc : public Base
38	{
39	public:
40		void ProcessAndXorBlock(const byte *inBlock, const byte *xorBlock, byte *outBlock) const;
41	};
42
43	class CRYPTOPP_NO_VTABLE Dec : public Base
44	{
45	public:
46		void ProcessAndXorBlock(const byte *inBlock, const byte *xorBlock, byte *outBlock) const;
47	};
48
49public:
50	typedef BlockCipherFinal<ENCRYPTION, Enc> Encryption;
51	typedef BlockCipherFinal<DECRYPTION, Dec> Decryption;
52};
53
54typedef Twofish::Encryption TwofishEncryption;
55typedef Twofish::Decryption TwofishDecryption;
56
57NAMESPACE_END
58
59#endif
60