Back to home page

EIC code displayed by LXR

 
 

    


File indexing completed on 2025-01-18 09:54:54

0001 // cast.h - originally written and placed in the public domain by Wei Dai

0002 
0003 /// \file cast.h

0004 /// \brief Classes for the CAST-128 and CAST-256 block ciphers

0005 /// \since Crypto++ 2.2

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 /// \brief CAST block cipher base

0016 /// \since Crypto++ 2.2

0017 class CAST
0018 {
0019 protected:
0020     static const word32 S[8][256];
0021 };
0022 
0023 /// \brief CAST128 block cipher information

0024 /// \since Crypto++ 2.2

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 /// \brief CAST128 block cipher

0031 /// \sa <a href="http://www.cryptopp.com/wiki/CAST-128">CAST-128</a>

0032 /// \since Crypto++ 2.2

0033 class CAST128 : public CAST128_Info, public BlockCipherDocumentation
0034 {
0035     /// \brief CAST128 block cipher default operation

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 &params);
0040 
0041     protected:
0042         bool reduced;
0043         FixedSizeSecBlock<word32, 32> K;
0044         mutable FixedSizeSecBlock<word32, 3> m_t;
0045     };
0046 
0047     /// \brief CAST128 block cipher encryption operation

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     /// \brief CAST128 block cipher decryption operation

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 /// \brief CAST256 block cipher information

0067 /// \since Crypto++ 4.0

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 /// \brief CAST256 block cipher

0074 /// \sa <a href="http://www.cryptopp.com/wiki/CAST-256">CAST-256</a>

0075 /// \since Crypto++ 4.0

0076 class CAST256 : public CAST256_Info, public BlockCipherDocumentation
0077 {
0078     /// \brief CAST256 block cipher default operation

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 &params);
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