diff options
author | Pieter Wuille <pieter.wuille@gmail.com> | 2017-07-13 23:26:04 -0700 |
---|---|---|
committer | Pieter Wuille <pieter.wuille@gmail.com> | 2017-07-20 09:03:53 -0700 |
commit | 2991c91d88f3d17ac6b38bddfa6f1b6b8d835c0f (patch) | |
tree | 38783e7e46a9fbf4b038236f2cde834afe1a6fdb /src/crypto | |
parent | 4d50f38fe05374342b4b55953d188fd50d422663 (diff) |
Add SHA256 dispatcher
Diffstat (limited to 'src/crypto')
-rw-r--r-- | src/crypto/sha256.cpp | 13 | ||||
-rw-r--r-- | src/crypto/sha256.h | 6 |
2 files changed, 17 insertions, 2 deletions
diff --git a/src/crypto/sha256.cpp b/src/crypto/sha256.cpp index 45ee93d471..3649dc4be0 100644 --- a/src/crypto/sha256.cpp +++ b/src/crypto/sha256.cpp @@ -8,6 +8,8 @@ #include <string.h> +#include <atomic> + // Internal implementation code. namespace { @@ -131,8 +133,15 @@ void Transform(uint32_t* s, const unsigned char* chunk, size_t blocks) } } // namespace sha256 + +void (*Transform)(uint32_t*, const unsigned char*, size_t) = sha256::Transform; + } // namespace +std::string SHA256AutoDetect() +{ + return "standard"; +} ////// SHA-256 @@ -150,12 +159,12 @@ CSHA256& CSHA256::Write(const unsigned char* data, size_t len) memcpy(buf + bufsize, data, 64 - bufsize); bytes += 64 - bufsize; data += 64 - bufsize; - sha256::Transform(s, buf, 1); + Transform(s, buf, 1); bufsize = 0; } if (end - data >= 64) { size_t blocks = (end - data) / 64; - sha256::Transform(s, data, blocks); + Transform(s, data, blocks); data += 64 * blocks; bytes += 64 * blocks; } diff --git a/src/crypto/sha256.h b/src/crypto/sha256.h index 127e62a228..aa4f3972cc 100644 --- a/src/crypto/sha256.h +++ b/src/crypto/sha256.h @@ -7,6 +7,7 @@ #include <stdint.h> #include <stdlib.h> +#include <string> /** A hasher class for SHA-256. */ class CSHA256 @@ -25,4 +26,9 @@ public: CSHA256& Reset(); }; +/** Autodetect the best available SHA256 implementation. + * Returns the name of the implementation. + */ +std::string SHA256AutoDetect(); + #endif // BITCOIN_CRYPTO_SHA256_H |