diff options
author | Jack Lloyd <[email protected]> | 2018-07-09 20:09:12 -0400 |
---|---|---|
committer | Jack Lloyd <[email protected]> | 2018-07-09 20:09:12 -0400 |
commit | b48a14a985f9bef9e0b5ea2260bfc33aa6148480 (patch) | |
tree | 9b1838fe4ce482101fa109186f897c377756d9c7 /src/lib/block/sm4/sm4.cpp | |
parent | f197e17a70a4b0c2b601a6c4cf28784592b596b8 (diff) |
Add support for ARMv8 SM4 instructions
Tested in qemu
Diffstat (limited to 'src/lib/block/sm4/sm4.cpp')
-rw-r--r-- | src/lib/block/sm4/sm4.cpp | 36 |
1 files changed, 36 insertions, 0 deletions
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 <botan/sm4.h> #include <botan/loadstor.h> +#include <botan/cpuid.h> 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<uint32_t>(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<uint32_t>(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"; + } + } |