1#ifndef CRYPTOPP_CAST_H
2#define CRYPTOPP_CAST_H
3
4/** \file
5*/
6
7#include "seckey.h"
8#include "secblock.h"
9
10NAMESPACE_BEGIN(CryptoPP)
11
12class CAST
13{
14protected:
15	static const word32 S[8][256];
16};
17
18//! algorithm info
19struct CAST128_Info : public FixedBlockSize<8>, public VariableKeyLength<16, 5, 16>
20{
21	static const char *StaticAlgorithmName() {return "CAST-128";}
22};
23
24/// <a href="http://www.weidai.com/scan-mirror/cs.html#CAST-128">CAST-128</a>
25class CAST128 : public CAST128_Info, public BlockCipherDocumentation
26{
27	class CRYPTOPP_NO_VTABLE Base : public CAST, public BlockCipherImpl<CAST128_Info>
28	{
29	public:
30		void UncheckedSetKey(const byte *userKey, unsigned int length, const NameValuePairs &params);
31
32	protected:
33		bool reduced;
34		FixedSizeSecBlock<word32, 32> K;
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
54//! algorithm info
55struct CAST256_Info : public FixedBlockSize<16>, public VariableKeyLength<16, 16, 32>
56{
57	static const char *StaticAlgorithmName() {return "CAST-256";}
58};
59
60//! <a href="http://www.weidai.com/scan-mirror/cs.html#CAST-256">CAST-256</a>
61class CAST256 : public CAST256_Info, public BlockCipherDocumentation
62{
63	class CRYPTOPP_NO_VTABLE Base : public CAST, public BlockCipherImpl<CAST256_Info>
64	{
65	public:
66		void UncheckedSetKey(const byte *userKey, unsigned int length, const NameValuePairs &params);
67		void ProcessAndXorBlock(const byte *inBlock, const byte *xorBlock, byte *outBlock) const;
68
69	protected:
70		static const word32 t_m[8][24];
71		static const unsigned int t_r[8][24];
72
73		static void Omega(int i, word32 kappa[8]);
74
75		FixedSizeSecBlock<word32, 8*12> K;
76	};
77
78public:
79	typedef BlockCipherFinal<ENCRYPTION, Base> Encryption;
80	typedef BlockCipherFinal<DECRYPTION, Base> Decryption;
81};
82
83typedef CAST128::Encryption CAST128Encryption;
84typedef CAST128::Decryption CAST128Decryption;
85
86typedef CAST256::Encryption CAST256Encryption;
87typedef CAST256::Decryption CAST256Decryption;
88
89NAMESPACE_END
90
91#endif
92