Add ARM SHA512 asm implementation from Cryptogams (GH #841)

pull/843/head
Jeffrey Walton 2019-05-19 08:10:05 -04:00
parent 4c9ca6b723
commit 86cc94ec1a
No known key found for this signature in database
GPG Key ID: B36AB348921B1838
7 changed files with 1943 additions and 2 deletions

View File

@ -318,6 +318,8 @@ sha1_armv4.h
sha1_armv4.S
sha256_armv4.h
sha256_armv4.S
sha512_armv4.h
sha512_armv4.S
sha3.cpp
sha3.h
shacal2.cpp

View File

@ -1059,7 +1059,7 @@ endif
ifeq ($(IS_ARM32),1)
CRYPTOGAMS_ARCH_FLAG = -march=armv7-a
CRYPTOGAMS_ARCH_FLAG += -Wa,--noexecstack
SRCS += aes_armv4.S sha1_armv4.S sha256_armv4.S
SRCS += aes_armv4.S sha1_armv4.S sha256_armv4.S sha512_armv4.S
endif
# List cryptlib.cpp first, then cpu.cpp, then integer.cpp to tame C++ static initialization problems.
@ -1513,6 +1513,10 @@ sha1_armv4.o : sha1_armv4.S
sha256_armv4.o : sha256_armv4.S
$(CC) $(strip $(CXXFLAGS) $(CRYPTOGAMS_ARCH_FLAG) -c) $<
# Cryptogams ARM asm implementation.
sha512_armv4.o : sha512_armv4.S
$(CC) $(strip $(CXXFLAGS) $(CRYPTOGAMS_ARCH_FLAG) -c) $<
sha3_simd.o : sha3_simd.cpp
$(CXX) $(strip $(CXXFLAGS) $(SHA3_FLAG) -c) $<

View File

@ -594,7 +594,7 @@ ifeq ($(IS_ARM32),1)
ifneq ($(IS_IOS),1)
CRYPTOGAMS_ARCH_FLAG = -march=armv7-a
CRYPTOGAMS_ARCH_FLAG += -Wa,--noexecstack
SRCS += aes_armv4.S sha1_armv4.S sha256_armv4.S
SRCS += aes_armv4.S sha1_armv4.S sha256_armv4.S sha512_armv4.S
endif
endif
@ -873,6 +873,10 @@ sha1_armv4.o : sha1_armv4.S
sha256_armv4.o : sha256_armv4.S
$(CC) $(strip $(CXXFLAGS) $(CRYPTOGAMS_ARCH_FLAG) -c) $<
# Cryptogams ARM asm implementation.
sha512_armv4.o : sha512_armv4.S
$(CC) $(strip $(CXXFLAGS) $(CRYPTOGAMS_ARCH_FLAG) -c) $<
# SSE4.2/SHA-NI or ARMv8a available
shacal2_simd.o : shacal2_simd.cpp
$(CXX) $(strip $(CXXFLAGS) $(SHA_FLAG) -c) $<

View File

@ -366,6 +366,7 @@
# define CRYPTOGAMS_ARM_AES 1
# define CRYPTOGAMS_ARM_SHA1 1
# define CRYPTOGAMS_ARM_SHA256 1
# define CRYPTOGAMS_ARM_SHA512 1
# endif
#endif

28
sha.cpp
View File

@ -83,6 +83,11 @@ extern void SHA256_HashMultipleBlocks_POWER8(word32 *state, const word32 *data,
extern void SHA512_HashMultipleBlocks_POWER8(word64 *state, const word64 *data, size_t length, ByteOrder order);
#endif
#if (CRYPTOGAMS_ARM_SHA512)
extern "C" unsigned int CRYPTOGAMS_armcaps;
extern "C" int sha512_block_data_order(word64* state, const word64 *data, size_t blocks);
#endif
// We add extern to export table to sha_simd.cpp, but it
// cleared http://github.com/weidai11/cryptopp/issues/502
extern const word32 SHA256_K[64];
@ -997,6 +1002,12 @@ std::string SHA512_AlgorithmProvider()
if (HasSSE2())
return "SSE2";
#endif
#if CRYPTOGAMS_ARM_SHA512
if (HasNEON())
return "NEON";
if (HasARMv7())
return "ARMv7";
#endif
#if (CRYPTOPP_POWER8_SHA_AVAILABLE)
if (HasSHA512())
return "Power8";
@ -1303,6 +1314,23 @@ void SHA512::Transform(word64 *state, const word64 *data)
return;
}
#endif
#if CRYPTOGAMS_ARM_SHA512
if (HasARMv7())
{
// The Cryptogams code uses a global variable named CRYPTOGAMS_armcaps
// for capabilities like ARMv7 and NEON. Storage is allocated in the
// module. We still need to set CRYPTOGAMS_armcaps accordingly.
// The Cryptogams code defines NEON as 1<<0; see ARMV7_NEON.
static const unsigned int unused = CRYPTOGAMS_armcaps = HasNEON() ? (1<<0) : 0;
CRYPTOPP_UNUSED(unused);
word64 dataBuf[16];
ByteReverse(dataBuf, data, SHA512::BLOCKSIZE);
sha512_block_data_order(state, dataBuf, 1);
return;
}
#endif
#if CRYPTOPP_POWER8_SHA_AVAILABLE
if (HasSHA512())
{

1881
sha512_armv4.S Normal file

File diff suppressed because it is too large Load Diff

21
sha512_armv4.h Normal file
View File

@ -0,0 +1,21 @@
/* Header file for use with Cryptogam's ARMv4 SHA512. */
/* Also see http://www.openssl.org/~appro/cryptogams/ */
/* https://wiki.openssl.org/index.php/Cryptogams_SHA. */
#ifndef CRYPTOGAMS_SHA512_ARMV4_H
#define CRYPTOGAMS_SHA512_ARMV4_H
#ifdef __cplusplus
extern "C" {
#endif
void sha512_block_data_order(void *state, const void *data, size_t blocks);
/* Cryptogams arm caps */
#define ARMV7_NEON (1<<0)
#ifdef __cplusplus
}
#endif
#endif /* CRYPTOGAMS_SHA512_ARMV4_H */