00001
00002
00003
00004
00005
00006 #ifndef CRYPTOPP_CAST_H
00007 #define CRYPTOPP_CAST_H
00008
00009 #include "seckey.h"
00010 #include "secblock.h"
00011
00012 NAMESPACE_BEGIN(CryptoPP)
00013
00014 class CAST
00015 {
00016 protected:
00017 static const word32 S[8][256];
00018 };
00019
00020
00021 struct CAST128_Info : public FixedBlockSize<8>, public VariableKeyLength<16, 5, 16>
00022 {
00023 static const char *StaticAlgorithmName() {return "CAST-128";}
00024 };
00025
00026
00027 class CAST128 : public CAST128_Info, public BlockCipherDocumentation
00028 {
00029 class CRYPTOPP_NO_VTABLE Base : public CAST, public BlockCipherImpl<CAST128_Info>
00030 {
00031 public:
00032 void UncheckedSetKey(const byte *userKey, unsigned int length, const NameValuePairs ¶ms);
00033
00034 protected:
00035 bool reduced;
00036 FixedSizeSecBlock<word32, 32> K;
00037 };
00038
00039 class CRYPTOPP_NO_VTABLE Enc : public Base
00040 {
00041 public:
00042 void ProcessAndXorBlock(const byte *inBlock, const byte *xorBlock, byte *outBlock) const;
00043 };
00044
00045 class CRYPTOPP_NO_VTABLE Dec : public Base
00046 {
00047 public:
00048 void ProcessAndXorBlock(const byte *inBlock, const byte *xorBlock, byte *outBlock) const;
00049 };
00050
00051 public:
00052 typedef BlockCipherFinal<ENCRYPTION, Enc> Encryption;
00053 typedef BlockCipherFinal<DECRYPTION, Dec> Decryption;
00054 };
00055
00056
00057 struct CAST256_Info : public FixedBlockSize<16>, public VariableKeyLength<16, 16, 32>
00058 {
00059 static const char *StaticAlgorithmName() {return "CAST-256";}
00060 };
00061
00062
00063 class CAST256 : public CAST256_Info, public BlockCipherDocumentation
00064 {
00065 class CRYPTOPP_NO_VTABLE Base : public CAST, public BlockCipherImpl<CAST256_Info>
00066 {
00067 public:
00068 void UncheckedSetKey(const byte *userKey, unsigned int length, const NameValuePairs ¶ms);
00069 void ProcessAndXorBlock(const byte *inBlock, const byte *xorBlock, byte *outBlock) const;
00070
00071 protected:
00072 static const word32 t_m[8][24];
00073 static const unsigned int t_r[8][24];
00074
00075 static void Omega(int i, word32 kappa[8]);
00076
00077 FixedSizeSecBlock<word32, 8*12> K;
00078 };
00079
00080 public:
00081 typedef BlockCipherFinal<ENCRYPTION, Base> Encryption;
00082 typedef BlockCipherFinal<DECRYPTION, Base> Decryption;
00083 };
00084
00085 typedef CAST128::Encryption CAST128Encryption;
00086 typedef CAST128::Decryption CAST128Decryption;
00087
00088 typedef CAST256::Encryption CAST256Encryption;
00089 typedef CAST256::Decryption CAST256Decryption;
00090
00091 NAMESPACE_END
00092
00093 #endif