diff options
author | Jeffrey Walton <noloader@gmail.com> | 2018-07-13 08:33:13 -0400 |
---|---|---|
committer | Jeffrey Walton <noloader@gmail.com> | 2018-07-13 08:33:13 -0400 |
commit | 3c2123344073eaa3fbb49c9ff1cc9b286a9a7a7e (patch) | |
tree | 6eb6152c5f6fe7f2a08d58b1af73fa20367478dc /sm4.cpp | |
parent | 2f71e4d7d971b3361ac8f484d6042aff074e6653 (diff) | |
download | cryptopp-git-3c2123344073eaa3fbb49c9ff1cc9b286a9a7a7e.tar.gz |
Add AES-NI accelerated SM4 encryption (GH #540)
Thanks to Markku-Juhani Olavi Saarinen for the code. Also see https://github.com/mjosaarinen/sm4ni
Diffstat (limited to 'sm4.cpp')
-rw-r--r-- | sm4.cpp | 30 |
1 files changed, 30 insertions, 0 deletions
@@ -89,6 +89,22 @@ ANONYMOUS_NAMESPACE_END NAMESPACE_BEGIN(CryptoPP)
+#if CRYPTOPP_SM4_ADVANCED_PROCESS_BLOCKS
+# if defined(CRYPTOPP_AESNI_AVAILABLE)
+extern size_t SM4_Enc_AdvancedProcessBlocks_AESNI(const word32* subKeys, size_t rounds,
+ const byte *inBlocks, const byte *xorBlocks, byte *outBlocks, size_t length, word32 flags);
+# endif
+#endif
+
+std::string SM4::Enc::AlgorithmProvider() const
+{
+#if defined(CRYPTOPP_AESNI_AVAILABLE)
+ if (HasAESNI())
+ return "AESNI";
+#endif
+ return "C++";
+}
+
void SM4::Base::UncheckedSetKey(const byte *userKey, unsigned int keyLength, const NameValuePairs ¶ms)
{
CRYPTOPP_ASSERT(keyLength == 16);
@@ -174,4 +190,18 @@ void SM4::Dec::ProcessAndXorBlock(const byte *inBlock, const byte *xorBlock, byt OutBlock oblk(xorBlock, outBlock); oblk(m_wspace[3])(m_wspace[2])(m_wspace[1])(m_wspace[0]);
}
+#if CRYPTOPP_SM4_ADVANCED_PROCESS_BLOCKS
+size_t SM4::Enc::AdvancedProcessBlocks(const byte *inBlocks, const byte *xorBlocks,
+ byte *outBlocks, size_t length, word32 flags) const
+{
+#if defined(CRYPTOPP_AESNI_AVAILABLE)
+ if (HasAESNI()) {
+ return SM4_Enc_AdvancedProcessBlocks_AESNI(m_rkeys, 32,
+ inBlocks, xorBlocks, outBlocks, length, flags);
+ }
+#endif
+ return BlockTransformation::AdvancedProcessBlocks(inBlocks, xorBlocks, outBlocks, length, flags);
+}
+#endif // CRYPTOPP_SM4_ADVANCED_PROCESS_BLOCKS
+
NAMESPACE_END
|