From 20c3d556c320092a0a79744e449fadda47e44946 Mon Sep 17 00:00:00 2001 From: Jeffrey Walton Date: Wed, 10 May 2017 06:30:08 -0400 Subject: [PATCH] Revert "XOR block in specialized ProcessBlock" This reverts commit 76bb4ead40ded06b55b506a85106eae38519b7ee. The Visual Studio project files and other test files were not supposed to be checked-in. --- cryptdll.vcxproj | 21 ++++- cryptest.vcxproj | 19 ++++- cryptest.vcxproj.filters | 5 +- cryptest.vcxproj.user | 9 +-- cryptlib.vcxproj | 14 +++- dlltest.vcxproj | 16 +++- kalyna.cpp | 168 +++++++++++++++++++++++---------------- kalyna.h | 10 +-- regtest2.cpp | 1 - 9 files changed, 173 insertions(+), 90 deletions(-) diff --git a/cryptdll.vcxproj b/cryptdll.vcxproj index e86a9791..9553cd14 100644 --- a/cryptdll.vcxproj +++ b/cryptdll.vcxproj @@ -1,4 +1,4 @@ - + @@ -21,17 +21,20 @@ {94a428a1-9ba8-4db2-b76e-bd2e3c08f257} cryptdll - v110 + v100 DynamicLibrary + + + DynamicLibrary @@ -43,6 +46,7 @@ $(Platform)\DLL_Output\$(Configuration)\ $(Platform)\$(ProjectName)\$(Configuration)\ + @@ -63,6 +67,7 @@ $(TargetDir)\cryptopp.lib + @@ -78,6 +83,7 @@ 0x0409 + @@ -99,6 +105,7 @@ true + @@ -109,6 +116,7 @@ true + @@ -118,6 +126,7 @@ MachineX64 + @@ -133,6 +142,7 @@ Properties="Configuration=Debug;Platform=Win32;"/> --> + Creating Win32/Debug cryptest.exe for MAC computation @@ -142,6 +152,7 @@ + @@ -154,6 +165,7 @@ $(OutDir)cryptopp.mac.done;%(Outputs) + @@ -162,6 +174,7 @@ $(IntDir)x64dll.obj;%(Outputs) + @@ -226,6 +239,7 @@ + @@ -296,6 +310,7 @@ + @@ -304,4 +319,4 @@ - \ No newline at end of file + diff --git a/cryptest.vcxproj b/cryptest.vcxproj index 8fe70017..c857b673 100644 --- a/cryptest.vcxproj +++ b/cryptest.vcxproj @@ -1,4 +1,4 @@ - + @@ -34,14 +34,16 @@ x64 + {09cdac08-e6ae-48a9-8de7-0fbc779eebde} cryptest - v110 + v100 Application + @@ -50,6 +52,7 @@ + Application @@ -59,6 +62,7 @@ MultiByte true + @@ -73,6 +77,7 @@ $(Platform)\DLL_Output\Release\ $(Platform)\$(ProjectName)\$(Configuration)\ + @@ -92,6 +97,7 @@ Console + @@ -107,6 +113,7 @@ 0x0409 + @@ -128,6 +135,7 @@ true + @@ -147,6 +155,7 @@ cryptopp.lib;cryptlib.lib;Ws2_32.lib + @@ -157,6 +166,7 @@ true + @@ -166,6 +176,7 @@ MachineX64 + @@ -179,12 +190,14 @@ + + @@ -202,12 +215,14 @@ + + diff --git a/cryptest.vcxproj.filters b/cryptest.vcxproj.filters index ec0ae192..2d2177b0 100644 --- a/cryptest.vcxproj.filters +++ b/cryptest.vcxproj.filters @@ -1,4 +1,4 @@ - + @@ -75,6 +75,9 @@ TestVectors + + TestVectors + TestVectors diff --git a/cryptest.vcxproj.user b/cryptest.vcxproj.user index 08271a53..ceb23602 100644 --- a/cryptest.vcxproj.user +++ b/cryptest.vcxproj.user @@ -1,9 +1,6 @@ - + - tv kalyna + v - - WindowsLocalDebugger - - \ No newline at end of file + diff --git a/cryptlib.vcxproj b/cryptlib.vcxproj index fcfe505b..22d3e4d7 100644 --- a/cryptlib.vcxproj +++ b/cryptlib.vcxproj @@ -1,4 +1,4 @@ - + @@ -37,7 +37,7 @@ {c39f4b46-6e89-4074-902e-ca57073044d2} cryptlib - v110 + v100 StaticLibrary @@ -50,6 +50,7 @@ + StaticLibrary @@ -59,6 +60,7 @@ MultiByte true + @@ -73,6 +75,7 @@ $(Platform)\DLL_Output\Release\ $(Platform)\$(ProjectName)\$(Configuration)\ + @@ -86,6 +89,7 @@ NoErrorReport + @@ -101,6 +105,7 @@ 0x0409 + @@ -118,6 +123,7 @@ 0x0409 + @@ -129,6 +135,7 @@ NDEBUG;USE_PRECOMPILED_HEADERS;CRYPTOPP_IMPORTS;%(PreprocessorDefinitions) + @@ -139,6 +146,7 @@ true + @@ -148,7 +156,9 @@ MachineX64 + + diff --git a/dlltest.vcxproj b/dlltest.vcxproj index c82c557a..f008456c 100644 --- a/dlltest.vcxproj +++ b/dlltest.vcxproj @@ -1,4 +1,4 @@ - + @@ -21,17 +21,20 @@ {1974a53a-9863-41c9-886d-b2b8c2fc3c8b} dlltest - v110 + v100 Application + + + Application @@ -41,6 +44,7 @@ $(Platform)\DLL_Output\$(Configuration)\ $(Platform)\$(ProjectName)\$(Configuration)\ + @@ -57,6 +61,7 @@ true + @@ -72,6 +77,7 @@ 0x0409 + @@ -93,6 +99,7 @@ true + @@ -103,6 +110,7 @@ true + @@ -112,12 +120,14 @@ MachineX64 + + - \ No newline at end of file + diff --git a/kalyna.cpp b/kalyna.cpp index eba64846..864f139d 100644 --- a/kalyna.cpp +++ b/kalyna.cpp @@ -929,16 +929,20 @@ void Kalyna::Base::SetKey_88(const word64 key[8]) // *********************** ProcessAndXorBlock specializations *********************** // -void Kalyna::Base::ProcessBlock_22(const word64 inBlock[2], const word64 xorBlock[2], word64 outBlock[2]) const +void Kalyna::Base::ProcessBlock_22(const word64 inBlock[2], word64 outBlock[2]) const { +#if defined(IS_BIG_ENDIAN) word64 *t1 = m_wspace+0, *t2 = m_wspace+2, *msg = m_wspace+4; + { + typedef GetBlock Block; + Block block(inBlock); + block(msg[0])(msg[1]); + inBlock = msg; + } +#else + word64 *t1 = outBlock, *t2 = m_wspace+2; +#endif - // Reverse bytes on BigEndian; Align pointer on LittleEndian - typedef GetBlock InBlock; - InBlock iblk(inBlock); - iblk(msg[0])(msg[1]); - - inBlock = msg; if (IsForwardTransformation()) { AddKey<2>(inBlock, t1, m_rkeys); @@ -969,22 +973,29 @@ void Kalyna::Base::ProcessBlock_22(const word64 inBlock[2], const word64 xorBloc IGL128(t2, t1, &m_rkeys[0]); } - // Reverse bytes on BigEndian; Align pointer on LittleEndian - typedef PutBlock OutBlock; - OutBlock oblk(xorBlock, outBlock); - oblk(t1[0])(t1[1]); +#if defined(IS_BIG_ENDIAN) + { + typedef GetBlock Block; + Block block(t1); + block(outBlock[0])(outBlock[1]); + } +#endif } -void Kalyna::Base::ProcessBlock_24(const word64 inBlock[2], const word64 xorBlock[2], word64 outBlock[2]) const +void Kalyna::Base::ProcessBlock_24(const word64 inBlock[2], word64 outBlock[2]) const { +#if defined(IS_BIG_ENDIAN) word64 *t1 = m_wspace+0, *t2 = m_wspace+2, *msg = m_wspace+4; + { + typedef GetBlock Block; + Block block(inBlock); + block(msg[0])(msg[1]); + inBlock = msg; + } +#else + word64 *t1 = outBlock, *t2 = m_wspace+2; +#endif - // Reverse bytes on BigEndian; Align pointer on LittleEndian - typedef GetBlock InBlock; - InBlock iblk(inBlock); - iblk(msg[0])(msg[1]); - - inBlock = msg; if (IsForwardTransformation()) { AddKey<2>(inBlock, t1, m_rkeys); @@ -1023,22 +1034,29 @@ void Kalyna::Base::ProcessBlock_24(const word64 inBlock[2], const word64 xorBloc IGL128(t2, t1, &m_rkeys[0]); } - // Reverse bytes on BigEndian; Align pointer on LittleEndian - typedef PutBlock OutBlock; - OutBlock oblk(xorBlock, outBlock); - oblk(t1[0])(t1[1]); +#if defined(IS_BIG_ENDIAN) + { + typedef GetBlock Block; + Block block(t1); + block(outBlock[0])(outBlock[1]); + } +#endif } -void Kalyna::Base::ProcessBlock_44(const word64 inBlock[4], const word64 xorBlock[4], word64 outBlock[4]) const +void Kalyna::Base::ProcessBlock_44(const word64 inBlock[4], word64 outBlock[4]) const { +#if defined(IS_BIG_ENDIAN) word64 *t1 = m_wspace+0, *t2 = m_wspace+4, *msg = m_wspace+8; + { + typedef GetBlock Block; + Block block(inBlock); + block(msg[0])(msg[1])(msg[2])(msg[3]); + inBlock = msg; + } +#else + word64 *t1 = outBlock, *t2 = m_wspace+4; +#endif - // Reverse bytes on BigEndian; Align pointer on LittleEndian - typedef GetBlock InBlock; - InBlock iblk(inBlock); - iblk(msg[0])(msg[1])(msg[2])(msg[3]); - - inBlock = msg; if (IsForwardTransformation()) { AddKey<4>(inBlock, t1, m_rkeys); @@ -1077,25 +1095,32 @@ void Kalyna::Base::ProcessBlock_44(const word64 inBlock[4], const word64 xorBloc IGL256(t2, t1, &m_rkeys[0]); } - // Reverse bytes on BigEndian; Align pointer on LittleEndian - typedef PutBlock OutBlock; - OutBlock oblk(xorBlock, outBlock); - oblk(t1[0])(t1[1])(t1[2])(t1[3]); +#if defined(IS_BIG_ENDIAN) + { + typedef GetBlock Block; + Block block(t1); + block(outBlock[0])(outBlock[1])(outBlock[2])(outBlock[3]); + } +#endif } -void Kalyna::Base::ProcessBlock_48(const word64 inBlock[4], const word64 xorBlock[4], word64 outBlock[4]) const +void Kalyna::Base::ProcessBlock_48(const word64 inBlock[4], word64 outBlock[4]) const { +#if defined(IS_BIG_ENDIAN) word64 *t1 = m_wspace+0, *t2 = m_wspace+4, *msg = m_wspace+8; + { + typedef GetBlock Block; + Block block(inBlock); + block(msg[0])(msg[1])(msg[2])(msg[3]); + inBlock = msg; + } +#else + word64 *t1 = outBlock, *t2 = m_wspace+4; +#endif - // Reverse bytes on BigEndian; Align pointer on LittleEndian - typedef GetBlock InBlock; - InBlock iblk(inBlock); - iblk(msg[0])(msg[1])(msg[2])(msg[3]); - - inBlock = msg; if (IsForwardTransformation()) { - AddKey<4>(inBlock, t1, m_rkeys); + AddKey<4>((const word64*)inBlock, t1, m_rkeys); G256(t1, t2, &m_rkeys[4]); // 1 G256(t2, t1, &m_rkeys[8]); // 2 G256(t1, t2, &m_rkeys[12]); // 3 @@ -1139,22 +1164,29 @@ void Kalyna::Base::ProcessBlock_48(const word64 inBlock[4], const word64 xorBloc IGL256(t2, t1, &m_rkeys[0]); } - // Reverse bytes on BigEndian; Align pointer on LittleEndian - typedef PutBlock OutBlock; - OutBlock oblk(xorBlock, outBlock); - oblk(t1[0])(t1[1])(t1[2])(t1[3]); +#if defined(IS_BIG_ENDIAN) + { + typedef GetBlock Block; + Block block(t1); + block(outBlock[0])(outBlock[1])(outBlock[2])(outBlock[3]); + } +#endif } -void Kalyna::Base::ProcessBlock_88(const word64 inBlock[8], const word64 xorBlock[8], word64 outBlock[8]) const +void Kalyna::Base::ProcessBlock_88(const word64 inBlock[8], word64 outBlock[8]) const { +#if defined(IS_BIG_ENDIAN) word64 *t1 = m_wspace+0, *t2 = m_wspace+8, *msg = m_wspace+16; + { + typedef GetBlock Block; + Block block(inBlock); + block(msg[0])(msg[1])(msg[2])(msg[3])(msg[4])(msg[5])(msg[6])(msg[7]); + inBlock = msg; + } +#else + word64 *t1 = outBlock, *t2 = m_wspace+8; +#endif - // Reverse bytes on BigEndian; Align pointer on LittleEndian - typedef GetBlock InBlock; - InBlock iblk(inBlock); - iblk(msg[0])(msg[1])(msg[2])(msg[3])(msg[4])(msg[5])(msg[6])(msg[7]); - - inBlock = msg; if (IsForwardTransformation()) { AddKey<8>(inBlock, t1, m_rkeys); @@ -1201,10 +1233,14 @@ void Kalyna::Base::ProcessBlock_88(const word64 inBlock[8], const word64 xorBloc IGL512(t2, t1, &m_rkeys[0]); } - // Reverse bytes on BigEndian; Align pointer on LittleEndian - typedef PutBlock OutBlock; - OutBlock oblk(xorBlock, outBlock); - oblk(t1[0])(t1[1])(t1[2])(t1[3])(t1[4])(t1[5])(t1[6])(t1[7]); +#if defined(IS_BIG_ENDIAN) + { + typedef GetBlock Block; + Block block(t1); + block(outBlock[0])(outBlock[1])(outBlock[2])(outBlock[3]) + (outBlock[4])(outBlock[5])(outBlock[6])(outBlock[7]); + } +#endif } // *********************** Library routines *********************** // @@ -1288,34 +1324,32 @@ void Kalyna::Base::ProcessAndXorBlock(const byte *inBlock, const byte *xorBlock, const byte* p = reinterpret_cast(KalynaTab::S); for (unsigned int i=0; i<256; i+=cacheLineSize) - u ^= *reinterpret_cast(p+i); + u &= *reinterpret_cast(p+i); m_wspace[0] = u; switch ((m_nb << 8) | m_nk) { case (2 << 8) | 2: - ProcessBlock_22(reinterpret_cast(inBlock), - reinterpret_cast(xorBlock), reinterpret_cast(outBlock)); + ProcessBlock_22(reinterpret_cast(inBlock), reinterpret_cast(outBlock)); break; case (2 << 8) | 4: - ProcessBlock_24(reinterpret_cast(inBlock), - reinterpret_cast(xorBlock), reinterpret_cast(outBlock)); + ProcessBlock_24(reinterpret_cast(inBlock), reinterpret_cast(outBlock)); break; case (4 << 8) | 4: - ProcessBlock_44(reinterpret_cast(inBlock), - reinterpret_cast(xorBlock), reinterpret_cast(outBlock)); + ProcessBlock_44(reinterpret_cast(inBlock), reinterpret_cast(outBlock)); break; case (4 << 8) | 8: - ProcessBlock_48(reinterpret_cast(inBlock), - reinterpret_cast(xorBlock), reinterpret_cast(outBlock)); + ProcessBlock_48(reinterpret_cast(inBlock), reinterpret_cast(outBlock)); break; case (8 << 8) | 8: - ProcessBlock_88(reinterpret_cast(inBlock), - reinterpret_cast(xorBlock), reinterpret_cast(outBlock)); + ProcessBlock_88(reinterpret_cast(inBlock), reinterpret_cast(outBlock)); break; default: CRYPTOPP_ASSERT(0); } + + for (size_t i=0; xorBlock && i // void ProcessBlock_Template(const word64 inBlock[NB], const word64 outBlock[NB]) const; - void ProcessBlock_22(const word64 inBlock[2], const word64 xorBlock[2], word64 outBlock[2]) const; - void ProcessBlock_24(const word64 inBlock[2], const word64 xorBlock[2] ,word64 outBlock[2]) const; - void ProcessBlock_44(const word64 inBlock[4], const word64 xorBlock[4], word64 outBlock[4]) const; - void ProcessBlock_48(const word64 inBlock[4], const word64 xorBlock[4], word64 outBlock[4]) const; - void ProcessBlock_88(const word64 inBlock[8], const word64 xorBlock[8], word64 outBlock[8]) const; + void ProcessBlock_22(const word64 inBlock[2], word64 outBlock[2]) const; + void ProcessBlock_24(const word64 inBlock[2], word64 outBlock[2]) const; + void ProcessBlock_44(const word64 inBlock[4], word64 outBlock[4]) const; + void ProcessBlock_48(const word64 inBlock[4], word64 outBlock[4]) const; + void ProcessBlock_88(const word64 inBlock[8], word64 outBlock[8]) const; private: typedef SecBlock > AlignedSecBlock64; diff --git a/regtest2.cpp b/regtest2.cpp index 0e9d3d2d..b5528869 100644 --- a/regtest2.cpp +++ b/regtest2.cpp @@ -135,7 +135,6 @@ void RegisterFactories2() RegisterSymmetricCipherDefaultFactories >(); RegisterSymmetricCipherDefaultFactories >(); RegisterSymmetricCipherDefaultFactories >(); // Test Vectors - RegisterSymmetricCipherDefaultFactories >(); // Test Vectors RegisterSymmetricCipherDefaultFactories >(); // Benchmarks RegisterDefaultFactoryFor >();