diff options
author | Jack Lloyd <[email protected]> | 2020-05-06 09:10:21 -0400 |
---|---|---|
committer | Jack Lloyd <[email protected]> | 2020-05-06 09:10:21 -0400 |
commit | 213eca6b830787a98d3b274c76bd8eb86b1ce506 (patch) | |
tree | 2d0a1fbce06ed49890e2053275b7b9b40fb30190 /src/lib | |
parent | a4a237e7f69be2742da6ee1c5a35412081e2c789 (diff) |
Consolidate the logic for hardware AES
We can safely assume there is only one hardware instruction set.
(Well, at least until VAES support is added, we can address that
when it happens)
Diffstat (limited to 'src/lib')
-rw-r--r-- | src/lib/block/aes/aes.cpp | 202 | ||||
-rw-r--r-- | src/lib/block/aes/aes.h | 39 | ||||
-rw-r--r-- | src/lib/block/aes/aes_armv8/aes_armv8.cpp | 12 | ||||
-rw-r--r-- | src/lib/block/aes/aes_ni/aes_ni.cpp | 12 | ||||
-rw-r--r-- | src/lib/block/aes/aes_power8/aes_power8.cpp | 12 | ||||
-rw-r--r-- | src/lib/utils/cpuid/cpuid.h | 16 |
6 files changed, 81 insertions, 212 deletions
diff --git a/src/lib/block/aes/aes.cpp b/src/lib/block/aes/aes.cpp index 7732e0909..b10c7b249 100644 --- a/src/lib/block/aes/aes.cpp +++ b/src/lib/block/aes/aes.cpp @@ -13,6 +13,10 @@ namespace Botan { +#if defined(BOTAN_HAS_AES_POWER8) || defined(BOTAN_HAS_AES_ARMV8) || defined(BOTAN_HAS_AES_NI) + #define BOTAN_HAS_HW_AES_SUPPORT +#endif + namespace { /* @@ -721,31 +725,17 @@ void aes_key_schedule(const uint8_t key[], size_t length, size_t aes_parallelism() { -#if defined(BOTAN_HAS_AES_NI) - if(CPUID::has_aes_ni()) - { - return 4; - } -#endif - -#if defined(BOTAN_HAS_AES_POWER8) - if(CPUID::has_power_crypto()) +#if defined(BOTAN_HAS_HW_AES_SUPPORT) + if(CPUID::has_hw_aes()) { - return 4; - } -#endif - -#if defined(BOTAN_HAS_AES_ARMV8) - if(CPUID::has_arm_aes()) - { - return 4; + return 4; // pipelined } #endif #if defined(BOTAN_HAS_AES_VPERM) if(CPUID::has_vperm()) { - return 2; + return 2; // pipelined } #endif @@ -755,24 +745,10 @@ size_t aes_parallelism() const char* aes_provider() { -#if defined(BOTAN_HAS_AES_NI) - if(CPUID::has_aes_ni()) - { - return "aesni"; - } -#endif - -#if defined(BOTAN_HAS_AES_POWER8) - if(CPUID::has_power_crypto()) +#if defined(BOTAN_HAS_HW_AES_SUPPORT) + if(CPUID::has_hw_aes()) { - return "power8"; - } -#endif - -#if defined(BOTAN_HAS_AES_ARMV8) - if(CPUID::has_arm_aes()) - { - return "armv8"; + return "cpu"; } #endif @@ -800,24 +776,10 @@ void AES_128::encrypt_n(const uint8_t in[], uint8_t out[], size_t blocks) const { verify_key_set(m_EK.empty() == false); -#if defined(BOTAN_HAS_AES_NI) - if(CPUID::has_aes_ni()) - { - return aesni_encrypt_n(in, out, blocks); - } -#endif - -#if defined(BOTAN_HAS_AES_ARMV8) - if(CPUID::has_arm_aes()) - { - return armv8_encrypt_n(in, out, blocks); - } -#endif - -#if defined(BOTAN_HAS_AES_POWER8) - if(CPUID::has_power_crypto()) +#if defined(BOTAN_HAS_HW_AES_SUPPORT) + if(CPUID::has_hw_aes()) { - return power8_encrypt_n(in, out, blocks); + return hw_aes_encrypt_n(in, out, blocks); } #endif @@ -835,24 +797,10 @@ void AES_128::decrypt_n(const uint8_t in[], uint8_t out[], size_t blocks) const { verify_key_set(m_DK.empty() == false); -#if defined(BOTAN_HAS_AES_NI) - if(CPUID::has_aes_ni()) - { - return aesni_decrypt_n(in, out, blocks); - } -#endif - -#if defined(BOTAN_HAS_AES_ARMV8) - if(CPUID::has_arm_aes()) - { - return armv8_decrypt_n(in, out, blocks); - } -#endif - -#if defined(BOTAN_HAS_AES_POWER8) - if(CPUID::has_power_crypto()) +#if defined(BOTAN_HAS_HW_AES_SUPPORT) + if(CPUID::has_hw_aes()) { - return power8_decrypt_n(in, out, blocks); + return hw_aes_decrypt_n(in, out, blocks); } #endif @@ -875,16 +823,10 @@ void AES_128::key_schedule(const uint8_t key[], size_t length) } #endif -#if defined(BOTAN_HAS_AES_ARMV8) - if(CPUID::has_arm_aes()) - { - return aes_key_schedule(key, length, m_EK, m_DK); - } -#endif - -#if defined(BOTAN_HAS_AES_POWER8) - if(CPUID::has_power_crypto()) +#if defined(BOTAN_HAS_HW_AES_SUPPORT) + if(CPUID::has_hw_aes()) { + // POWER and ARM use the standard key schedule code return aes_key_schedule(key, length, m_EK, m_DK); } #endif @@ -909,24 +851,10 @@ void AES_192::encrypt_n(const uint8_t in[], uint8_t out[], size_t blocks) const { verify_key_set(m_EK.empty() == false); -#if defined(BOTAN_HAS_AES_NI) - if(CPUID::has_aes_ni()) +#if defined(BOTAN_HAS_HW_AES_SUPPORT) + if(CPUID::has_hw_aes()) { - return aesni_encrypt_n(in, out, blocks); - } -#endif - -#if defined(BOTAN_HAS_AES_ARMV8) - if(CPUID::has_arm_aes()) - { - return armv8_encrypt_n(in, out, blocks); - } -#endif - -#if defined(BOTAN_HAS_AES_POWER8) - if(CPUID::has_power_crypto()) - { - return power8_encrypt_n(in, out, blocks); + return hw_aes_encrypt_n(in, out, blocks); } #endif @@ -944,24 +872,10 @@ void AES_192::decrypt_n(const uint8_t in[], uint8_t out[], size_t blocks) const { verify_key_set(m_DK.empty() == false); -#if defined(BOTAN_HAS_AES_NI) - if(CPUID::has_aes_ni()) - { - return aesni_decrypt_n(in, out, blocks); - } -#endif - -#if defined(BOTAN_HAS_AES_ARMV8) - if(CPUID::has_arm_aes()) - { - return armv8_decrypt_n(in, out, blocks); - } -#endif - -#if defined(BOTAN_HAS_AES_POWER8) - if(CPUID::has_power_crypto()) +#if defined(BOTAN_HAS_HW_AES_SUPPORT) + if(CPUID::has_hw_aes()) { - return power8_decrypt_n(in, out, blocks); + return hw_aes_decrypt_n(in, out, blocks); } #endif @@ -984,16 +898,10 @@ void AES_192::key_schedule(const uint8_t key[], size_t length) } #endif -#if defined(BOTAN_HAS_AES_ARMV8) - if(CPUID::has_arm_aes()) - { - return aes_key_schedule(key, length, m_EK, m_DK); - } -#endif - -#if defined(BOTAN_HAS_AES_POWER8) - if(CPUID::has_power_crypto()) +#if defined(BOTAN_HAS_HW_AES_SUPPORT) + if(CPUID::has_hw_aes()) { + // POWER and ARM use the standard key schedule code return aes_key_schedule(key, length, m_EK, m_DK); } #endif @@ -1018,24 +926,10 @@ void AES_256::encrypt_n(const uint8_t in[], uint8_t out[], size_t blocks) const { verify_key_set(m_EK.empty() == false); -#if defined(BOTAN_HAS_AES_NI) - if(CPUID::has_aes_ni()) +#if defined(BOTAN_HAS_HW_AES_SUPPORT) + if(CPUID::has_hw_aes()) { - return aesni_encrypt_n(in, out, blocks); - } -#endif - -#if defined(BOTAN_HAS_AES_ARMV8) - if(CPUID::has_arm_aes()) - { - return armv8_encrypt_n(in, out, blocks); - } -#endif - -#if defined(BOTAN_HAS_AES_POWER8) - if(CPUID::has_power_crypto()) - { - return power8_encrypt_n(in, out, blocks); + return hw_aes_encrypt_n(in, out, blocks); } #endif @@ -1053,24 +947,10 @@ void AES_256::decrypt_n(const uint8_t in[], uint8_t out[], size_t blocks) const { verify_key_set(m_DK.empty() == false); -#if defined(BOTAN_HAS_AES_NI) - if(CPUID::has_aes_ni()) +#if defined(BOTAN_HAS_HW_AES_SUPPORT) + if(CPUID::has_hw_aes()) { - return aesni_decrypt_n(in, out, blocks); - } -#endif - -#if defined(BOTAN_HAS_AES_ARMV8) - if(CPUID::has_arm_aes()) - { - return armv8_decrypt_n(in, out, blocks); - } -#endif - -#if defined(BOTAN_HAS_AES_POWER8) - if(CPUID::has_power_crypto()) - { - return power8_decrypt_n(in, out, blocks); + return hw_aes_decrypt_n(in, out, blocks); } #endif @@ -1093,16 +973,10 @@ void AES_256::key_schedule(const uint8_t key[], size_t length) } #endif -#if defined(BOTAN_HAS_AES_ARMV8) - if(CPUID::has_arm_aes()) - { - return aes_key_schedule(key, length, m_EK, m_DK); - } -#endif - -#if defined(BOTAN_HAS_AES_POWER8) - if(CPUID::has_power_crypto()) +#if defined(BOTAN_HAS_HW_AES_SUPPORT) + if(CPUID::has_hw_aes()) { + // POWER and ARM use the standard key schedule code return aes_key_schedule(key, length, m_EK, m_DK); } #endif diff --git a/src/lib/block/aes/aes.h b/src/lib/block/aes/aes.h index ef1c3a7ca..76248200d 100644 --- a/src/lib/block/aes/aes.h +++ b/src/lib/block/aes/aes.h @@ -40,19 +40,12 @@ class BOTAN_PUBLIC_API(2,0) AES_128 final : public Block_Cipher_Fixed_Params<16, #endif #if defined(BOTAN_HAS_AES_NI) - void aesni_encrypt_n(const uint8_t in[], uint8_t out[], size_t blocks) const; - void aesni_decrypt_n(const uint8_t in[], uint8_t out[], size_t blocks) const; void aesni_key_schedule(const uint8_t key[], size_t length); #endif -#if defined(BOTAN_HAS_AES_ARMV8) - void armv8_encrypt_n(const uint8_t in[], uint8_t out[], size_t blocks) const; - void armv8_decrypt_n(const uint8_t in[], uint8_t out[], size_t blocks) const; -#endif - -#if defined(BOTAN_HAS_AES_POWER8) - void power8_encrypt_n(const uint8_t in[], uint8_t out[], size_t blocks) const; - void power8_decrypt_n(const uint8_t in[], uint8_t out[], size_t blocks) const; +#if defined(BOTAN_HAS_AES_POWER8) || defined(BOTAN_HAS_AES_ARMV8) || defined(BOTAN_HAS_AES_NI) + void hw_aes_encrypt_n(const uint8_t in[], uint8_t out[], size_t blocks) const; + void hw_aes_decrypt_n(const uint8_t in[], uint8_t out[], size_t blocks) const; #endif secure_vector<uint32_t> m_EK, m_DK; @@ -82,19 +75,12 @@ class BOTAN_PUBLIC_API(2,0) AES_192 final : public Block_Cipher_Fixed_Params<16, #endif #if defined(BOTAN_HAS_AES_NI) - void aesni_encrypt_n(const uint8_t in[], uint8_t out[], size_t blocks) const; - void aesni_decrypt_n(const uint8_t in[], uint8_t out[], size_t blocks) const; void aesni_key_schedule(const uint8_t key[], size_t length); #endif -#if defined(BOTAN_HAS_AES_ARMV8) - void armv8_encrypt_n(const uint8_t in[], uint8_t out[], size_t blocks) const; - void armv8_decrypt_n(const uint8_t in[], uint8_t out[], size_t blocks) const; -#endif - -#if defined(BOTAN_HAS_AES_POWER8) - void power8_encrypt_n(const uint8_t in[], uint8_t out[], size_t blocks) const; - void power8_decrypt_n(const uint8_t in[], uint8_t out[], size_t blocks) const; +#if defined(BOTAN_HAS_AES_POWER8) || defined(BOTAN_HAS_AES_ARMV8) || defined(BOTAN_HAS_AES_NI) + void hw_aes_encrypt_n(const uint8_t in[], uint8_t out[], size_t blocks) const; + void hw_aes_decrypt_n(const uint8_t in[], uint8_t out[], size_t blocks) const; #endif void key_schedule(const uint8_t key[], size_t length) override; @@ -127,19 +113,12 @@ class BOTAN_PUBLIC_API(2,0) AES_256 final : public Block_Cipher_Fixed_Params<16, #endif #if defined(BOTAN_HAS_AES_NI) - void aesni_encrypt_n(const uint8_t in[], uint8_t out[], size_t blocks) const; - void aesni_decrypt_n(const uint8_t in[], uint8_t out[], size_t blocks) const; void aesni_key_schedule(const uint8_t key[], size_t length); #endif -#if defined(BOTAN_HAS_AES_ARMV8) - void armv8_encrypt_n(const uint8_t in[], uint8_t out[], size_t blocks) const; - void armv8_decrypt_n(const uint8_t in[], uint8_t out[], size_t blocks) const; -#endif - -#if defined(BOTAN_HAS_AES_POWER8) - void power8_encrypt_n(const uint8_t in[], uint8_t out[], size_t blocks) const; - void power8_decrypt_n(const uint8_t in[], uint8_t out[], size_t blocks) const; +#if defined(BOTAN_HAS_AES_POWER8) || defined(BOTAN_HAS_AES_ARMV8) || defined(BOTAN_HAS_AES_NI) + void hw_aes_encrypt_n(const uint8_t in[], uint8_t out[], size_t blocks) const; + void hw_aes_decrypt_n(const uint8_t in[], uint8_t out[], size_t blocks) const; #endif void key_schedule(const uint8_t key[], size_t length) override; diff --git a/src/lib/block/aes/aes_armv8/aes_armv8.cpp b/src/lib/block/aes/aes_armv8/aes_armv8.cpp index 0cd81b283..9766bf88c 100644 --- a/src/lib/block/aes/aes_armv8/aes_armv8.cpp +++ b/src/lib/block/aes/aes_armv8/aes_armv8.cpp @@ -54,7 +54,7 @@ namespace Botan { * AES-128 Encryption */ BOTAN_FUNC_ISA("+crypto") -void AES_128::armv8_encrypt_n(const uint8_t in[], uint8_t out[], size_t blocks) const +void AES_128::hw_aes_encrypt_n(const uint8_t in[], uint8_t out[], size_t blocks) const { const uint8_t *skey = reinterpret_cast<const uint8_t*>(m_EK.data()); @@ -119,7 +119,7 @@ void AES_128::armv8_encrypt_n(const uint8_t in[], uint8_t out[], size_t blocks) * AES-128 Decryption */ BOTAN_FUNC_ISA("+crypto") -void AES_128::armv8_decrypt_n(const uint8_t in[], uint8_t out[], size_t blocks) const +void AES_128::hw_aes_decrypt_n(const uint8_t in[], uint8_t out[], size_t blocks) const { const uint8_t *skey = reinterpret_cast<const uint8_t*>(m_DK.data()); @@ -184,7 +184,7 @@ void AES_128::armv8_decrypt_n(const uint8_t in[], uint8_t out[], size_t blocks) * AES-192 Encryption */ BOTAN_FUNC_ISA("+crypto") -void AES_192::armv8_encrypt_n(const uint8_t in[], uint8_t out[], size_t blocks) const +void AES_192::hw_aes_encrypt_n(const uint8_t in[], uint8_t out[], size_t blocks) const { const uint8_t *skey = reinterpret_cast<const uint8_t*>(m_EK.data()); @@ -255,7 +255,7 @@ void AES_192::armv8_encrypt_n(const uint8_t in[], uint8_t out[], size_t blocks) * AES-192 Decryption */ BOTAN_FUNC_ISA("+crypto") -void AES_192::armv8_decrypt_n(const uint8_t in[], uint8_t out[], size_t blocks) const +void AES_192::hw_aes_decrypt_n(const uint8_t in[], uint8_t out[], size_t blocks) const { const uint8_t *skey = reinterpret_cast<const uint8_t*>(m_DK.data()); @@ -326,7 +326,7 @@ void AES_192::armv8_decrypt_n(const uint8_t in[], uint8_t out[], size_t blocks) * AES-256 Encryption */ BOTAN_FUNC_ISA("+crypto") -void AES_256::armv8_encrypt_n(const uint8_t in[], uint8_t out[], size_t blocks) const +void AES_256::hw_aes_encrypt_n(const uint8_t in[], uint8_t out[], size_t blocks) const { const uint8_t *skey = reinterpret_cast<const uint8_t*>(m_EK.data()); @@ -403,7 +403,7 @@ void AES_256::armv8_encrypt_n(const uint8_t in[], uint8_t out[], size_t blocks) * AES-256 Decryption */ BOTAN_FUNC_ISA("+crypto") -void AES_256::armv8_decrypt_n(const uint8_t in[], uint8_t out[], size_t blocks) const +void AES_256::hw_aes_decrypt_n(const uint8_t in[], uint8_t out[], size_t blocks) const { const uint8_t *skey = reinterpret_cast<const uint8_t*>(m_DK.data()); diff --git a/src/lib/block/aes/aes_ni/aes_ni.cpp b/src/lib/block/aes/aes_ni/aes_ni.cpp index 0160bc1ee..76c695f32 100644 --- a/src/lib/block/aes/aes_ni/aes_ni.cpp +++ b/src/lib/block/aes/aes_ni/aes_ni.cpp @@ -107,7 +107,7 @@ __m128i aes_256_key_expansion(__m128i key, __m128i key2) * AES-128 Encryption */ BOTAN_FUNC_ISA("ssse3,aes") -void AES_128::aesni_encrypt_n(const uint8_t in[], uint8_t out[], size_t blocks) const +void AES_128::hw_aes_encrypt_n(const uint8_t in[], uint8_t out[], size_t blocks) const { const __m128i* in_mm = reinterpret_cast<const __m128i*>(in); __m128i* out_mm = reinterpret_cast<__m128i*>(out); @@ -184,7 +184,7 @@ void AES_128::aesni_encrypt_n(const uint8_t in[], uint8_t out[], size_t blocks) * AES-128 Decryption */ BOTAN_FUNC_ISA("ssse3,aes") -void AES_128::aesni_decrypt_n(const uint8_t in[], uint8_t out[], size_t blocks) const +void AES_128::hw_aes_decrypt_n(const uint8_t in[], uint8_t out[], size_t blocks) const { const __m128i* in_mm = reinterpret_cast<const __m128i*>(in); __m128i* out_mm = reinterpret_cast<__m128i*>(out); @@ -314,7 +314,7 @@ void AES_128::aesni_key_schedule(const uint8_t key[], size_t) * AES-192 Encryption */ BOTAN_FUNC_ISA("ssse3,aes") -void AES_192::aesni_encrypt_n(const uint8_t in[], uint8_t out[], size_t blocks) const +void AES_192::hw_aes_encrypt_n(const uint8_t in[], uint8_t out[], size_t blocks) const { const __m128i* in_mm = reinterpret_cast<const __m128i*>(in); __m128i* out_mm = reinterpret_cast<__m128i*>(out); @@ -397,7 +397,7 @@ void AES_192::aesni_encrypt_n(const uint8_t in[], uint8_t out[], size_t blocks) * AES-192 Decryption */ BOTAN_FUNC_ISA("ssse3,aes") -void AES_192::aesni_decrypt_n(const uint8_t in[], uint8_t out[], size_t blocks) const +void AES_192::hw_aes_decrypt_n(const uint8_t in[], uint8_t out[], size_t blocks) const { const __m128i* in_mm = reinterpret_cast<const __m128i*>(in); __m128i* out_mm = reinterpret_cast<__m128i*>(out); @@ -530,7 +530,7 @@ void AES_192::aesni_key_schedule(const uint8_t key[], size_t) * AES-256 Encryption */ BOTAN_FUNC_ISA("ssse3,aes") -void AES_256::aesni_encrypt_n(const uint8_t in[], uint8_t out[], size_t blocks) const +void AES_256::hw_aes_encrypt_n(const uint8_t in[], uint8_t out[], size_t blocks) const { const __m128i* in_mm = reinterpret_cast<const __m128i*>(in); __m128i* out_mm = reinterpret_cast<__m128i*>(out); @@ -619,7 +619,7 @@ void AES_256::aesni_encrypt_n(const uint8_t in[], uint8_t out[], size_t blocks) * AES-256 Decryption */ BOTAN_FUNC_ISA("ssse3,aes") -void AES_256::aesni_decrypt_n(const uint8_t in[], uint8_t out[], size_t blocks) const +void AES_256::hw_aes_decrypt_n(const uint8_t in[], uint8_t out[], size_t blocks) const { const __m128i* in_mm = reinterpret_cast<const __m128i*>(in); __m128i* out_mm = reinterpret_cast<__m128i*>(out); diff --git a/src/lib/block/aes/aes_power8/aes_power8.cpp b/src/lib/block/aes/aes_power8/aes_power8.cpp index 0dea7a953..02dca5fdc 100644 --- a/src/lib/block/aes/aes_power8/aes_power8.cpp +++ b/src/lib/block/aes/aes_power8/aes_power8.cpp @@ -112,7 +112,7 @@ inline void store_blocks(Altivec64x2 B0, Altivec64x2 B1, } BOTAN_FUNC_ISA("crypto") -void AES_128::power8_encrypt_n(const uint8_t in[], uint8_t out[], size_t blocks) const +void AES_128::hw_aes_encrypt_n(const uint8_t in[], uint8_t out[], size_t blocks) const { const Altivec64x2 K0 = load_key(&m_EK[0]); const Altivec64x2 K1 = load_key(&m_EK[4]); @@ -176,7 +176,7 @@ void AES_128::power8_encrypt_n(const uint8_t in[], uint8_t out[], size_t blocks) } BOTAN_FUNC_ISA("crypto") -void AES_128::power8_decrypt_n(const uint8_t in[], uint8_t out[], size_t blocks) const +void AES_128::hw_aes_decrypt_n(const uint8_t in[], uint8_t out[], size_t blocks) const { const Altivec64x2 K0 = load_key(&m_EK[40]); const Altivec64x2 K1 = load_key(&m_EK[36]); @@ -240,7 +240,7 @@ void AES_128::power8_decrypt_n(const uint8_t in[], uint8_t out[], size_t blocks) } BOTAN_FUNC_ISA("crypto") -void AES_192::power8_encrypt_n(const uint8_t in[], uint8_t out[], size_t blocks) const +void AES_192::hw_aes_encrypt_n(const uint8_t in[], uint8_t out[], size_t blocks) const { const Altivec64x2 K0 = load_key(&m_EK[0]); const Altivec64x2 K1 = load_key(&m_EK[4]); @@ -310,7 +310,7 @@ void AES_192::power8_encrypt_n(const uint8_t in[], uint8_t out[], size_t blocks) } BOTAN_FUNC_ISA("crypto") -void AES_192::power8_decrypt_n(const uint8_t in[], uint8_t out[], size_t blocks) const +void AES_192::hw_aes_decrypt_n(const uint8_t in[], uint8_t out[], size_t blocks) const { const Altivec64x2 K0 = load_key(&m_EK[48]); const Altivec64x2 K1 = load_key(&m_EK[44]); @@ -380,7 +380,7 @@ void AES_192::power8_decrypt_n(const uint8_t in[], uint8_t out[], size_t blocks) } BOTAN_FUNC_ISA("crypto") -void AES_256::power8_encrypt_n(const uint8_t in[], uint8_t out[], size_t blocks) const +void AES_256::hw_aes_encrypt_n(const uint8_t in[], uint8_t out[], size_t blocks) const { const Altivec64x2 K0 = load_key(&m_EK[0]); const Altivec64x2 K1 = load_key(&m_EK[4]); @@ -456,7 +456,7 @@ void AES_256::power8_encrypt_n(const uint8_t in[], uint8_t out[], size_t blocks) } BOTAN_FUNC_ISA("crypto") -void AES_256::power8_decrypt_n(const uint8_t in[], uint8_t out[], size_t blocks) const +void AES_256::hw_aes_decrypt_n(const uint8_t in[], uint8_t out[], size_t blocks) const { const Altivec64x2 K0 = load_key(&m_EK[56]); const Altivec64x2 K1 = load_key(&m_EK[52]); diff --git a/src/lib/utils/cpuid/cpuid.h b/src/lib/utils/cpuid/cpuid.h index d9e6b97b3..d9e0a74a6 100644 --- a/src/lib/utils/cpuid/cpuid.h +++ b/src/lib/utils/cpuid/cpuid.h @@ -335,6 +335,22 @@ class BOTAN_PUBLIC_API(2,1) CPUID final } /** + * Check if the processor supports hardware AES instructions + */ + static bool has_hw_aes() + { +#if defined(BOTAN_TARGET_CPU_IS_X86_FAMILY) + return has_aes_ni(); +#elif defined(BOTAN_TARGET_CPU_IS_ARM_FAMILY) + return has_arm_aes(); +#elif defined(BOTAN_TARGET_CPU_IS_PPC_FAMILY) + return has_power_crypto(); +#else + return false; +#endif + } + + /** * Check if the processor supports carryless multiply * (CLMUL, PMULL) */ |