Fold calls to set CRYPTOGAMS_armcaps into CryptogamsArmCaps

pull/843/head
Jeffrey Walton 2019-05-19 16:18:20 -04:00
parent 6f2a2866e2
commit 65bbba6609
No known key found for this signature in database
GPG Key ID: B36AB348921B1838
1 changed files with 56 additions and 12 deletions

68
sha.cpp
View File

@ -65,7 +65,7 @@ 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); extern void SHA256_HashMultipleBlocks_SHANI(word32 *state, const word32 *data, size_t length, ByteOrder order);
#endif #endif
#if (CRYPTOGAMS_ARM_SHA1) #if CRYPTOGAMS_ARM_SHA1
extern "C" unsigned int CRYPTOGAMS_armcaps; extern "C" unsigned int CRYPTOGAMS_armcaps;
extern "C" int sha1_block_data_order(word32* state, const word32 *data, size_t blocks); extern "C" int sha1_block_data_order(word32* state, const word32 *data, size_t blocks);
#endif #endif
@ -78,7 +78,7 @@ extern void SHA1_HashMultipleBlocks_ARMV8(word32 *state, const word32 *data, siz
extern void SHA256_HashMultipleBlocks_ARMV8(word32 *state, const word32 *data, size_t length, ByteOrder order); extern void SHA256_HashMultipleBlocks_ARMV8(word32 *state, const word32 *data, size_t length, ByteOrder order);
#endif #endif
#if (CRYPTOGAMS_ARM_SHA256) #if CRYPTOGAMS_ARM_SHA256
extern "C" unsigned int CRYPTOGAMS_armcaps; extern "C" unsigned int CRYPTOGAMS_armcaps;
extern "C" int sha256_block_data_order(word32* state, const word32 *data, size_t blocks); extern "C" int sha256_block_data_order(word32* state, const word32 *data, size_t blocks);
#endif #endif
@ -92,7 +92,7 @@ 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); extern void SHA512_HashMultipleBlocks_POWER8(word64 *state, const word64 *data, size_t length, ByteOrder order);
#endif #endif
#if (CRYPTOGAMS_ARM_SHA512) #if CRYPTOGAMS_ARM_SHA512
extern "C" unsigned int CRYPTOGAMS_armcaps; extern "C" unsigned int CRYPTOGAMS_armcaps;
extern "C" int sha512_block_data_order(word64* state, const word64 *data, size_t blocks); extern "C" int sha512_block_data_order(word64* state, const word64 *data, size_t blocks);
#endif #endif
@ -167,6 +167,23 @@ const word32 SHA256_K[64] = {
0x90befffa, 0xa4506ceb, 0xbef9a3f7, 0xc67178f2 0x90befffa, 0xa4506ceb, 0xbef9a3f7, 0xc67178f2
}; };
ANONYMOUS_NAMESPACE_BEGIN
#if CRYPTOGAMS_ARM_SHA1 || CRYPTOGAMS_ARM_SHA256 || CRYPTOGAMS_ARM_SHA512
bool CryptogamsArmCaps()
{
// 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.
*reinterpret_cast<volatile unsigned int*>(&CRYPTOGAMS_armcaps) = CryptoPP::HasNEON() ? (1<<0) : 0;
return true;
}
#endif
ANONYMOUS_NAMESPACE_END
//////////////////////////////// ////////////////////////////////
// start of Steve Reid's code // // start of Steve Reid's code //
//////////////////////////////// ////////////////////////////////
@ -290,11 +307,23 @@ void SHA1::Transform(word32 *state, const word32 *data)
return; return;
} }
#endif #endif
#if CRYPTOGAMS_ARM_SHA1 && 0 #if CRYPTOGAMS_ARM_SHA1
// TODO: convert LE to BE and use Cryptogams code
if (HasARMv7()) 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 bool unused = CryptogamsArmCaps();
CRYPTOPP_UNUSED(unused);
# if defined(CRYPTOPP_LITTLE_ENDIAN)
word32 dataBuf[16];
ByteReverse(dataBuf, data, SHA1::BLOCKSIZE);
sha1_block_data_order(state, data, 1); sha1_block_data_order(state, data, 1);
# else
sha1_block_data_order(state, data, 1);
# endif
return; return;
} }
#endif #endif
@ -328,7 +357,7 @@ size_t SHA1::HashMultipleBlocks(const word32 *input, size_t length)
// for capabilities like ARMv7 and NEON. Storage is allocated in the // for capabilities like ARMv7 and NEON. Storage is allocated in the
// module. We still need to set CRYPTOGAMS_armcaps accordingly. // module. We still need to set CRYPTOGAMS_armcaps accordingly.
// The Cryptogams code defines NEON as 1<<0; see ARMV7_NEON. // The Cryptogams code defines NEON as 1<<0; see ARMV7_NEON.
static const unsigned int unused = CRYPTOGAMS_armcaps = HasNEON() ? (1<<0) : 0; static const bool unused = CryptogamsArmCaps();
CRYPTOPP_UNUSED(unused); CRYPTOPP_UNUSED(unused);
sha1_block_data_order(m_state, input, length / SHA1::BLOCKSIZE); sha1_block_data_order(m_state, input, length / SHA1::BLOCKSIZE);
@ -837,11 +866,23 @@ void SHA256::Transform(word32 *state, const word32 *data)
return; return;
} }
#endif #endif
#if CRYPTOGAMS_ARM_SHA256 && 0 #if CRYPTOGAMS_ARM_SHA256
// TODO: convert LE to BE and use Cryptogams code
if (HasARMv7()) 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 bool unused = CryptogamsArmCaps();
CRYPTOPP_UNUSED(unused);
# if defined(CRYPTOPP_LITTLE_ENDIAN)
word32 dataBuf[16];
ByteReverse(dataBuf, data, SHA256::BLOCKSIZE);
sha256_block_data_order(state, data, 1); sha256_block_data_order(state, data, 1);
# else
sha256_block_data_order(state, data, 1);
# endif
return; return;
} }
#endif #endif
@ -890,7 +931,7 @@ size_t SHA256::HashMultipleBlocks(const word32 *input, size_t length)
// for capabilities like ARMv7 and NEON. Storage is allocated in the // for capabilities like ARMv7 and NEON. Storage is allocated in the
// module. We still need to set CRYPTOGAMS_armcaps accordingly. // module. We still need to set CRYPTOGAMS_armcaps accordingly.
// The Cryptogams code defines NEON as 1<<0; see ARMV7_NEON. // The Cryptogams code defines NEON as 1<<0; see ARMV7_NEON.
static const unsigned int unused = CRYPTOGAMS_armcaps = HasNEON() ? (1<<0) : 0; static const bool unused = CryptogamsArmCaps();
CRYPTOPP_UNUSED(unused); CRYPTOPP_UNUSED(unused);
sha256_block_data_order(m_state, input, length / SHA256::BLOCKSIZE); sha256_block_data_order(m_state, input, length / SHA256::BLOCKSIZE);
@ -960,7 +1001,7 @@ size_t SHA224::HashMultipleBlocks(const word32 *input, size_t length)
// for capabilities like ARMv7 and NEON. Storage is allocated in the // for capabilities like ARMv7 and NEON. Storage is allocated in the
// module. We still need to set CRYPTOGAMS_armcaps accordingly. // module. We still need to set CRYPTOGAMS_armcaps accordingly.
// The Cryptogams code defines NEON as 1<<0; see ARMV7_NEON. // The Cryptogams code defines NEON as 1<<0; see ARMV7_NEON.
static const unsigned int unused = CRYPTOGAMS_armcaps = HasNEON() ? (1<<0) : 0; static const bool unused = CryptogamsArmCaps();
CRYPTOPP_UNUSED(unused); CRYPTOPP_UNUSED(unused);
sha256_block_data_order(m_state, input, length / SHA256::BLOCKSIZE); sha256_block_data_order(m_state, input, length / SHA256::BLOCKSIZE);
@ -1330,13 +1371,16 @@ void SHA512::Transform(word64 *state, const word64 *data)
// for capabilities like ARMv7 and NEON. Storage is allocated in the // for capabilities like ARMv7 and NEON. Storage is allocated in the
// module. We still need to set CRYPTOGAMS_armcaps accordingly. // module. We still need to set CRYPTOGAMS_armcaps accordingly.
// The Cryptogams code defines NEON as 1<<0; see ARMV7_NEON. // The Cryptogams code defines NEON as 1<<0; see ARMV7_NEON.
static const unsigned int unused = CRYPTOGAMS_armcaps = HasNEON() ? (1<<0) : 0; static const bool unused = CryptogamsArmCaps();
CRYPTOPP_UNUSED(unused); CRYPTOPP_UNUSED(unused);
# if defined(CRYPTOPP_LITTLE_ENDIAN)
word64 dataBuf[16]; word64 dataBuf[16];
ByteReverse(dataBuf, data, SHA512::BLOCKSIZE); ByteReverse(dataBuf, data, SHA512::BLOCKSIZE);
sha512_block_data_order(state, dataBuf, 1); sha512_block_data_order(state, dataBuf, 1);
# else
sha512_block_data_order(state, data, 1);
# endif
return; return;
} }
#endif #endif