Browse Source

Add SSE4 based SHA256

0.15
Pieter Wuille 7 years ago
parent
commit
c1ccb15b0e
  1. 1
      src/Makefile.am
  2. 18
      src/crypto/sha256.cpp
  3. 1506
      src/crypto/sha256_sse4.cpp

1
src/Makefile.am

@ -263,6 +263,7 @@ crypto_libbitcoin_crypto_a_SOURCES = \ @@ -263,6 +263,7 @@ crypto_libbitcoin_crypto_a_SOURCES = \
crypto/sha1.cpp \
crypto/sha1.h \
crypto/sha256.cpp \
crypto/sha256_sse4.cpp \
crypto/sha256.h \
crypto/sha512.cpp \
crypto/sha512.h

18
src/crypto/sha256.cpp

@ -3,13 +3,19 @@ @@ -3,13 +3,19 @@
// file COPYING or http://www.opensource.org/licenses/mit-license.php.
#include "crypto/sha256.h"
#include "crypto/common.h"
#include <string.h>
#include <atomic>
#if defined(__x86_64__) || defined(__amd64__)
#include <cpuid.h>
namespace sha256_sse4
{
void Transform(uint32_t* s, const unsigned char* chunk, size_t blocks);
}
#endif
// Internal implementation code.
namespace
{
@ -140,6 +146,14 @@ void (*Transform)(uint32_t*, const unsigned char*, size_t) = sha256::Transform; @@ -140,6 +146,14 @@ void (*Transform)(uint32_t*, const unsigned char*, size_t) = sha256::Transform;
std::string SHA256AutoDetect()
{
#if defined(__x86_64__) || defined(__amd64__)
uint32_t eax, ebx, ecx, edx;
if (__get_cpuid(1, &eax, &ebx, &ecx, &edx) && (ecx >> 19) & 1) {
Transform = sha256_sse4::Transform;
return "sse4";
}
#endif
return "standard";
}

1506
src/crypto/sha256_sse4.cpp

File diff suppressed because it is too large Load Diff
Loading…
Cancel
Save