summaryrefslogtreecommitdiff
path: root/speck.cpp
diff options
context:
space:
mode:
Diffstat (limited to 'speck.cpp')
-rw-r--r--speck.cpp52
1 files changed, 33 insertions, 19 deletions
diff --git a/speck.cpp b/speck.cpp
index 9359ae9a..7f6eb31b 100644
--- a/speck.cpp
+++ b/speck.cpp
@@ -7,6 +7,14 @@
#include "misc.h"
#include "cpu.h"
+#ifndef CRYPTOPP_INLINE
+# if defined(CRYPTOPP_DEBUG)
+# define CRYPTOPP_INLINE static
+# else
+# define CRYPTOPP_INLINE inline
+# endif
+#endif
+
// Uncomment for benchmarking C++ against SSE or NEON.
// Do so in both speck.cpp and speck-simd.cpp.
// #undef CRYPTOPP_SSSE3_AVAILABLE
@@ -28,7 +36,7 @@ using CryptoPP::rotrConstant;
/// additional template parameters also made calling SPECK_Encrypt and SPECK_Decrypt
/// kind of messy.
template <class W>
-inline void TF83(W& x, W& y, const W k)
+CRYPTOPP_INLINE void TF83(W& x, W& y, const W k)
{
x = rotrConstant<8>(x);
x += y; x ^= k;
@@ -44,7 +52,7 @@ inline void TF83(W& x, W& y, const W k)
/// additional template parameters also made calling SPECK_Encrypt and SPECK_Decrypt
/// kind of messy.
template <class W>
-inline void TR83(W& x, W& y, const W k)
+CRYPTOPP_INLINE void TR83(W& x, W& y, const W k)
{
y ^= x;
y = rotrConstant<3>(y);
@@ -59,7 +67,7 @@ inline void TR83(W& x, W& y, const W k)
/// \param p input array
/// \param k subkey array
template <class W, unsigned int R>
-inline void SPECK_Encrypt(W c[2], const W p[2], const W k[R])
+CRYPTOPP_INLINE void SPECK_Encrypt(W c[2], const W p[2], const W k[R])
{
c[0]=p[0]; c[1]=p[1];
@@ -75,7 +83,7 @@ inline void SPECK_Encrypt(W c[2], const W p[2], const W k[R])
/// \param c input array
/// \param k subkey array
template <class W, unsigned int R>
-inline void SPECK_Decrypt(W p[2], const W c[2], const W k[R])
+CRYPTOPP_INLINE void SPECK_Decrypt(W p[2], const W c[2], const W k[R])
{
p[0]=c[0]; p[1]=c[1];
@@ -91,7 +99,7 @@ inline void SPECK_Decrypt(W p[2], const W c[2], const W k[R])
/// \param key empty subkey array
/// \param k user key array
template <class W, unsigned int R>
-inline void SPECK_ExpandKey_2W(W key[R], const W k[2])
+CRYPTOPP_INLINE void SPECK_ExpandKey_2W(W key[R], const W k[2])
{
CRYPTOPP_ASSERT(R==32);
W i=0, B=k[0], A=k[1];
@@ -111,7 +119,7 @@ inline void SPECK_ExpandKey_2W(W key[R], const W k[2])
/// \param key empty subkey array
/// \param k user key array
template <class W, unsigned int R>
-inline void SPECK_ExpandKey_3W(W key[R], const W k[3])
+CRYPTOPP_INLINE void SPECK_ExpandKey_3W(W key[R], const W k[3])
{
CRYPTOPP_ASSERT(R==33 || R==26);
W i=0, C=k[0], B=k[1], A=k[2];
@@ -138,7 +146,7 @@ inline void SPECK_ExpandKey_3W(W key[R], const W k[3])
/// \param key empty subkey array
/// \param k user key array
template <class W, unsigned int R>
-inline void SPECK_ExpandKey_4W(W key[R], const W k[4])
+CRYPTOPP_INLINE void SPECK_ExpandKey_4W(W key[R], const W k[4])
{
CRYPTOPP_ASSERT(R==34 || R==27);
W i=0, D=k[0], C=k[1], B=k[2], A=k[3];
@@ -200,11 +208,11 @@ extern size_t SPECK128_Dec_AdvancedProcessBlocks_SSSE3(const word64* subKeys, si
const byte *inBlocks, const byte *xorBlocks, byte *outBlocks, size_t length, word32 flags);
#endif
-#if defined(CRYPTOPP_POWER7_AVAILABLE)
-extern size_t SPECK64_Enc_AdvancedProcessBlocks_POWER7(const word32* subKeys, size_t rounds,
+#if defined(CRYPTOPP_ALTIVEC_AVAILABLE)
+extern size_t SPECK64_Enc_AdvancedProcessBlocks_ALTIVEC(const word32* subKeys, size_t rounds,
const byte *inBlocks, const byte *xorBlocks, byte *outBlocks, size_t length, word32 flags);
-extern size_t SPECK64_Dec_AdvancedProcessBlocks_POWER7(const word32* subKeys, size_t rounds,
+extern size_t SPECK64_Dec_AdvancedProcessBlocks_ALTIVEC(const word32* subKeys, size_t rounds,
const byte *inBlocks, const byte *xorBlocks, byte *outBlocks, size_t length, word32 flags);
#endif
@@ -227,9 +235,9 @@ std::string SPECK64::Base::AlgorithmProvider() const
if (HasNEON())
return "NEON";
# endif
-# if (CRYPTOPP_POWER7_AVAILABLE)
- if (HasPower7())
- return "Power7";
+# if (CRYPTOPP_ALTIVEC_AVAILABLE)
+ if (HasAltivec())
+ return "Altivec";
# endif
#endif
return "C++";
@@ -264,6 +272,12 @@ void SPECK64::Base::UncheckedSetKey(const byte *userKey, unsigned int keyLength,
default:
CRYPTOPP_ASSERT(0);;
}
+
+ // Altivec loads the current subkey as a 16-byte vector
+ // The extra elements ensure memory backs the last subkey.
+#if CRYPTOPP_ALTIVEC_AVAILABLE
+ m_rkeys.Grow(m_rkeys.size()+4);
+#endif
}
void SPECK64::Enc::ProcessAndXorBlock(const byte *inBlock, const byte *xorBlock, byte *outBlock) const
@@ -435,9 +449,9 @@ size_t SPECK64::Enc::AdvancedProcessBlocks(const byte *inBlocks, const byte *xor
return SPECK64_Enc_AdvancedProcessBlocks_NEON(m_rkeys, (size_t)m_rounds,
inBlocks, xorBlocks, outBlocks, length, flags);
#endif
-#if (CRYPTOPP_POWER7_AVAILABLE)
- if (HasPower7())
- return SPECK64_Enc_AdvancedProcessBlocks_POWER7(m_rkeys, (size_t)m_rounds,
+#if (CRYPTOPP_ALTIVEC_AVAILABLE)
+ if (HasAltivec())
+ return SPECK64_Enc_AdvancedProcessBlocks_ALTIVEC(m_rkeys, (size_t)m_rounds,
inBlocks, xorBlocks, outBlocks, length, flags);
#endif
return BlockTransformation::AdvancedProcessBlocks(inBlocks, xorBlocks, outBlocks, length, flags);
@@ -456,9 +470,9 @@ size_t SPECK64::Dec::AdvancedProcessBlocks(const byte *inBlocks, const byte *xor
return SPECK64_Dec_AdvancedProcessBlocks_NEON(m_rkeys, (size_t)m_rounds,
inBlocks, xorBlocks, outBlocks, length, flags);
#endif
-#if (CRYPTOPP_POWER7_AVAILABLE)
- if (HasPower7())
- return SPECK64_Dec_AdvancedProcessBlocks_POWER7(m_rkeys, (size_t)m_rounds,
+#if (CRYPTOPP_ALTIVEC_AVAILABLE)
+ if (HasAltivec())
+ return SPECK64_Dec_AdvancedProcessBlocks_ALTIVEC(m_rkeys, (size_t)m_rounds,
inBlocks, xorBlocks, outBlocks, length, flags);
#endif
return BlockTransformation::AdvancedProcessBlocks(inBlocks, xorBlocks, outBlocks, length, flags);