summaryrefslogtreecommitdiff
path: root/sha.cpp
diff options
context:
space:
mode:
authorJeffrey Walton <noloader@gmail.com>2018-07-15 08:35:14 -0400
committerGitHub <noreply@github.com>2018-07-15 08:35:14 -0400
commit4e3a1ea962d8f8cc58b97d2dd59554479a2b2db9 (patch)
tree8671ea037c90d6c316d83a1b9e5fca5c9b1e14e2 /sha.cpp
parent2600f6dcc2c7adc001959309bb944384f352e111 (diff)
downloadcryptopp-git-4e3a1ea962d8f8cc58b97d2dd59554479a2b2db9.tar.gz
Add ARMv8.4 cpu feature detection support (GH #685) (#687)
This PR adds ARMv8.4 cpu feature detection support. Previously we only needed ARMv8.1 and things were much easier. For example, ARMv8.1 `__ARM_FEATURE_CRYPTO` meant PMULL, AES, SHA-1 and SHA-256 were available. ARMv8.4 `__ARM_FEATURE_CRYPTO` means PMULL, AES, SHA-1, SHA-256, SHA-512, SHA-3, SM3 and SM4 are available. We still use the same pattern as before. We make something available based on compiler version and/or preprocessor macros. But this time around we had to tighten things up a bit to ensure ARMv8.4 did not cross-pollinate down into ARMv8.1. ARMv8.4 is largely untested at the moment. There is no hardware in the field and CI lacks QEMU with the relevant patches/support. We will probably have to revisit some of this stuff in the future. Since this update applies to ARM gadgets we took the time to expand Android and iOS testing on Travis. Travis now tests more platforms, and includes Autotools and CMake builds, too.
Diffstat (limited to 'sha.cpp')
-rw-r--r--sha.cpp25
1 files changed, 16 insertions, 9 deletions
diff --git a/sha.cpp b/sha.cpp
index 889f909c..ab4fb7f2 100644
--- a/sha.cpp
+++ b/sha.cpp
@@ -6,7 +6,7 @@
// code from Johannes Schneiders, Skip Hovsmith and Barry O'Rourke.
// All code is in the public domain.
-// In August 2017 Walton reworked the internals to align all the implementations.
+// In August 2017 JW reworked the internals to align all the implementations.
// Formerly all hashes were software based, IterHashBase handled endian conversions,
// and IterHashBase dispatched a single to block SHA{N}::Transform. SHA{N}::Transform
// then performed the single block hashing. It was repeated for multiple blocks.
@@ -62,11 +62,18 @@ extern void SHA1_HashMultipleBlocks_SHANI(word32 *state, const word32 *data, siz
extern void SHA256_HashMultipleBlocks_SHANI(word32 *state, const word32 *data, size_t length, ByteOrder order);
#endif
-#if CRYPTOPP_ARM_SHA_AVAILABLE
+#if CRYPTOPP_ARM_SHA1_AVAILABLE
extern void SHA1_HashMultipleBlocks_ARMV8(word32 *state, const word32 *data, size_t length, ByteOrder order);
+#endif
+
+#if CRYPTOPP_ARM_SHA2_AVAILABLE
extern void SHA256_HashMultipleBlocks_ARMV8(word32 *state, const word32 *data, size_t length, ByteOrder order);
#endif
+#if CRYPTOPP_ARM_SHA512_AVAILABLE
+extern void SHA512_HashMultipleBlocks_ARMV8(word32 *state, const word32 *data, size_t length, ByteOrder order);
+#endif
+
#if CRYPTOPP_POWER8_SHA_AVAILABLE
extern void SHA256_HashMultipleBlocks_POWER8(word32 *state, const word32 *data, size_t length, ByteOrder order);
extern void SHA512_HashMultipleBlocks_POWER8(word64 *state, const word64 *data, size_t length, ByteOrder order);
@@ -161,7 +168,7 @@ std::string SHA1::AlgorithmProvider() const
if (HasSSE2())
return "SSE2";
#endif
-#if CRYPTOPP_ARM_SHA_AVAILABLE
+#if CRYPTOPP_ARM_SHA1_AVAILABLE
if (HasSHA1())
return "ARMv8";
#endif
@@ -189,7 +196,7 @@ void SHA1::Transform(word32 *state, const word32 *data)
return;
}
#endif
-#if CRYPTOPP_ARM_SHA_AVAILABLE
+#if CRYPTOPP_ARM_SHA1_AVAILABLE
if (HasSHA1())
{
SHA1_HashMultipleBlocks_ARMV8(state, data, SHA1::BLOCKSIZE, LITTLE_ENDIAN_ORDER);
@@ -212,7 +219,7 @@ size_t SHA1::HashMultipleBlocks(const word32 *input, size_t length)
return length & (SHA1::BLOCKSIZE - 1);
}
#endif
-#if CRYPTOPP_ARM_SHA_AVAILABLE
+#if CRYPTOPP_ARM_SHA1_AVAILABLE
if (HasSHA1())
{
SHA1_HashMultipleBlocks_ARMV8(m_state, input, length, BIG_ENDIAN_ORDER);
@@ -347,7 +354,7 @@ std::string SHA256_AlgorithmProvider()
if (HasSSE2())
return "SSE2";
#endif
-#if CRYPTOPP_ARM_SHA_AVAILABLE
+#if CRYPTOPP_ARM_SHA2_AVAILABLE
if (HasSHA2())
return "ARMv8";
#endif
@@ -728,7 +735,7 @@ void SHA256::Transform(word32 *state, const word32 *data)
return;
}
#endif
-#if CRYPTOPP_ARM_SHA_AVAILABLE
+#if CRYPTOPP_ARM_SHA2_AVAILABLE
if (HasSHA2())
{
SHA256_HashMultipleBlocks_ARMV8(state, data, SHA256::BLOCKSIZE, LITTLE_ENDIAN_ORDER);
@@ -766,7 +773,7 @@ size_t SHA256::HashMultipleBlocks(const word32 *input, size_t length)
return res;
}
#endif
-#if CRYPTOPP_ARM_SHA_AVAILABLE
+#if CRYPTOPP_ARM_SHA2_AVAILABLE
if (HasSHA2())
{
SHA256_HashMultipleBlocks_ARMV8(m_state, input, length, BIG_ENDIAN_ORDER);
@@ -822,7 +829,7 @@ size_t SHA224::HashMultipleBlocks(const word32 *input, size_t length)
return res;
}
#endif
-#if CRYPTOPP_ARM_SHA_AVAILABLE
+#if CRYPTOPP_ARM_SHA2_AVAILABLE
if (HasSHA2())
{
SHA256_HashMultipleBlocks_ARMV8(m_state, input, length, BIG_ENDIAN_ORDER);