Bitcointalk · Faster SHA-256, MSVC build

中本聪,2010 年 7 月 18 日

SN-1387 已核对来源,附原文与上下文。

阅读语言
中文译文

OpenSSL 没有接口只做 SHA256 底层原始块哈希那部分。SHA256 一开始要把你的数据包进一个特殊格式的缓冲区。如果像我们这样只哈希一两个块,搭建缓冲区花的时间比实际哈希还长一个量级。它本来是设计给哈希几 KB、几 MB 数据时摊薄开销用的。在 BitcoinMiner 里,我们把缓冲区搭一次然后反复复用。

倘若你能找到(在 MinGW/GCC 下)比我们现有的更快的 SHA256 代码,那真是太好!(不过要留意许可证)我们现在这个是我试过的唯一一个,所以提升空间很大。

2 年多前我写它的时候,SHA1 实现正火,SHA256 少有人问津。这么长时间足够他们拿出更好的东西了。当时 SHA256 比最快的 SHA1 慢得超出我的预期。SHA256 理应比 SHA1 慢一些,但不该慢那么多。

(希望你不介意我把你的主题改了名,SHA-256 优化很重要,我却老忘了这茬)

ORIGINAL · 英文原文
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)
上下文
← 上一条 SN-1387 · 当前 下一条 → 在档案中查看完整主题串 →
来源
Bitcointalk 原始链接 ↗ 记录编号 SN-1387