16 ANONYMOUS_NAMESPACE_BEGIN
18 using CryptoPP::word32;
19 using CryptoPP::word64;
31 inline void TF83(W& x, W& y,
const W k)
33 x = rotrConstant<8>(x);
35 y = rotlConstant<3>(y);
47 inline void TR83(W& x, W& y,
const W k)
50 y = rotrConstant<3>(y);
52 x = rotlConstant<8>(x);
61 template <
class W,
unsigned int R>
62 inline void SPECK_Encrypt(W c[2],
const W p[2],
const W k[R])
67 for (
int i = 0; i < static_cast<int>(R); ++i)
68 TF83(c[0], c[1], k[i]);
77 template <
class W,
unsigned int R>
78 inline void SPECK_Decrypt(W p[2],
const W c[2],
const W k[R])
83 for (
int i = static_cast<int>(R-1); i >= 0; --i)
84 TR83(p[0], p[1], k[i]);
93 template <
class W,
unsigned int R>
94 inline void SPECK_ExpandKey_2W(W key[R],
const W k[2])
97 W i=0, B=k[0], A=k[1];
101 key[i]=A; TF83(B, A, i);
113 template <
class W,
unsigned int R>
114 inline void SPECK_ExpandKey_3W(W key[R],
const W k[3])
117 W i=0, C=k[0], B=k[1], A=k[2];
119 unsigned int blocks = R/2;
122 key[i+0]=A; TF83(B, A, i+0);
123 key[i+1]=A; TF83(C, A, i+1);
140 template <
class W,
unsigned int R>
141 inline void SPECK_ExpandKey_4W(W key[R],
const W k[4])
144 W i=0, D=k[0], C=k[1], B=k[2], A=k[3];
146 unsigned int blocks = R/3;
149 key[i+0]=A; TF83(B, A, i+0);
150 key[i+1]=A; TF83(C, A, i+1);
151 key[i+2]=A; TF83(D, A, i+2);
162 key[R-2]=A; TF83(B, A, W(R-2));
167 ANONYMOUS_NAMESPACE_END
173 #if (CRYPTOPP_ARM_NEON_AVAILABLE) 174 extern size_t SPECK64_Enc_AdvancedProcessBlocks_NEON(
const word32* subKeys,
size_t rounds,
175 const byte *inBlocks,
const byte *xorBlocks,
byte *outBlocks,
size_t length, word32 flags);
177 extern size_t SPECK64_Dec_AdvancedProcessBlocks_NEON(
const word32* subKeys,
size_t rounds,
178 const byte *inBlocks,
const byte *xorBlocks,
byte *outBlocks,
size_t length, word32 flags);
180 extern size_t SPECK128_Enc_AdvancedProcessBlocks_NEON(
const word64* subKeys,
size_t rounds,
181 const byte *inBlocks,
const byte *xorBlocks,
byte *outBlocks,
size_t length, word32 flags);
183 extern size_t SPECK128_Dec_AdvancedProcessBlocks_NEON(
const word64* subKeys,
size_t rounds,
184 const byte *inBlocks,
const byte *xorBlocks,
byte *outBlocks,
size_t length, word32 flags);
187 #if defined(CRYPTOPP_SSE41_AVAILABLE) 188 extern size_t SPECK64_Enc_AdvancedProcessBlocks_SSE41(
const word32* subKeys,
size_t rounds,
189 const byte *inBlocks,
const byte *xorBlocks,
byte *outBlocks,
size_t length, word32 flags);
191 extern size_t SPECK64_Dec_AdvancedProcessBlocks_SSE41(
const word32* subKeys,
size_t rounds,
192 const byte *inBlocks,
const byte *xorBlocks,
byte *outBlocks,
size_t length, word32 flags);
195 #if defined(CRYPTOPP_SSSE3_AVAILABLE) 196 extern size_t SPECK128_Enc_AdvancedProcessBlocks_SSSE3(
const word64* subKeys,
size_t rounds,
197 const byte *inBlocks,
const byte *xorBlocks,
byte *outBlocks,
size_t length, word32 flags);
199 extern size_t SPECK128_Dec_AdvancedProcessBlocks_SSSE3(
const word64* subKeys,
size_t rounds,
200 const byte *inBlocks,
const byte *xorBlocks,
byte *outBlocks,
size_t length, word32 flags);
203 void SPECK64::Base::UncheckedSetKey(
const byte *userKey,
unsigned int keyLength,
const NameValuePairs ¶ms)
206 CRYPTOPP_UNUSED(params);
210 m_kwords = keyLength/
sizeof(word32);
215 KeyBlock kblk(userKey);
220 m_rkeys.
New((m_rounds = 26));
221 kblk(m_wspace[2])(m_wspace[1])(m_wspace[0]);
222 SPECK_ExpandKey_3W<word32, 26>(m_rkeys, m_wspace);
225 m_rkeys.
New((m_rounds = 27));
226 kblk(m_wspace[3])(m_wspace[2])(m_wspace[1])(m_wspace[0]);
227 SPECK_ExpandKey_4W<word32, 27>(m_rkeys, m_wspace);
234 void SPECK64::Enc::ProcessAndXorBlock(
const byte *inBlock,
const byte *xorBlock,
byte *outBlock)
const 238 InBlock iblk(inBlock); iblk(m_wspace[1])(m_wspace[0]);
243 SPECK_Encrypt<word32, 26>(m_wspace+2, m_wspace+0, m_rkeys);
246 SPECK_Encrypt<word32, 27>(m_wspace+2, m_wspace+0, m_rkeys);
254 OutBlock oblk(xorBlock, outBlock); oblk(m_wspace[3])(m_wspace[2]);
257 void SPECK64::Dec::ProcessAndXorBlock(
const byte *inBlock,
const byte *xorBlock,
byte *outBlock)
const 261 InBlock iblk(inBlock); iblk(m_wspace[1])(m_wspace[0]);
266 SPECK_Decrypt<word32, 26>(m_wspace+2, m_wspace+0, m_rkeys);
269 SPECK_Decrypt<word32, 27>(m_wspace+2, m_wspace+0, m_rkeys);
277 OutBlock oblk(xorBlock, outBlock); oblk(m_wspace[3])(m_wspace[2]);
282 void SPECK128::Base::UncheckedSetKey(
const byte *userKey,
unsigned int keyLength,
const NameValuePairs ¶ms)
284 CRYPTOPP_ASSERT(keyLength == 16 || keyLength == 24 || keyLength == 32);
285 CRYPTOPP_UNUSED(params);
289 m_kwords = keyLength/
sizeof(word64);
294 KeyBlock kblk(userKey);
299 m_rkeys.New((m_rounds = 32));
300 kblk(m_wspace[1])(m_wspace[0]);
301 SPECK_ExpandKey_2W<word64, 32>(m_rkeys, m_wspace);
304 m_rkeys.New((m_rounds = 33));
305 kblk(m_wspace[2])(m_wspace[1])(m_wspace[0]);
306 SPECK_ExpandKey_3W<word64, 33>(m_rkeys, m_wspace);
309 m_rkeys.New((m_rounds = 34));
310 kblk(m_wspace[3])(m_wspace[2])(m_wspace[1])(m_wspace[0]);
311 SPECK_ExpandKey_4W<word64, 34>(m_rkeys, m_wspace);
318 void SPECK128::Enc::ProcessAndXorBlock(
const byte *inBlock,
const byte *xorBlock,
byte *outBlock)
const 322 InBlock iblk(inBlock); iblk(m_wspace[1])(m_wspace[0]);
327 SPECK_Encrypt<word64, 32>(m_wspace+2, m_wspace+0, m_rkeys);
330 SPECK_Encrypt<word64, 33>(m_wspace+2, m_wspace+0, m_rkeys);
333 SPECK_Encrypt<word64, 34>(m_wspace+2, m_wspace+0, m_rkeys);
341 OutBlock oblk(xorBlock, outBlock); oblk(m_wspace[3])(m_wspace[2]);
344 void SPECK128::Dec::ProcessAndXorBlock(
const byte *inBlock,
const byte *xorBlock,
byte *outBlock)
const 348 InBlock iblk(inBlock); iblk(m_wspace[1])(m_wspace[0]);
353 SPECK_Decrypt<word64, 32>(m_wspace+2, m_wspace+0, m_rkeys);
356 SPECK_Decrypt<word64, 33>(m_wspace+2, m_wspace+0, m_rkeys);
359 SPECK_Decrypt<word64, 34>(m_wspace+2, m_wspace+0, m_rkeys);
367 OutBlock oblk(xorBlock, outBlock); oblk(m_wspace[3])(m_wspace[2]);
370 #if defined(CRYPTOPP_SPECK64_ADVANCED_PROCESS_BLOCKS) 371 size_t SPECK64::Enc::AdvancedProcessBlocks(
const byte *inBlocks,
const byte *xorBlocks,
372 byte *outBlocks,
size_t length, word32 flags)
const 374 #if defined(CRYPTOPP_SSE41_AVAILABLE) 376 return SPECK64_Enc_AdvancedProcessBlocks_SSE41(m_rkeys, (
size_t)m_rounds,
377 inBlocks, xorBlocks, outBlocks, length, flags);
379 #if (CRYPTOPP_ARM_NEON_AVAILABLE) 381 return SPECK64_Enc_AdvancedProcessBlocks_NEON(m_rkeys, (
size_t)m_rounds,
382 inBlocks, xorBlocks, outBlocks, length, flags);
387 size_t SPECK64::Dec::AdvancedProcessBlocks(
const byte *inBlocks,
const byte *xorBlocks,
388 byte *outBlocks,
size_t length, word32 flags)
const 390 #if defined(CRYPTOPP_SSE41_AVAILABLE) 392 return SPECK64_Dec_AdvancedProcessBlocks_SSE41(m_rkeys, (
size_t)m_rounds,
393 inBlocks, xorBlocks, outBlocks, length, flags);
395 #if (CRYPTOPP_ARM_NEON_AVAILABLE) 397 return SPECK64_Dec_AdvancedProcessBlocks_NEON(m_rkeys, (
size_t)m_rounds,
398 inBlocks, xorBlocks, outBlocks, length, flags);
402 #endif // CRYPTOPP_SPECK64_ADVANCED_PROCESS_BLOCKS 404 #if defined(CRYPTOPP_SPECK128_ADVANCED_PROCESS_BLOCKS) 405 size_t SPECK128::Enc::AdvancedProcessBlocks(
const byte *inBlocks,
const byte *xorBlocks,
406 byte *outBlocks,
size_t length, word32 flags)
const 408 #if defined(CRYPTOPP_SSSE3_AVAILABLE) 410 return SPECK128_Enc_AdvancedProcessBlocks_SSSE3(m_rkeys, (
size_t)m_rounds,
411 inBlocks, xorBlocks, outBlocks, length, flags);
413 #if (CRYPTOPP_ARM_NEON_AVAILABLE) 415 return SPECK128_Enc_AdvancedProcessBlocks_NEON(m_rkeys, (
size_t)m_rounds,
416 inBlocks, xorBlocks, outBlocks, length, flags);
421 size_t SPECK128::Dec::AdvancedProcessBlocks(
const byte *inBlocks,
const byte *xorBlocks,
422 byte *outBlocks,
size_t length, word32 flags)
const 424 #if defined(CRYPTOPP_SSSE3_AVAILABLE) 426 return SPECK128_Dec_AdvancedProcessBlocks_SSSE3(m_rkeys, (
size_t)m_rounds,
427 inBlocks, xorBlocks, outBlocks, length, flags);
429 #if (CRYPTOPP_ARM_NEON_AVAILABLE) 431 return SPECK128_Dec_AdvancedProcessBlocks_NEON(m_rkeys, (
size_t)m_rounds,
432 inBlocks, xorBlocks, outBlocks, length, flags);
436 #endif // CRYPTOPP_SPECK128_ADVANCED_PROCESS_BLOCKS Utility functions for the Crypto++ library.
bool HasSSSE3()
Determines SSSE3 availability.
Library configuration file.
void New(size_type newSize)
Change size without preserving contents.
T rotlConstant(T x)
Performs a left rotate.
#define CRYPTOPP_ASSERT(exp)
Debugging and diagnostic assertion.
Functions for CPU features and intrinsics.
Classes for the Speck block cipher.
T rotrConstant(T x)
Performs a right rotate.
Access a block of memory.
bool HasSSE41()
Determines SSE4.1 availability.
Access a block of memory.
Crypto++ library namespace.
bool HasNEON()
Determine if an ARM processor has Advanced SIMD available.
Interface for retrieving values given their names.