File indexing completed on 2025-01-18 09:54:54
0001
0002
0003
0004
0005
0006
0007 #ifndef CRYPTOPP_CAST_H
0008 #define CRYPTOPP_CAST_H
0009
0010 #include "seckey.h"
0011 #include "secblock.h"
0012
0013 NAMESPACE_BEGIN(CryptoPP)
0014
0015
0016
0017 class CAST
0018 {
0019 protected:
0020 static const word32 S[8][256];
0021 };
0022
0023
0024
0025 struct CAST128_Info : public FixedBlockSize<8>, public VariableKeyLength<16, 5, 16>
0026 {
0027 CRYPTOPP_STATIC_CONSTEXPR const char* StaticAlgorithmName() {return "CAST-128";}
0028 };
0029
0030
0031
0032
0033 class CAST128 : public CAST128_Info, public BlockCipherDocumentation
0034 {
0035
0036 class CRYPTOPP_NO_VTABLE Base : public CAST, public BlockCipherImpl<CAST128_Info>
0037 {
0038 public:
0039 void UncheckedSetKey(const byte *userKey, unsigned int length, const NameValuePairs ¶ms);
0040
0041 protected:
0042 bool reduced;
0043 FixedSizeSecBlock<word32, 32> K;
0044 mutable FixedSizeSecBlock<word32, 3> m_t;
0045 };
0046
0047
0048 class CRYPTOPP_NO_VTABLE Enc : public Base
0049 {
0050 public:
0051 void ProcessAndXorBlock(const byte *inBlock, const byte *xorBlock, byte *outBlock) const;
0052 };
0053
0054
0055 class CRYPTOPP_NO_VTABLE Dec : public Base
0056 {
0057 public:
0058 void ProcessAndXorBlock(const byte *inBlock, const byte *xorBlock, byte *outBlock) const;
0059 };
0060
0061 public:
0062 typedef BlockCipherFinal<ENCRYPTION, Enc> Encryption;
0063 typedef BlockCipherFinal<DECRYPTION, Dec> Decryption;
0064 };
0065
0066
0067
0068 struct CAST256_Info : public FixedBlockSize<16>, public VariableKeyLength<16, 16, 32, 4>
0069 {
0070 CRYPTOPP_STATIC_CONSTEXPR const char* StaticAlgorithmName() {return "CAST-256";}
0071 };
0072
0073
0074
0075
0076 class CAST256 : public CAST256_Info, public BlockCipherDocumentation
0077 {
0078
0079 class CRYPTOPP_NO_VTABLE Base : public CAST, public BlockCipherImpl<CAST256_Info>
0080 {
0081 public:
0082 void UncheckedSetKey(const byte *userKey, unsigned int length, const NameValuePairs ¶ms);
0083 void ProcessAndXorBlock(const byte *inBlock, const byte *xorBlock, byte *outBlock) const;
0084
0085 protected:
0086 static const word32 t_m[8][24];
0087 static const unsigned int t_r[8][24];
0088
0089 static void Omega(int i, word32 kappa[8]);
0090
0091 FixedSizeSecBlock<word32, 8*12> K;
0092 mutable FixedSizeSecBlock<word32, 8> kappa;
0093 mutable FixedSizeSecBlock<word32, 3> m_t;
0094 };
0095
0096 public:
0097 typedef BlockCipherFinal<ENCRYPTION, Base> Encryption;
0098 typedef BlockCipherFinal<DECRYPTION, Base> Decryption;
0099 };
0100
0101 typedef CAST128::Encryption CAST128Encryption;
0102 typedef CAST128::Decryption CAST128Decryption;
0103
0104 typedef CAST256::Encryption CAST256Encryption;
0105 typedef CAST256::Decryption CAST256Decryption;
0106
0107 NAMESPACE_END
0108
0109 #endif