00001
00002
00003
00004
00005
00006 #ifndef CRYPTOPP_TWOFISH_H
00007 #define CRYPTOPP_TWOFISH_H
00008
00009 #include "seckey.h"
00010 #include "secblock.h"
00011
00012 NAMESPACE_BEGIN(CryptoPP)
00013
00014
00015 struct Twofish_Info : public FixedBlockSize<16>, public VariableKeyLength<16, 0, 32>, FixedRounds<16>
00016 {
00017 static const char *StaticAlgorithmName() {return "Twofish";}
00018 };
00019
00020
00021 class Twofish : public Twofish_Info, public BlockCipherDocumentation
00022 {
00023 class CRYPTOPP_NO_VTABLE Base : public BlockCipherImpl<Twofish_Info>
00024 {
00025 public:
00026 void UncheckedSetKey(const byte *userKey, unsigned int length, const NameValuePairs ¶ms);
00027
00028 protected:
00029 static word32 h0(word32 x, const word32 *key, unsigned int kLen);
00030 static word32 h(word32 x, const word32 *key, unsigned int kLen);
00031
00032 static const byte q[2][256];
00033 static const word32 mds[4][256];
00034
00035 FixedSizeSecBlock<word32, 40> m_k;
00036 FixedSizeSecBlock<word32, 4*256> m_s;
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 typedef Twofish::Encryption TwofishEncryption;
00057 typedef Twofish::Decryption TwofishDecryption;
00058
00059 NAMESPACE_END
00060
00061 #endif