原始文献 / 论坛帖 / Re: MSVC build & SHA-256

Re: MSVC build & SHA-256

Bitcointalk · 2010-07-18 21:24:09 UTC

AuthorSatoshi Nakamoto
TitleRe: MSVC build & SHA-256
Date2010-07-18 21:24:09 UTC
ForumBitcointalk · 原文

OpenSSL 没有只做 SHA256 底层原始块哈希部分的接口。SHA256 开始时要把你的数据包进一个特殊格式的缓冲区。只哈希一两个块(像我们这样)时,搭这个缓冲区的时间比实际哈希长一个数量级。它是假设你在哈希很多 KB 或 MB 数据、时间能被摊薄而设计的。在 BitcoinMiner 里,我们把缓冲区格式化一次然后反复用。

如果你能找到比我们现在用的更快的 SHA256 代码(MinGW/GCC 下),那就太棒了!(不过注意许可证)我们现在这个是我试过的唯一一个,所以有很大改进空间。

我写它的时候是 2 年多前,那时有快得吓人的 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)