00001
00002
00003 #include "pch.h"
00004
00005 #include "wake.h"
00006 #include "smartptr.h"
00007
00008 NAMESPACE_BEGIN(CryptoPP)
00009
00010 #if !defined(NDEBUG) && !defined(CRYPTOPP_DOXYGEN_PROCESSING)
00011 void WAKE_TestInstantiations()
00012 {
00013 WAKE_OFB<>::Encryption x2;
00014 WAKE_OFB<>::Decryption x4;
00015 }
00016 #endif
00017
00018 inline word32 WAKE_Base::M(word32 x, word32 y)
00019 {
00020 word32 w = x+y;
00021 return (w>>8) ^ t[w & 0xff];
00022 }
00023
00024 void WAKE_Base::GenKey(word32 k0, word32 k1, word32 k2, word32 k3)
00025 {
00026
00027 signed int x, z, p;
00028
00029 CRYPTOPP_COMPILE_ASSERT(sizeof(x) == 4);
00030 static unsigned int tt[10]= {
00031 0x726a8f3b,
00032 0xe69a3b5c,
00033 0xd3c71fe5,
00034 0xab3c73d2,
00035 0x4d3a8eb3,
00036 0x0396d6e8,
00037 0x3d4c2f7a,
00038 0x9ee27cf3, } ;
00039 t[0] = k0;
00040 t[1] = k1;
00041 t[2] = k2;
00042 t[3] = k3;
00043 for (p=4 ; p<256 ; p++)
00044 {
00045 x=t[p-4]+t[p-1] ;
00046 t[p]= (x>>3) ^ tt[x&7] ;
00047 }
00048
00049 for (p=0 ; p<23 ; p++)
00050 t[p]+=t[p+89] ;
00051 x=t[33] ; z=t[59] | 0x01000001 ;
00052 z=z&0xff7fffff ;
00053 for (p=0 ; p<256 ; p++) {
00054 x=(x&0xff7fffff)+z ;
00055 t[p]=(t[p] & 0x00ffffff) ^ x ; }
00056
00057 t[256]=t[0] ;
00058 byte y=byte(x);
00059 for (p=0 ; p<256 ; p++) {
00060 t[p]=t[y=byte(t[p^y]^y)] ;
00061 t[y]=t[p+1] ; }
00062 }
00063
00064 template <class B>
00065 void WAKE_Policy<B>::CipherSetKey(const NameValuePairs ¶ms, const byte *key, size_t length)
00066 {
00067 CRYPTOPP_UNUSED(params); CRYPTOPP_UNUSED(key); CRYPTOPP_UNUSED(length);
00068 word32 k0, k1, k2, k3;
00069 BlockGetAndPut<word32, BigEndian>::Get(key)(r3)(r4)(r5)(r6)(k0)(k1)(k2)(k3);
00070 GenKey(k0, k1, k2, k3);
00071 }
00072
00073
00074 template <class B>
00075 void WAKE_Policy<B>::OperateKeystream(KeystreamOperation operation, byte *output, const byte *input, size_t iterationCount)
00076 {
00077 #define WAKE_OUTPUT(x)\
00078 while (iterationCount--)\
00079 {\
00080 CRYPTOPP_KEYSTREAM_OUTPUT_WORD(x, B::ToEnum(), 0, r6);\
00081 r3 = M(r3, r6);\
00082 r4 = M(r4, r3);\
00083 r5 = M(r5, r4);\
00084 r6 = M(r6, r5);\
00085 output += 4;\
00086 if (!(x & INPUT_NULL))\
00087 input += 4;\
00088 }
00089
00090 typedef word32 WordType;
00091 CRYPTOPP_KEYSTREAM_OUTPUT_SWITCH(WAKE_OUTPUT, 0);
00092 }
00093
00094
00095
00096
00097
00098
00099
00100
00101
00102
00103
00104
00105
00106
00107
00108
00109 template class WAKE_Policy<BigEndian>;
00110 template class WAKE_Policy<LittleEndian>;
00111
00112
00113
00114 NAMESPACE_END