Crypto++ 8.9
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
13NAMESPACE_BEGIN(CryptoPP)
14
15/// \brief CAST block cipher base
16/// \since Crypto++ 2.2
17class CAST
18{
19protected:
20 static const word32 S[8][256];
21};
22
23/// \brief CAST128 block cipher information
24/// \since Crypto++ 2.2
25struct 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
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;
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
61public:
64};
65
66/// \brief CAST256 block cipher information
67/// \since Crypto++ 4.0
68struct 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
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
92 mutable FixedSizeSecBlock<word32, 8> kappa;
94 };
95
96public:
99};
100
103
106
107NAMESPACE_END
108
109#endif
Provides class member functions to key a block cipher.
Definition seckey.h:318
Provides a base implementation of Algorithm and SimpleKeyingInterface for block ciphers.
Definition seckey.h:306
CAST128 block cipher.
Definition cast.h:34
CAST256 block cipher.
Definition cast.h:77
CAST block cipher base.
Definition cast.h:18
Inherited by algorithms with fixed block size.
Definition seckey.h:41
Fixed size stack-based SecBlock.
Definition secblock.h:1246
Interface for retrieving values given their names.
Definition cryptlib.h:327
Inherited by keyed algorithms with variable key length.
Definition seckey.h:166
unsigned int word32
32-bit unsigned datatype
Definition config_int.h:72
Crypto++ library namespace.
Classes and functions for secure memory allocations.
Classes and functions for implementing secret key algorithms.
Provides Encryption and Decryption typedefs used by derived classes to implement a block cipher.
Definition seckey.h:399
CAST128 block cipher information.
Definition cast.h:26
CAST256 block cipher information.
Definition cast.h:69