Fix incorrect SPECK-128 decrypt when blocks >= 6
Add defines for CRYPTOPP_SPECK64_ADVANCED_PROCESS_BLOCKS and CRYPTOPP_SPECK128_ADVANCED_PROCESS_BLOCKSpull/548/head
parent
18ccd89965
commit
f0e49785f6
|
|
@ -234,8 +234,9 @@ inline void SIMON128_Dec_Block(uint8x16_t &block0, const word64 *subkeys, unsign
|
|||
|
||||
if (rounds & 1)
|
||||
{
|
||||
const uint64x2_t rk = vld1q_dup_u64(subkeys + rounds - 1);
|
||||
std::swap(x1, y1);
|
||||
const uint64x2_t rk = vld1q_dup_u64(subkeys + rounds - 1);
|
||||
|
||||
y1 = veorq_u64(veorq_u64(y1, rk), SIMON128_f(x1));
|
||||
rounds--;
|
||||
}
|
||||
|
|
@ -266,7 +267,7 @@ inline void SIMON128_Dec_6_Blocks(uint8x16_t &block0, uint8x16_t &block1,
|
|||
uint64x2_t x2 = UnpackLow64<uint64x2_t>(block2, block3);
|
||||
uint64x2_t y2 = UnpackHigh64<uint64x2_t>(block2, block3);
|
||||
uint64x2_t x3 = UnpackLow64<uint64x2_t>(block4, block5);
|
||||
uint64x2_t y3 = UnpackHigh64<uint64x2_t>(block5, block5);
|
||||
uint64x2_t y3 = UnpackHigh64<uint64x2_t>(block4, block5);
|
||||
|
||||
x1 = Shuffle64(x1); y1 = Shuffle64(y1);
|
||||
x2 = Shuffle64(x2); y2 = Shuffle64(y2);
|
||||
|
|
@ -279,6 +280,7 @@ inline void SIMON128_Dec_6_Blocks(uint8x16_t &block0, uint8x16_t &block1,
|
|||
|
||||
y1 = veorq_u64(veorq_u64(y1, rk), SIMON128_f(x1));
|
||||
y2 = veorq_u64(veorq_u64(y2, rk), SIMON128_f(x2));
|
||||
y3 = veorq_u64(veorq_u64(y3, rk), SIMON128_f(x3));
|
||||
rounds--;
|
||||
}
|
||||
|
||||
|
|
|
|||
|
|
@ -384,7 +384,7 @@ void SIMON128::Dec::ProcessAndXorBlock(const byte *inBlock, const byte *xorBlock
|
|||
OutBlock oblk(xorBlock, outBlock); oblk(m_wspace[2])(m_wspace[3]);
|
||||
}
|
||||
|
||||
#if defined(CRYPTOPP_SIMON_ADVANCED_PROCESS_BLOCKS)
|
||||
#if defined(CRYPTOPP_SIMON64_ADVANCED_PROCESS_BLOCKS)
|
||||
size_t SIMON64::Enc::AdvancedProcessBlocks(const byte *inBlocks, const byte *xorBlocks,
|
||||
byte *outBlocks, size_t length, word32 flags) const
|
||||
{
|
||||
|
|
@ -416,7 +416,9 @@ size_t SIMON64::Dec::AdvancedProcessBlocks(const byte *inBlocks, const byte *xor
|
|||
#endif
|
||||
return BlockTransformation::AdvancedProcessBlocks(inBlocks, xorBlocks, outBlocks, length, flags);
|
||||
}
|
||||
#endif // CRYPTOPP_SIMON64_ADVANCED_PROCESS_BLOCKS
|
||||
|
||||
#if defined(CRYPTOPP_SIMON128_ADVANCED_PROCESS_BLOCKS)
|
||||
size_t SIMON128::Enc::AdvancedProcessBlocks(const byte *inBlocks, const byte *xorBlocks,
|
||||
byte *outBlocks, size_t length, word32 flags) const
|
||||
{
|
||||
|
|
@ -448,6 +450,6 @@ size_t SIMON128::Dec::AdvancedProcessBlocks(const byte *inBlocks, const byte *xo
|
|||
#endif
|
||||
return BlockTransformation::AdvancedProcessBlocks(inBlocks, xorBlocks, outBlocks, length, flags);
|
||||
}
|
||||
#endif
|
||||
#endif // CRYPTOPP_SIMON128_ADVANCED_PROCESS_BLOCKS
|
||||
|
||||
NAMESPACE_END
|
||||
|
|
|
|||
14
simon.h
14
simon.h
|
|
@ -16,8 +16,12 @@
|
|||
#include "seckey.h"
|
||||
#include "secblock.h"
|
||||
|
||||
#if CRYPTOPP_BOOL_X64 || CRYPTOPP_BOOL_X32 || CRYPTOPP_BOOL_X86
|
||||
# define CRYPTOPP_SIMON64_ADVANCED_PROCESS_BLOCKS 1
|
||||
#endif
|
||||
|
||||
#if CRYPTOPP_BOOL_X64 || CRYPTOPP_BOOL_X32 || CRYPTOPP_BOOL_X86 || CRYPTOPP_BOOL_ARM32 || CRYPTOPP_BOOL_ARM64
|
||||
# define CRYPTOPP_SIMON_ADVANCED_PROCESS_BLOCKS 1
|
||||
# define CRYPTOPP_SIMON128_ADVANCED_PROCESS_BLOCKS 1
|
||||
#endif
|
||||
|
||||
NAMESPACE_BEGIN(CryptoPP)
|
||||
|
|
@ -94,7 +98,7 @@ public:
|
|||
{
|
||||
protected:
|
||||
void ProcessAndXorBlock(const byte *inBlock, const byte *xorBlock, byte *outBlock) const;
|
||||
#if CRYPTOPP_SIMON_ADVANCED_PROCESS_BLOCKS
|
||||
#if CRYPTOPP_SIMON64_ADVANCED_PROCESS_BLOCKS
|
||||
size_t AdvancedProcessBlocks(const byte *inBlocks, const byte *xorBlocks, byte *outBlocks, size_t length, word32 flags) const;
|
||||
#endif
|
||||
};
|
||||
|
|
@ -107,7 +111,7 @@ public:
|
|||
{
|
||||
protected:
|
||||
void ProcessAndXorBlock(const byte *inBlock, const byte *xorBlock, byte *outBlock) const;
|
||||
#if CRYPTOPP_SIMON_ADVANCED_PROCESS_BLOCKS
|
||||
#if CRYPTOPP_SIMON64_ADVANCED_PROCESS_BLOCKS
|
||||
size_t AdvancedProcessBlocks(const byte *inBlocks, const byte *xorBlocks, byte *outBlocks, size_t length, word32 flags) const;
|
||||
#endif
|
||||
};
|
||||
|
|
@ -152,7 +156,7 @@ public:
|
|||
{
|
||||
protected:
|
||||
void ProcessAndXorBlock(const byte *inBlock, const byte *xorBlock, byte *outBlock) const;
|
||||
#if CRYPTOPP_SIMON_ADVANCED_PROCESS_BLOCKS
|
||||
#if CRYPTOPP_SIMON128_ADVANCED_PROCESS_BLOCKS
|
||||
size_t AdvancedProcessBlocks(const byte *inBlocks, const byte *xorBlocks, byte *outBlocks, size_t length, word32 flags) const;
|
||||
#endif
|
||||
};
|
||||
|
|
@ -165,7 +169,7 @@ public:
|
|||
{
|
||||
protected:
|
||||
void ProcessAndXorBlock(const byte *inBlock, const byte *xorBlock, byte *outBlock) const;
|
||||
#if CRYPTOPP_SIMON_ADVANCED_PROCESS_BLOCKS
|
||||
#if CRYPTOPP_SIMON128_ADVANCED_PROCESS_BLOCKS
|
||||
size_t AdvancedProcessBlocks(const byte *inBlocks, const byte *xorBlocks, byte *outBlocks, size_t length, word32 flags) const;
|
||||
#endif
|
||||
};
|
||||
|
|
|
|||
|
|
@ -254,7 +254,7 @@ inline void SPECK128_Dec_6_Blocks(uint8x16_t &block0, uint8x16_t &block1,
|
|||
uint64x2_t x2 = UnpackLow64<uint64x2_t>(block2, block3);
|
||||
uint64x2_t y2 = UnpackHigh64<uint64x2_t>(block2, block3);
|
||||
uint64x2_t x3 = UnpackLow64<uint64x2_t>(block4, block5);
|
||||
uint64x2_t y3 = UnpackHigh64<uint64x2_t>(block5, block5);
|
||||
uint64x2_t y3 = UnpackHigh64<uint64x2_t>(block4, block5);
|
||||
|
||||
x1 = Shuffle64(x1);
|
||||
y1 = Shuffle64(y1);
|
||||
|
|
@ -996,10 +996,6 @@ inline size_t SPECK64_AdvancedProcessBlocks_SSE41(F1 func1, F4 func4,
|
|||
}
|
||||
}
|
||||
|
||||
//inBlocks += inIncrement;
|
||||
//xorBlocks += xorIncrement;
|
||||
//outBlocks += outIncrement;
|
||||
|
||||
while (length >= blockSize)
|
||||
{
|
||||
const word32* inPtr = reinterpret_cast<const word32*>(inBlocks);
|
||||
|
|
|
|||
|
|
@ -364,7 +364,7 @@ void SPECK128::Dec::ProcessAndXorBlock(const byte *inBlock, const byte *xorBlock
|
|||
OutBlock oblk(xorBlock, outBlock); oblk(m_wspace[2])(m_wspace[3]);
|
||||
}
|
||||
|
||||
#if defined(CRYPTOPP_SPECK_ADVANCED_PROCESS_BLOCKS)
|
||||
#if defined(CRYPTOPP_SPECK64_ADVANCED_PROCESS_BLOCKS)
|
||||
size_t SPECK64::Enc::AdvancedProcessBlocks(const byte *inBlocks, const byte *xorBlocks,
|
||||
byte *outBlocks, size_t length, word32 flags) const
|
||||
{
|
||||
|
|
@ -386,7 +386,9 @@ size_t SPECK64::Dec::AdvancedProcessBlocks(const byte *inBlocks, const byte *xor
|
|||
#endif
|
||||
return BlockTransformation::AdvancedProcessBlocks(inBlocks, xorBlocks, outBlocks, length, flags);
|
||||
}
|
||||
#endif // CRYPTOPP_SPECK64_ADVANCED_PROCESS_BLOCKS
|
||||
|
||||
#if defined(CRYPTOPP_SPECK128_ADVANCED_PROCESS_BLOCKS)
|
||||
size_t SPECK128::Enc::AdvancedProcessBlocks(const byte *inBlocks, const byte *xorBlocks,
|
||||
byte *outBlocks, size_t length, word32 flags) const
|
||||
{
|
||||
|
|
@ -418,6 +420,6 @@ size_t SPECK128::Dec::AdvancedProcessBlocks(const byte *inBlocks, const byte *xo
|
|||
#endif
|
||||
return BlockTransformation::AdvancedProcessBlocks(inBlocks, xorBlocks, outBlocks, length, flags);
|
||||
}
|
||||
#endif
|
||||
#endif // CRYPTOPP_SPECK128_ADVANCED_PROCESS_BLOCKS
|
||||
|
||||
NAMESPACE_END
|
||||
|
|
|
|||
14
speck.h
14
speck.h
|
|
@ -17,7 +17,11 @@
|
|||
#include "secblock.h"
|
||||
|
||||
#if CRYPTOPP_BOOL_X64 || CRYPTOPP_BOOL_X32 || CRYPTOPP_BOOL_X86 || CRYPTOPP_BOOL_ARM32 || CRYPTOPP_BOOL_ARM64
|
||||
# define CRYPTOPP_SPECK_ADVANCED_PROCESS_BLOCKS 1
|
||||
# define CRYPTOPP_SPECK64_ADVANCED_PROCESS_BLOCKS 1
|
||||
#endif
|
||||
|
||||
#if CRYPTOPP_BOOL_X64 || CRYPTOPP_BOOL_X32 || CRYPTOPP_BOOL_X86 || CRYPTOPP_BOOL_ARM32 || CRYPTOPP_BOOL_ARM64
|
||||
# define CRYPTOPP_SPECK128_ADVANCED_PROCESS_BLOCKS 1
|
||||
#endif
|
||||
|
||||
NAMESPACE_BEGIN(CryptoPP)
|
||||
|
|
@ -94,7 +98,7 @@ public:
|
|||
{
|
||||
protected:
|
||||
void ProcessAndXorBlock(const byte *inBlock, const byte *xorBlock, byte *outBlock) const;
|
||||
#if CRYPTOPP_SPECK_ADVANCED_PROCESS_BLOCKS
|
||||
#if CRYPTOPP_SPECK64_ADVANCED_PROCESS_BLOCKS
|
||||
size_t AdvancedProcessBlocks(const byte *inBlocks, const byte *xorBlocks, byte *outBlocks, size_t length, word32 flags) const;
|
||||
#endif
|
||||
};
|
||||
|
|
@ -107,7 +111,7 @@ public:
|
|||
{
|
||||
protected:
|
||||
void ProcessAndXorBlock(const byte *inBlock, const byte *xorBlock, byte *outBlock) const;
|
||||
#if CRYPTOPP_SPECK_ADVANCED_PROCESS_BLOCKS
|
||||
#if CRYPTOPP_SPECK64_ADVANCED_PROCESS_BLOCKS
|
||||
size_t AdvancedProcessBlocks(const byte *inBlocks, const byte *xorBlocks, byte *outBlocks, size_t length, word32 flags) const;
|
||||
#endif
|
||||
};
|
||||
|
|
@ -152,7 +156,7 @@ public:
|
|||
{
|
||||
protected:
|
||||
void ProcessAndXorBlock(const byte *inBlock, const byte *xorBlock, byte *outBlock) const;
|
||||
#if CRYPTOPP_SPECK_ADVANCED_PROCESS_BLOCKS
|
||||
#if CRYPTOPP_SPECK128_ADVANCED_PROCESS_BLOCKS
|
||||
size_t AdvancedProcessBlocks(const byte *inBlocks, const byte *xorBlocks, byte *outBlocks, size_t length, word32 flags) const;
|
||||
#endif
|
||||
};
|
||||
|
|
@ -165,7 +169,7 @@ public:
|
|||
{
|
||||
protected:
|
||||
void ProcessAndXorBlock(const byte *inBlock, const byte *xorBlock, byte *outBlock) const;
|
||||
#if CRYPTOPP_SPECK_ADVANCED_PROCESS_BLOCKS
|
||||
#if CRYPTOPP_SPECK128_ADVANCED_PROCESS_BLOCKS
|
||||
size_t AdvancedProcessBlocks(const byte *inBlocks, const byte *xorBlocks, byte *outBlocks, size_t length, word32 flags) const;
|
||||
#endif
|
||||
};
|
||||
|
|
|
|||
Loading…
Reference in New Issue