Skip to content

Commit c1ccb15

Browse files
committed
Add SSE4 based SHA256
1 parent 2991c91 commit c1ccb15

File tree

3 files changed

+1523
-2
lines changed

3 files changed

+1523
-2
lines changed

Diff for: src/Makefile.am

+1
Original file line numberDiff line numberDiff line change
@@ -263,6 +263,7 @@ crypto_libbitcoin_crypto_a_SOURCES = \
263263
crypto/sha1.cpp \
264264
crypto/sha1.h \
265265
crypto/sha256.cpp \
266+
crypto/sha256_sse4.cpp \
266267
crypto/sha256.h \
267268
crypto/sha512.cpp \
268269
crypto/sha512.h

Diff for: src/crypto/sha256.cpp

+16-2
Original file line numberDiff line numberDiff line change
@@ -3,13 +3,19 @@
33
// file COPYING or http://www.opensource.org/licenses/mit-license.php.
44

55
#include "crypto/sha256.h"
6-
76
#include "crypto/common.h"
87

98
#include <string.h>
10-
119
#include <atomic>
1210

11+
#if defined(__x86_64__) || defined(__amd64__)
12+
#include <cpuid.h>
13+
namespace sha256_sse4
14+
{
15+
void Transform(uint32_t* s, const unsigned char* chunk, size_t blocks);
16+
}
17+
#endif
18+
1319
// Internal implementation code.
1420
namespace
1521
{
@@ -140,6 +146,14 @@ void (*Transform)(uint32_t*, const unsigned char*, size_t) = sha256::Transform;
140146

141147
std::string SHA256AutoDetect()
142148
{
149+
#if defined(__x86_64__) || defined(__amd64__)
150+
uint32_t eax, ebx, ecx, edx;
151+
if (__get_cpuid(1, &eax, &ebx, &ecx, &edx) && (ecx >> 19) & 1) {
152+
Transform = sha256_sse4::Transform;
153+
return "sse4";
154+
}
155+
#endif
156+
143157
return "standard";
144158
}
145159

0 commit comments

Comments
 (0)