File indexing completed on 2025-01-18 09:55:10
0001
0002
0003
0004
0005
0006
0007
0008
0009 #ifndef CRYPTOPP_THREEFISH_H
0010 #define CRYPTOPP_THREEFISH_H
0011
0012 #include "config.h"
0013 #include "seckey.h"
0014 #include "secblock.h"
0015 #include "algparam.h"
0016 #include "argnames.h"
0017 #include "stdcpp.h"
0018
0019 NAMESPACE_BEGIN(CryptoPP)
0020
0021
0022
0023
0024 template <unsigned int BS>
0025 struct Threefish_Info : public FixedBlockSize<BS>, FixedKeyLength<BS>
0026 {
0027 static const std::string StaticAlgorithmName()
0028 {
0029
0030 return "Threefish-" + IntToString(BS*8) + "(" + IntToString(BS*8) + ")";
0031 }
0032 };
0033
0034
0035
0036
0037
0038
0039 template <unsigned int BS>
0040 struct CRYPTOPP_NO_VTABLE Threefish_Base
0041 {
0042 virtual ~Threefish_Base() {}
0043
0044 void SetTweak(const NameValuePairs ¶ms)
0045 {
0046 m_tweak.New(3);
0047 ConstByteArrayParameter t;
0048 if (params.GetValue(Name::Tweak(), t))
0049 {
0050
0051 CRYPTOPP_ASSERT(t.size() == 16);
0052 GetUserKey(LITTLE_ENDIAN_ORDER, m_tweak.begin(), 2, t.begin(), 16);
0053 m_tweak[2] = m_tweak[0] ^ m_tweak[1];
0054 }
0055 else
0056 {
0057 std::memset(m_tweak.begin(), 0x00, 24);
0058 }
0059 }
0060
0061 typedef SecBlock<word64, AllocatorWithCleanup<word64, true> > AlignedSecBlock64;
0062 mutable AlignedSecBlock64 m_wspace;
0063 AlignedSecBlock64 m_rkey;
0064 AlignedSecBlock64 m_tweak;
0065 };
0066
0067
0068
0069
0070
0071
0072 class CRYPTOPP_NO_VTABLE Threefish256 : public Threefish_Info<32>, public BlockCipherDocumentation
0073 {
0074 public:
0075
0076
0077
0078 class CRYPTOPP_NO_VTABLE Base : public Threefish_Base<32>, public BlockCipherImpl<Threefish_Info<32> >
0079 {
0080 protected:
0081 void UncheckedSetKey(const byte *userKey, unsigned int keyLength, const NameValuePairs ¶ms);
0082 };
0083
0084
0085
0086
0087
0088 class CRYPTOPP_NO_VTABLE Enc : public Base
0089 {
0090 protected:
0091 void ProcessAndXorBlock(const byte *inBlock, const byte *xorBlock, byte *outBlock) const;
0092 };
0093
0094
0095
0096
0097
0098 class CRYPTOPP_NO_VTABLE Dec : public Base
0099 {
0100 protected:
0101 void ProcessAndXorBlock(const byte *inBlock, const byte *xorBlock, byte *outBlock) const;
0102 };
0103
0104 typedef BlockCipherFinal<ENCRYPTION, Enc> Encryption;
0105 typedef BlockCipherFinal<DECRYPTION, Dec> Decryption;
0106 };
0107
0108 typedef Threefish256::Encryption Threefish256Encryption;
0109 typedef Threefish256::Decryption Threefish256Decryption;
0110
0111
0112
0113
0114
0115
0116 class CRYPTOPP_NO_VTABLE Threefish512 : public Threefish_Info<64>, public BlockCipherDocumentation
0117 {
0118 public:
0119
0120
0121
0122 class CRYPTOPP_NO_VTABLE Base : public Threefish_Base<64>, public BlockCipherImpl<Threefish_Info<64> >
0123 {
0124 protected:
0125 void UncheckedSetKey(const byte *userKey, unsigned int keyLength, const NameValuePairs ¶ms);
0126 };
0127
0128
0129
0130
0131
0132 class CRYPTOPP_NO_VTABLE Enc : public Base
0133 {
0134 protected:
0135 void ProcessAndXorBlock(const byte *inBlock, const byte *xorBlock, byte *outBlock) const;
0136 };
0137
0138
0139
0140
0141
0142 class CRYPTOPP_NO_VTABLE Dec : public Base
0143 {
0144 protected:
0145 void ProcessAndXorBlock(const byte *inBlock, const byte *xorBlock, byte *outBlock) const;
0146 };
0147
0148 typedef BlockCipherFinal<ENCRYPTION, Enc> Encryption;
0149 typedef BlockCipherFinal<DECRYPTION, Dec> Decryption;
0150 };
0151
0152 typedef Threefish512::Encryption Threefish512Encryption;
0153 typedef Threefish512::Decryption Threefish512Decryption;
0154
0155
0156
0157
0158
0159
0160 class CRYPTOPP_NO_VTABLE Threefish1024 : public Threefish_Info<128>, public BlockCipherDocumentation
0161 {
0162 public:
0163
0164
0165
0166 class CRYPTOPP_NO_VTABLE Base : public Threefish_Base<128>, public BlockCipherImpl<Threefish_Info<128> >
0167 {
0168 protected:
0169 void UncheckedSetKey(const byte *userKey, unsigned int keyLength, const NameValuePairs ¶ms);
0170 };
0171
0172
0173
0174
0175
0176 class CRYPTOPP_NO_VTABLE Enc : public Base
0177 {
0178 protected:
0179 void ProcessAndXorBlock(const byte *inBlock, const byte *xorBlock, byte *outBlock) const;
0180 };
0181
0182
0183
0184
0185
0186 class CRYPTOPP_NO_VTABLE Dec : public Base
0187 {
0188 protected:
0189 void ProcessAndXorBlock(const byte *inBlock, const byte *xorBlock, byte *outBlock) const;
0190 };
0191
0192 typedef BlockCipherFinal<ENCRYPTION, Enc> Encryption;
0193 typedef BlockCipherFinal<DECRYPTION, Dec> Decryption;
0194 };
0195
0196 typedef Threefish1024::Encryption Threefish1024Encryption;
0197 typedef Threefish1024::Decryption Threefish1024Decryption;
0198
0199 NAMESPACE_END
0200
0201 #endif