回复:MSVC 构建与 SHA-256
原始发布页
打开来源页面查看 1 个交叉存档
OpenSSL 没有任何接口能只执行 SHA256 底层的原始区块哈希部分。SHA256 首先会把你的数据封装到一个具有特殊格式的缓冲区中。如果像我们这样只对一两个区块进行哈希,设置缓冲区所花的时间会比实际哈希长一个数量级。它的设计意图是,当你对许多 KB 或 MB 的数据进行哈希时,这部分时间能够被摊薄。在 BitcoinMiner 中,我们只格式化一次缓冲区,然后不断复用它。
如果你能找到比我们现有代码更快(使用 MinGW/GCC)的 SHA256 代码,那就太棒了!(不过要记得留意许可证)我们现在用的是我唯一试过的一个,所以应该有很大的改进空间。
两年多前我写它的时候,已经有速度快得惊人的 SHA1 实现,但人们对 SHA256 的关注很少。这么长时间足以让他们做出更好的东西。当时 SHA256 比最快的 SHA1 慢得多,超出了我认为合理的程度。显然 SHA256 本来就应该比 SHA1 慢一些,但不该像我看到的那样慢那么多。
(希望你不介意我重命名了你的主题,SHA-256 优化是一件很重要、但我总会忘记的事)
英文原文
展开英文原文
OpenSSL doesn't have any interface for doing just the low level raw block hash part of SHA256. SHA256 begins by wrapping your data in a specially formatted buffer. Setting up the buffer takes an order of magnitude longer than the actual hashing if you're only hashing one or two blocks like we do. It's intended that the time is amortised if you were hashing many KB or MB of data. In BitcoinMiner, we format the buffer once and keep reusing it.
If you can find SHA256 code that's faster (with MinGW/GCC) than what we've got, that would be really great! (although, keep licensing in mind) The one we have is the only one I tried, so there's significant chance for improvement.
When I wrote it more than 2 years ago, there were screaming hot SHA1 implementations but minimal attention to SHA256. That's a lot of time for them to come up with better stuff. SHA256 was a lot slower than the fastest SHA1 at the time than I thought it should be. Obviously SHA256 should be slower than SHA1 by a certain amount, but not by as much as I saw.
(hope you don't mind I renamed your thread, SHA-256 optimisation is something important that I keep forgetting about)