研究了一个 cpu 矿工的源代码,我发现了这段代码:
work->data[20] = 0x80000000;
好吧,我问了编码,他的回答是:
“这些值是标准 SHA-2 填充的一部分”
谷歌搜索“sha 2 padding”没有帮助。你能告诉我这是做什么用的吗?
我以为 md5/sha256 函数只是获取数据并返回哈希值。
我不明白“填充”的概念。
最佳答案
您可以在 RFC 4634 -- SHA and HMAC-SHA 中找到它的记录,第 4.1 节。引自第 4 部分的介绍:
As a summary, a "1" followed by a number of "0"s followed by a 64-bit or 128-bit integer are appended to the end of the message.
0x80000000
是 10000000000000000000000000000000
以二进制形式。这是您的“1”,后跟一些“0”。原因是 SHA-256 通过将输入分成固定大小的块来处理输入。最后一个块可能更小,所以它被扩展(填充)直到它的大小与预期的块大小匹配。
关于sha - 什么是 sha-256 填充?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/24183109/