XOR block in specialized ProcessBlock
Use Put and Get blocks consistentlypull/416/head
parent
20c3d556c3
commit
3bee1f57cf
168
kalyna.cpp
168
kalyna.cpp
|
|
@ -929,20 +929,16 @@ void Kalyna::Base::SetKey_88(const word64 key[8])
|
||||||
|
|
||||||
// *********************** ProcessAndXorBlock specializations *********************** //
|
// *********************** ProcessAndXorBlock specializations *********************** //
|
||||||
|
|
||||||
void Kalyna::Base::ProcessBlock_22(const word64 inBlock[2], word64 outBlock[2]) const
|
void Kalyna::Base::ProcessBlock_22(const word64 inBlock[2], const word64 xorBlock[2], word64 outBlock[2]) const
|
||||||
{
|
{
|
||||||
#if defined(IS_BIG_ENDIAN)
|
|
||||||
word64 *t1 = m_wspace+0, *t2 = m_wspace+2, *msg = m_wspace+4;
|
word64 *t1 = m_wspace+0, *t2 = m_wspace+2, *msg = m_wspace+4;
|
||||||
{
|
|
||||||
typedef GetBlock<word64, LittleEndian, false> 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<word64, LittleEndian, false> InBlock;
|
||||||
|
InBlock iblk(inBlock);
|
||||||
|
iblk(msg[0])(msg[1]);
|
||||||
|
|
||||||
|
inBlock = msg;
|
||||||
if (IsForwardTransformation())
|
if (IsForwardTransformation())
|
||||||
{
|
{
|
||||||
AddKey<2>(inBlock, t1, m_rkeys);
|
AddKey<2>(inBlock, t1, m_rkeys);
|
||||||
|
|
@ -973,29 +969,22 @@ void Kalyna::Base::ProcessBlock_22(const word64 inBlock[2], word64 outBlock[2])
|
||||||
IGL128(t2, t1, &m_rkeys[0]);
|
IGL128(t2, t1, &m_rkeys[0]);
|
||||||
}
|
}
|
||||||
|
|
||||||
#if defined(IS_BIG_ENDIAN)
|
// Reverse bytes on BigEndian; Align pointer on LittleEndian
|
||||||
{
|
typedef PutBlock<word64, LittleEndian, false> OutBlock;
|
||||||
typedef GetBlock<word64, LittleEndian, false> Block;
|
OutBlock oblk(xorBlock, outBlock);
|
||||||
Block block(t1);
|
oblk(t1[0])(t1[1]);
|
||||||
block(outBlock[0])(outBlock[1]);
|
|
||||||
}
|
|
||||||
#endif
|
|
||||||
}
|
}
|
||||||
|
|
||||||
void Kalyna::Base::ProcessBlock_24(const word64 inBlock[2], word64 outBlock[2]) const
|
void Kalyna::Base::ProcessBlock_24(const word64 inBlock[2], const word64 xorBlock[2], word64 outBlock[2]) const
|
||||||
{
|
{
|
||||||
#if defined(IS_BIG_ENDIAN)
|
|
||||||
word64 *t1 = m_wspace+0, *t2 = m_wspace+2, *msg = m_wspace+4;
|
word64 *t1 = m_wspace+0, *t2 = m_wspace+2, *msg = m_wspace+4;
|
||||||
{
|
|
||||||
typedef GetBlock<word64, LittleEndian, false> 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<word64, LittleEndian, false> InBlock;
|
||||||
|
InBlock iblk(inBlock);
|
||||||
|
iblk(msg[0])(msg[1]);
|
||||||
|
|
||||||
|
inBlock = msg;
|
||||||
if (IsForwardTransformation())
|
if (IsForwardTransformation())
|
||||||
{
|
{
|
||||||
AddKey<2>(inBlock, t1, m_rkeys);
|
AddKey<2>(inBlock, t1, m_rkeys);
|
||||||
|
|
@ -1034,29 +1023,22 @@ void Kalyna::Base::ProcessBlock_24(const word64 inBlock[2], word64 outBlock[2])
|
||||||
IGL128(t2, t1, &m_rkeys[0]);
|
IGL128(t2, t1, &m_rkeys[0]);
|
||||||
}
|
}
|
||||||
|
|
||||||
#if defined(IS_BIG_ENDIAN)
|
// Reverse bytes on BigEndian; Align pointer on LittleEndian
|
||||||
{
|
typedef PutBlock<word64, LittleEndian, false> OutBlock;
|
||||||
typedef GetBlock<word64, LittleEndian, false> Block;
|
OutBlock oblk(xorBlock, outBlock);
|
||||||
Block block(t1);
|
oblk(t1[0])(t1[1]);
|
||||||
block(outBlock[0])(outBlock[1]);
|
|
||||||
}
|
|
||||||
#endif
|
|
||||||
}
|
}
|
||||||
|
|
||||||
void Kalyna::Base::ProcessBlock_44(const word64 inBlock[4], word64 outBlock[4]) const
|
void Kalyna::Base::ProcessBlock_44(const word64 inBlock[4], const word64 xorBlock[4], word64 outBlock[4]) const
|
||||||
{
|
{
|
||||||
#if defined(IS_BIG_ENDIAN)
|
|
||||||
word64 *t1 = m_wspace+0, *t2 = m_wspace+4, *msg = m_wspace+8;
|
word64 *t1 = m_wspace+0, *t2 = m_wspace+4, *msg = m_wspace+8;
|
||||||
{
|
|
||||||
typedef GetBlock<word64, LittleEndian, false> 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<word64, LittleEndian, false> InBlock;
|
||||||
|
InBlock iblk(inBlock);
|
||||||
|
iblk(msg[0])(msg[1])(msg[2])(msg[3]);
|
||||||
|
|
||||||
|
inBlock = msg;
|
||||||
if (IsForwardTransformation())
|
if (IsForwardTransformation())
|
||||||
{
|
{
|
||||||
AddKey<4>(inBlock, t1, m_rkeys);
|
AddKey<4>(inBlock, t1, m_rkeys);
|
||||||
|
|
@ -1095,32 +1077,25 @@ void Kalyna::Base::ProcessBlock_44(const word64 inBlock[4], word64 outBlock[4])
|
||||||
IGL256(t2, t1, &m_rkeys[0]);
|
IGL256(t2, t1, &m_rkeys[0]);
|
||||||
}
|
}
|
||||||
|
|
||||||
#if defined(IS_BIG_ENDIAN)
|
// Reverse bytes on BigEndian; Align pointer on LittleEndian
|
||||||
{
|
typedef PutBlock<word64, LittleEndian, false> OutBlock;
|
||||||
typedef GetBlock<word64, LittleEndian, false> Block;
|
OutBlock oblk(xorBlock, outBlock);
|
||||||
Block block(t1);
|
oblk(t1[0])(t1[1])(t1[2])(t1[3]);
|
||||||
block(outBlock[0])(outBlock[1])(outBlock[2])(outBlock[3]);
|
|
||||||
}
|
|
||||||
#endif
|
|
||||||
}
|
}
|
||||||
|
|
||||||
void Kalyna::Base::ProcessBlock_48(const word64 inBlock[4], word64 outBlock[4]) const
|
void Kalyna::Base::ProcessBlock_48(const word64 inBlock[4], const word64 xorBlock[4], word64 outBlock[4]) const
|
||||||
{
|
{
|
||||||
#if defined(IS_BIG_ENDIAN)
|
|
||||||
word64 *t1 = m_wspace+0, *t2 = m_wspace+4, *msg = m_wspace+8;
|
word64 *t1 = m_wspace+0, *t2 = m_wspace+4, *msg = m_wspace+8;
|
||||||
{
|
|
||||||
typedef GetBlock<word64, LittleEndian, false> 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<word64, LittleEndian, false> InBlock;
|
||||||
|
InBlock iblk(inBlock);
|
||||||
|
iblk(msg[0])(msg[1])(msg[2])(msg[3]);
|
||||||
|
|
||||||
|
inBlock = msg;
|
||||||
if (IsForwardTransformation())
|
if (IsForwardTransformation())
|
||||||
{
|
{
|
||||||
AddKey<4>((const word64*)inBlock, t1, m_rkeys);
|
AddKey<4>(inBlock, t1, m_rkeys);
|
||||||
G256(t1, t2, &m_rkeys[4]); // 1
|
G256(t1, t2, &m_rkeys[4]); // 1
|
||||||
G256(t2, t1, &m_rkeys[8]); // 2
|
G256(t2, t1, &m_rkeys[8]); // 2
|
||||||
G256(t1, t2, &m_rkeys[12]); // 3
|
G256(t1, t2, &m_rkeys[12]); // 3
|
||||||
|
|
@ -1164,29 +1139,22 @@ void Kalyna::Base::ProcessBlock_48(const word64 inBlock[4], word64 outBlock[4])
|
||||||
IGL256(t2, t1, &m_rkeys[0]);
|
IGL256(t2, t1, &m_rkeys[0]);
|
||||||
}
|
}
|
||||||
|
|
||||||
#if defined(IS_BIG_ENDIAN)
|
// Reverse bytes on BigEndian; Align pointer on LittleEndian
|
||||||
{
|
typedef PutBlock<word64, LittleEndian, false> OutBlock;
|
||||||
typedef GetBlock<word64, LittleEndian, false> Block;
|
OutBlock oblk(xorBlock, outBlock);
|
||||||
Block block(t1);
|
oblk(t1[0])(t1[1])(t1[2])(t1[3]);
|
||||||
block(outBlock[0])(outBlock[1])(outBlock[2])(outBlock[3]);
|
|
||||||
}
|
|
||||||
#endif
|
|
||||||
}
|
}
|
||||||
|
|
||||||
void Kalyna::Base::ProcessBlock_88(const word64 inBlock[8], word64 outBlock[8]) const
|
void Kalyna::Base::ProcessBlock_88(const word64 inBlock[8], const word64 xorBlock[8], word64 outBlock[8]) const
|
||||||
{
|
{
|
||||||
#if defined(IS_BIG_ENDIAN)
|
|
||||||
word64 *t1 = m_wspace+0, *t2 = m_wspace+8, *msg = m_wspace+16;
|
word64 *t1 = m_wspace+0, *t2 = m_wspace+8, *msg = m_wspace+16;
|
||||||
{
|
|
||||||
typedef GetBlock<word64, LittleEndian, false> 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<word64, LittleEndian, false> 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())
|
if (IsForwardTransformation())
|
||||||
{
|
{
|
||||||
AddKey<8>(inBlock, t1, m_rkeys);
|
AddKey<8>(inBlock, t1, m_rkeys);
|
||||||
|
|
@ -1233,14 +1201,10 @@ void Kalyna::Base::ProcessBlock_88(const word64 inBlock[8], word64 outBlock[8])
|
||||||
IGL512(t2, t1, &m_rkeys[0]);
|
IGL512(t2, t1, &m_rkeys[0]);
|
||||||
}
|
}
|
||||||
|
|
||||||
#if defined(IS_BIG_ENDIAN)
|
// Reverse bytes on BigEndian; Align pointer on LittleEndian
|
||||||
{
|
typedef PutBlock<word64, LittleEndian, false> OutBlock;
|
||||||
typedef GetBlock<word64, LittleEndian, false> Block;
|
OutBlock oblk(xorBlock, outBlock);
|
||||||
Block block(t1);
|
oblk(t1[0])(t1[1])(t1[2])(t1[3])(t1[4])(t1[5])(t1[6])(t1[7]);
|
||||||
block(outBlock[0])(outBlock[1])(outBlock[2])(outBlock[3])
|
|
||||||
(outBlock[4])(outBlock[5])(outBlock[6])(outBlock[7]);
|
|
||||||
}
|
|
||||||
#endif
|
|
||||||
}
|
}
|
||||||
|
|
||||||
// *********************** Library routines *********************** //
|
// *********************** Library routines *********************** //
|
||||||
|
|
@ -1324,32 +1288,34 @@ void Kalyna::Base::ProcessAndXorBlock(const byte *inBlock, const byte *xorBlock,
|
||||||
|
|
||||||
const byte* p = reinterpret_cast<const byte*>(KalynaTab::S);
|
const byte* p = reinterpret_cast<const byte*>(KalynaTab::S);
|
||||||
for (unsigned int i=0; i<256; i+=cacheLineSize)
|
for (unsigned int i=0; i<256; i+=cacheLineSize)
|
||||||
u &= *reinterpret_cast<const word64*>(p+i);
|
u ^= *reinterpret_cast<const word64*>(p+i);
|
||||||
m_wspace[0] = u;
|
m_wspace[0] = u;
|
||||||
|
|
||||||
switch ((m_nb << 8) | m_nk)
|
switch ((m_nb << 8) | m_nk)
|
||||||
{
|
{
|
||||||
case (2 << 8) | 2:
|
case (2 << 8) | 2:
|
||||||
ProcessBlock_22(reinterpret_cast<const word64*>(inBlock), reinterpret_cast<word64*>(outBlock));
|
ProcessBlock_22(reinterpret_cast<const word64*>(inBlock),
|
||||||
|
reinterpret_cast<const word64*>(xorBlock), reinterpret_cast<word64*>(outBlock));
|
||||||
break;
|
break;
|
||||||
case (2 << 8) | 4:
|
case (2 << 8) | 4:
|
||||||
ProcessBlock_24(reinterpret_cast<const word64*>(inBlock), reinterpret_cast<word64*>(outBlock));
|
ProcessBlock_24(reinterpret_cast<const word64*>(inBlock),
|
||||||
|
reinterpret_cast<const word64*>(xorBlock), reinterpret_cast<word64*>(outBlock));
|
||||||
break;
|
break;
|
||||||
case (4 << 8) | 4:
|
case (4 << 8) | 4:
|
||||||
ProcessBlock_44(reinterpret_cast<const word64*>(inBlock), reinterpret_cast<word64*>(outBlock));
|
ProcessBlock_44(reinterpret_cast<const word64*>(inBlock),
|
||||||
|
reinterpret_cast<const word64*>(xorBlock), reinterpret_cast<word64*>(outBlock));
|
||||||
break;
|
break;
|
||||||
case (4 << 8) | 8:
|
case (4 << 8) | 8:
|
||||||
ProcessBlock_48(reinterpret_cast<const word64*>(inBlock), reinterpret_cast<word64*>(outBlock));
|
ProcessBlock_48(reinterpret_cast<const word64*>(inBlock),
|
||||||
|
reinterpret_cast<const word64*>(xorBlock), reinterpret_cast<word64*>(outBlock));
|
||||||
break;
|
break;
|
||||||
case (8 << 8) | 8:
|
case (8 << 8) | 8:
|
||||||
ProcessBlock_88(reinterpret_cast<const word64*>(inBlock), reinterpret_cast<word64*>(outBlock));
|
ProcessBlock_88(reinterpret_cast<const word64*>(inBlock),
|
||||||
|
reinterpret_cast<const word64*>(xorBlock), reinterpret_cast<word64*>(outBlock));
|
||||||
break;
|
break;
|
||||||
default:
|
default:
|
||||||
CRYPTOPP_ASSERT(0);
|
CRYPTOPP_ASSERT(0);
|
||||||
}
|
}
|
||||||
|
|
||||||
for (size_t i=0; xorBlock && i<m_nb; ++i)
|
|
||||||
outBlock[i] ^= xorBlock[i];
|
|
||||||
}
|
}
|
||||||
|
|
||||||
NAMESPACE_END
|
NAMESPACE_END
|
||||||
|
|
|
||||||
10
kalyna.h
10
kalyna.h
|
|
@ -134,11 +134,11 @@ public:
|
||||||
// Visual Studio and C2910: 'Kalyna::Base::ProcessBlock_Template': cannot be explicitly specialized
|
// Visual Studio and C2910: 'Kalyna::Base::ProcessBlock_Template': cannot be explicitly specialized
|
||||||
//template <unsigned int NB, unsigned int NK>
|
//template <unsigned int NB, unsigned int NK>
|
||||||
// void ProcessBlock_Template(const word64 inBlock[NB], const word64 outBlock[NB]) const;
|
// void ProcessBlock_Template(const word64 inBlock[NB], const word64 outBlock[NB]) const;
|
||||||
void ProcessBlock_22(const word64 inBlock[2], word64 outBlock[2]) const;
|
void ProcessBlock_22(const word64 inBlock[2], const word64 xorBlock[2], word64 outBlock[2]) const;
|
||||||
void ProcessBlock_24(const word64 inBlock[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], word64 outBlock[4]) const;
|
void ProcessBlock_44(const word64 inBlock[4], const word64 xorBlock[4], word64 outBlock[4]) const;
|
||||||
void ProcessBlock_48(const word64 inBlock[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], word64 outBlock[8]) const;
|
void ProcessBlock_88(const word64 inBlock[8], const word64 xorBlock[8], word64 outBlock[8]) const;
|
||||||
|
|
||||||
private:
|
private:
|
||||||
typedef SecBlock<word64, AllocatorWithCleanup<word64, true> > AlignedSecBlock64;
|
typedef SecBlock<word64, AllocatorWithCleanup<word64, true> > AlignedSecBlock64;
|
||||||
|
|
|
||||||
Loading…
Reference in New Issue