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

cast.h
Go to the documentation of this file.
1 // cast.h - originally written and placed in the public domain by Wei Dai
2
3 /// \file cast.h
4 /// \brief Classes for the CAST-128 and CAST-256 block ciphers
5 /// \since Crypto++ 2.2
6
7 #ifndef CRYPTOPP_CAST_H
8 #define CRYPTOPP_CAST_H
9
10 #include "seckey.h"
11 #include "secblock.h"
12
13 NAMESPACE_BEGIN(CryptoPP)
14
15 /// \brief CAST block cipher base
16 /// \since Crypto++ 2.2
17 class CAST
18 {
19 protected:
20 static const word32 S[8][256];
21 };
22
23 /// \brief CAST128 block cipher information
24 /// \since Crypto++ 2.2
25 struct CAST128_Info : public FixedBlockSize<8>, public VariableKeyLength<16, 5, 16>
26 {
27 CRYPTOPP_STATIC_CONSTEXPR const char* StaticAlgorithmName() {return "CAST-128";}
28 };
29
30 /// \brief CAST128 block cipher
31 /// \sa <a href="http://www.cryptopp.com/wiki/CAST-128">CAST-128</a>
32 /// \since Crypto++ 2.2
33 class CAST128 : public CAST128_Info, public BlockCipherDocumentation
34 {
35 /// \brief CAST128 block cipher default operation
36 class CRYPTOPP_NO_VTABLE Base : public CAST, public BlockCipherImpl<CAST128_Info>
37 {
38 public:
39 void UncheckedSetKey(const byte *userKey, unsigned int length, const NameValuePairs &params);
40
41 protected:
42 bool reduced;
43 FixedSizeSecBlock<word32, 32> K;
44 mutable FixedSizeSecBlock<word32, 3> m_t;
45 };
46
47 /// \brief CAST128 block cipher encryption operation
48 class CRYPTOPP_NO_VTABLE Enc : public Base
49 {
50 public:
51 void ProcessAndXorBlock(const byte *inBlock, const byte *xorBlock, byte *outBlock) const;
52 };
53
54 /// \brief CAST128 block cipher decryption operation
55 class CRYPTOPP_NO_VTABLE Dec : public Base
56 {
57 public:
58 void ProcessAndXorBlock(const byte *inBlock, const byte *xorBlock, byte *outBlock) const;
59 };
60
61 public:
62 typedef BlockCipherFinal<ENCRYPTION, Enc> Encryption;
63 typedef BlockCipherFinal<DECRYPTION, Dec> Decryption;
64 };
65
66 /// \brief CAST256 block cipher information
67 /// \since Crypto++ 4.0
68 struct CAST256_Info : public FixedBlockSize<16>, public VariableKeyLength<16, 16, 32, 4>
69 {
70 CRYPTOPP_STATIC_CONSTEXPR const char* StaticAlgorithmName() {return "CAST-256";}
71 };
72
73 /// \brief CAST256 block cipher
74 /// \sa <a href="http://www.cryptopp.com/wiki/CAST-256">CAST-256</a>
75 /// \since Crypto++ 4.0
76 class CAST256 : public CAST256_Info, public BlockCipherDocumentation
77 {
78 /// \brief CAST256 block cipher default operation
79 class CRYPTOPP_NO_VTABLE Base : public CAST, public BlockCipherImpl<CAST256_Info>
80 {
81 public:
82 void UncheckedSetKey(const byte *userKey, unsigned int length, const NameValuePairs &params);
83 void ProcessAndXorBlock(const byte *inBlock, const byte *xorBlock, byte *outBlock) const;
84
85 protected:
86 static const word32 t_m[8][24];
87 static const unsigned int t_r[8][24];
88
89 static void Omega(int i, word32 kappa[8]);
90
91 FixedSizeSecBlock<word32, 8*12> K;
92 mutable FixedSizeSecBlock<word32, 8> kappa;
93 mutable FixedSizeSecBlock<word32, 3> m_t;
94 };
95
96 public:
97 typedef BlockCipherFinal<ENCRYPTION, Base> Encryption;
98 typedef BlockCipherFinal<DECRYPTION, Base> Decryption;
99 };
100
101 typedef CAST128::Encryption CAST128Encryption;
102 typedef CAST128::Decryption CAST128Decryption;
103
104 typedef CAST256::Encryption CAST256Encryption;
105 typedef CAST256::Decryption CAST256Decryption;
106
107 NAMESPACE_END
108
109 #endif
CAST256_Info
CAST256 block cipher information.
Definition: cast.h:68
CAST128_Info
CAST128 block cipher information.
Definition: cast.h:25
CAST128
CAST128 block cipher.
Definition: cast.h:33
CAST
CAST block cipher base.
Definition: cast.h:17
CAST256
CAST256 block cipher.
Definition: cast.h:76
secblock.h
Classes and functions for secure memory allocations.
word32
unsigned int word32
32-bit unsigned datatype
Definition: config_int.h:62
FixedBlockSize
Inherited by algorithms with fixed block size.
Definition: seckey.h:40
BlockCipherImpl
Provides a base implementation of Algorithm and SimpleKeyingInterface for block ciphers.
Definition: seckey.h:305
BlockCipherDocumentation
Provides Encryption and Decryption typedefs used by derived classes to implement a block cipher.
Definition: seckey.h:398
seckey.h
Classes and functions for implementing secret key algorithms.
BlockCipherFinal< ENCRYPTION, Enc >
FixedSizeSecBlock< word32, 32 >
CryptoPP
Crypto++ library namespace.
NameValuePairs
Interface for retrieving values given their names.
Definition: cryptlib.h:321
VariableKeyLength
Inherited by keyed algorithms with variable key length.
Definition: seckey.h:165