From b48a14a985f9bef9e0b5ea2260bfc33aa6148480 Mon Sep 17 00:00:00 2001 From: Jack Lloyd Date: Mon, 9 Jul 2018 20:09:12 -0400 Subject: Add support for ARMv8 SM4 instructions Tested in qemu --- src/lib/block/sm4/sm4.cpp | 36 ++++++++++++++++++++++++++++++++++++ 1 file changed, 36 insertions(+) (limited to 'src/lib/block/sm4/sm4.cpp') diff --git a/src/lib/block/sm4/sm4.cpp b/src/lib/block/sm4/sm4.cpp index 7c409d40f..7a370a67b 100644 --- a/src/lib/block/sm4/sm4.cpp +++ b/src/lib/block/sm4/sm4.cpp @@ -1,12 +1,14 @@ /* * SM4 * (C) 2017 Ribose Inc +* (C) 2018 Jack Lloyd * * Botan is released under the Simplified BSD License (see license.txt) */ #include #include +#include namespace Botan { @@ -126,6 +128,11 @@ void SM4::encrypt_n(const uint8_t in[], uint8_t out[], size_t blocks) const { verify_key_set(m_RK.empty() == false); +#if defined(BOTAN_HAS_SM4_ARMV8) + if(CPUID::has_arm_sm4()) + return sm4_armv8_encrypt(in, out, blocks); +#endif + for(size_t i = 0; i != blocks; ++i) { uint32_t B0 = load_be(in, 0); @@ -156,6 +163,11 @@ void SM4::decrypt_n(const uint8_t in[], uint8_t out[], size_t blocks) const { verify_key_set(m_RK.empty() == false); +#if defined(BOTAN_HAS_SM4_ARMV8) + if(CPUID::has_arm_sm4()) + return sm4_armv8_decrypt(in, out, blocks); +#endif + for(size_t i = 0; i != blocks; ++i) { uint32_t B0 = load_be(in, 0); @@ -219,4 +231,28 @@ void SM4::clear() zap(m_RK); } +size_t SM4::parallelism() const + { +#if defined(BOTAN_HAS_SM4_ARMV8) + if(CPUID::has_arm_sm4()) + { + return 4; + } +#endif + + return 1; + } + +std::string SM4::provider() const + { +#if defined(BOTAN_HAS_SM4_ARMV8) + if(CPUID::has_arm_sm4()) + { + return "armv8"; + } +#endif + + return "base"; + } + } -- cgit v1.2.3