diff options
author | Jeffrey Walton <noloader@gmail.com> | 2019-10-28 01:12:58 -0400 |
---|---|---|
committer | GitHub <noreply@github.com> | 2019-10-28 01:12:58 -0400 |
commit | c831d6ffeeb80ea805502e62ad795afb8ef6fdff (patch) | |
tree | 01361e7f350be558699c1cec28d1780c693a9836 /simon.cpp | |
parent | 6da6b7f5ace3d342942a2f5aa39fe8542da798c7 (diff) | |
download | cryptopp-git-c831d6ffeeb80ea805502e62ad795afb8ef6fdff.tar.gz |
Pre-splat SIMON and SPECK keys when appropriate for Altivec (PR #910)
SIMON and SPECK keys can be pre-splatted in the forward direction when Altivec instructions will be used. Pre-splatting does not work for the reverse transformation. It breaks modes like CBC, so the speed-up is only applied to the forward transformation.
Diffstat (limited to 'simon.cpp')
-rw-r--r-- | simon.cpp | 22 |
1 files changed, 19 insertions, 3 deletions
@@ -326,10 +326,15 @@ void SIMON64::Base::UncheckedSetKey(const byte *userKey, unsigned int keyLength, CRYPTOPP_ASSERT(0);
}
- // Altivec loads the current subkey as a 16-byte vector
- // The extra elements ensure memory backs the last subkey.
+ // Pre-splat the round keys for Altivec forward transformation
#if CRYPTOPP_ALTIVEC_AVAILABLE
- m_rkeys.Grow(m_rkeys.size()+4);
+ if (IsForwardTransformation() && HasAltivec())
+ {
+ AlignedSecBlock presplat(m_rkeys.size()*4);
+ for (size_t i=0, j=0; i<m_rkeys.size(); i++, j+=4)
+ presplat[j+0] = presplat[j+1] = presplat[j+2] = presplat[j+3] = m_rkeys[i];
+ m_rkeys.swap(presplat);
+ }
#endif
}
@@ -453,6 +458,17 @@ void SIMON128::Base::UncheckedSetKey(const byte *userKey, unsigned int keyLength default:
CRYPTOPP_ASSERT(0);
}
+
+ // Pre-splat the round keys for Power8 forward transformation
+#if CRYPTOPP_POWER8_AVAILABLE
+ if (IsForwardTransformation() && HasPower8())
+ {
+ AlignedSecBlock presplat(m_rkeys.size()*2);
+ for (size_t i=0, j=0; i<m_rkeys.size(); i++, j+=2)
+ presplat[j+0] = presplat[j+1] = m_rkeys[i];
+ m_rkeys.swap(presplat);
+ }
+#endif
}
void SIMON128::Enc::ProcessAndXorBlock(const byte *inBlock, const byte *xorBlock, byte *outBlock) const
|