- Introduces the classes CSHA256 and CSHA512 in crypto/sha2.{cpp,h}, CSHA1 in crypto/sha1.{cpp,h} and CRIPEMD160 in crypto/ripemd160.{cpp,h}.
- The HMAC-SHA512 implementation is moved to sha2.{cpp,h} as well, with a similar interface.
- In hash.h, CHash256 (=double SHA256) and CHash160 (SHA256 + RIPEMD160) are added.
- The rest of hash.h is refactored to use those classes.
- The internal miner is also modified to use CHash256 (hiding the inner SHA256 workings).
- The getwork() RPC call is removed.
Replace OpenSSL hash functions with built-in implementations #4100
pull sipa wants to merge 13 commits into bitcoin:master from sipa:ownhash changing 26 files +1387 −610-
sipa commented at 10:00 pm on April 27, 2014: member
-
sipa commented at 10:12 pm on April 27, 2014: memberBenchmark of the built-in miner: old code 1111 khash/s, new code 1016 khash/s.
-
sipa commented at 11:16 pm on April 27, 2014: memberMicrobenchmark for just double-SHA256 of a 80-byte block: old 1.26us, new 1.37us
-
jgarzik commented at 11:55 pm on April 27, 2014: contributor
IIRC, we suffer from the terribly annoying requirement that some getwork miners fail without midstate and hash1.
Sure, those miners could be modified, but it seems disappointing to break an interface we want to remove anyway. The internal miner and GBT continue to see modern users, but I think it is time to retire getwork.
-
luke-jr commented at 0:10 am on April 28, 2014: memberAFAIK the only miner which needs midstate/hash1 is DiabloMiner.
-
laanwj commented at 2:06 am on April 28, 2014: member
Agree on removing getwork completely in next major release. It doesn’t scale to modern mining hardware, that alone is reason enough to get rid of it (we will have to adopt the
contrib/pyminerto usegetblocktemplate). I’m not convinced it should happen in this pull, though. Removing midstate seems like a fine intermediate solution.Nit: we’re ending up with a lot of hash-related implementation and header files. Maybe move them to a directory
src/hash? -
laanwj added this to the milestone 0.10.0 on Apr 28, 2014
-
gmaxwell commented at 5:15 am on April 28, 2014: contributorI also think we should remove getwork. We should retain an ability to mine in the stock distribution (either the integrated miner or some contrib/ solution) but that doesn’t imply keeping getwork. I don’t even use getwork while mining on testnet.
-
sipa commented at 11:12 am on April 28, 2014: memberRemoved getwork(), and moved the SHA implementations to src/crypto/ (not src/hash/, as we’ll also want AES there eventually, I guess). I didn’t move hash.h itself there, as it doesn’t contain any actual crypto code (just wrappers), and it depends on more Bitcoin-specific stuff (this way, src/crypto/ is entirely dependencyless).
-
laanwj commented at 2:16 pm on April 28, 2014: memberGood point on
cryptoinstead ofhash. Woohoo, the pull-tester passed! -
sipa renamed this:
Replace the use of OpenSSL's SHA2 by a native implementation.
Replace the use of OpenSSL's SHA2 by a built-in implementation.
on Apr 28, 2014 -
sipa commented at 2:34 pm on April 28, 2014: memberOk, bug fixed. Seems I didn’t update the precomputed SHA256 state after updating the timestamp.
-
sipa renamed this:
Replace the use of OpenSSL's SHA2 by a built-in implementation.
Replace OpenSSL hash functions with built-in implementations
on Apr 30, 2014 -
sipa commented at 11:03 pm on April 30, 2014: memberAdded RIPEMD160 as well.
-
jgarzik commented at 1:02 pm on May 2, 2014: contributor
untested ACK. One comment:
{Read,Write}{BE,LE]{32,64} really wants to be in some sort of common header. One of my first reactions – though outside the scope of your initial conversion – was that the implementations of WriteBE* etc. is a “slow but safe” implementation. It should be a compiler intrinsic, as it can be on any gcc platform. And that requires a common header for such gizmos.
-
jgarzik commented at 3:49 pm on May 2, 2014: contributor
Not surprised. Enormous amounts of effort have been expended on the glibc [header] side, gcc and CPU sides of the problem, to make byte swapping faster.
As a result, you will see endian.h and friends play several tricks at compile-time, and then attempt to fall back to a compiler instrinsic if that does not work. Every modern CPU has a byte-swap instruction. Any networked LE or BE platform is constantly byte-swapping.
The general principle, therefore, is to include your platform’s favorite endian.h, and use the macros therein. It should degenerate into a compiler intrinsic for us.
In practice, this becomes painful as BSD and Linux diverge on the opinion of endian macro naming and header location.
-
sipa commented at 10:01 pm on May 2, 2014: member
More thorough test: 6% speedup. That’s probablt worth it given how many sha256’ing we do…
EDIT: with __builtin_bswap32, the built-in miner is only 4% slower than the current OpenSSL-based implementation.
-
sipa commented at 11:09 pm on May 2, 2014: memberMoved the Read/Write functions to crypto/common.h, and made them use direct read/write and/or __builtin_bswap* when possible.
-
sipa commented at 11:18 pm on May 2, 2014: memberUgh, endian.h doesn’t exist for mingw. This will need some autotools interaction :(
-
sipa commented at 11:33 pm on May 2, 2014: memberSmall cheat: WIN32 is always little endian
-
sipa commented at 7:21 pm on May 3, 2014: member\o/
-
sipa commented at 1:10 pm on May 10, 2014: memberRebased.
-
ghost commented at 12:42 pm on May 11, 2014: noneTested (linux) ACK.
-
sipa commented at 8:12 pm on May 31, 2014: memberExtended the hash unit tests.
-
sipa commented at 11:12 pm on June 5, 2014: memberNo need to rush things, as 0.10 won’t be for any time soon, but what do people think about the degree of tests here? Anything more required?
-
ghost commented at 7:08 am on June 6, 2014: noneI think it would be better to get this merged now so it can run on testnet for a while.
-
laanwj commented at 7:33 am on June 6, 2014: member
-
jgarzik commented at 1:58 am on June 7, 2014: contributor
General re-ACK.
Comments:
- It would be nice to specify a precise size on the char buffer in various Finalize() arguments, and the language does permit that. However, there may be disadvantages.
- On testing, the only thing I can suggest is a review of every callsite, and make sure that block import or some other populate code path (or test suite test) exercises that callsite.
- It seems likely that the endian.h area will need further autotools configury work (though it’s fine for now)
-
theuni commented at 7:52 pm on June 9, 2014: member
I’ve pushed up the autotools work as mentioned by @jgarzik here: https://github.com/theuni/bitcoin/commits/ownhash .
Also, this really needs to be built as its own library because it is entirely self-contained. My branch contains those changes as well.
There’s nothing there to derail this PR though, both of these things can be discussed/merged after.
-
sipa commented at 8:38 pm on June 9, 2014: memberRebased.
-
jgarzik commented at 1:11 am on June 13, 2014: contributor+1
-
sipa commented at 2:12 pm on June 21, 2014: memberAlternatively, I can move the non-crypto changes (just the wrapper interfaces, getwork/miner changes, unit tests, …) to a separate pullreq, as those should be no-ops.
-
laanwj commented at 3:20 pm on June 21, 2014: memberACK
-
977cdadea8
Add a built-in SHA256/SHA512 implementation.
This also moves the HMAC-SHA512 implementation to sha2.cpp.
-
Switch script.cpp and hash.cpp to use sha2.cpp instead of OpenSSL. 7b4737c878
-
Remove getwork() RPC call cf0c47b269
-
Switch miner.cpp to use sha2 instead of OpenSSL. 85aab2a088
-
Add built-in SHA-1 implementation. 1cc344ce42
-
Move crypto implementations to src/crypto/ 13b5dfef64
-
Add built-in RIPEMD-160 implementation a5bc9c0917
-
Move {Read,Write}{LE,BE}{32,64} to common.h and use builtins if possible 7ecd9739d9
-
Extend and move all crypto tests to crypto_tests.cpp 3820e01eb9
-
54372482a8
build: move bitcoin-config.h to its own directory
This allows us to include its path without making other header includes valid.
-
f2647cc0e9
crypto: explicitly check for byte read/write functions
Don't depend on hard-coded platform lists
-
4791b99e2d
crypto: create a separate lib for crypto functions
This lib has no dependencies on other bitcoin functionality. Attempting to use bitcoin headers will result in a failure to compile.
-
Add <Hasher>::OUTPUT_SIZE a0495bb68c
-
BitcoinPullTester commented at 6:39 pm on June 21, 2014: noneAutomatic sanity-testing: PASSED, see http://jenkins.bluematt.me/pull-tester/a0495bb68c6eff9c732d458bacab10490d6452b4 for binaries and test log. This test script verifies pulls every time they are updated. It, however, dies sometimes and fails to test properly. If you are waiting on a test, please check timestamps to verify that the test.log is moving at http://jenkins.bluematt.me/pull-tester/current/ Contact BlueMatt on freenode if something looks broken.
-
gmaxwell commented at 8:42 pm on June 21, 2014: contributorTested ACK.
-
sipa merged this on Jun 21, 2014
-
sipa closed this on Jun 21, 2014
-
sipa referenced this in commit 8f59251b83 on Jun 21, 2014
-
domob1812 referenced this in commit fa7e1e7e06 on Jun 13, 2018
-
domob1812 referenced this in commit fd710eff5c on Jun 13, 2018
-
DrahtBot locked this on Sep 8, 2021
This is a metadata mirror of the GitHub repository bitcoin/bitcoin. This site is not affiliated with GitHub. Content is generated from a GitHub metadata backup.
generated: 2025-12-13 09:13 UTC
More mirrored repositories can be found on mirror.b10c.me