MD5/SHA“更新”财产?

发布于 2024-10-04 21:48:58 字数 111 浏览 5 评论 0原文

允许您“更新”它们的 MD5/SHA 属性是什么?例如,如果您有“test”的哈希值,则可以添加“case”来获取“testcase”的哈希值。我想稍微了解一下这个房产,但我的搜索没有发现任何结果......

What is the MD5/SHA property that allows you to "update" them? For example, if you have the hash for "test" you can add "case" to get the hash for "testcase". I would like to read up on this property a bit but my searches turn up nothing...

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(3

温柔少女心 2024-10-11 21:48:58

只是它们实际上是增量计算的——您通过对数据的前 n 个字节进行操作来计算它们(MD5 的情况下为 128,请参阅 http://en.wikipedia.org/wiki/MD5#Algorithm),然后是接下来的 n 个字节的数据,等等。

It is merely that they are actually calculated incrementally -- you calculate them by operating on the first n bytes of data, (128 in the case of MD5, see http://en.wikipedia.org/wiki/MD5#Algorithm), then on the next n bytes of data, etc.

三五鸿雁 2024-10-11 21:48:58

编辑:这在理论上是不可能的,因为我在下面提到了 1 位填充。实际上,md5("case", Seed=md5("test")) == md5("test" + <1-bit> + "case")。无法使用 md5("test") 增量计算 md5("test" + "case")

如果您连接 512 位块,这在理论上是可能的。它不适用于将“case”附加到“test”,因为状态机的第一次运行受到用于将“case”转换为 512 位块的填充的污染。

此外,填充不是不只是一堆零。消息总是先用 1 位填充,以便“case”和“case\0”产生不同的哈希值。因此,您不能依赖“case”具有相同的哈希值(带或不带填充)。

EDIT: This isn't even theoretically possible, due to the 1-bit padding I mention below. In effect, md5("case", seed=md5("test")) == md5("test" + <1-bit> + "case"). There is no way to use md5("test") to incrementally compute md5("test" + "case").

This is theoretically possible if you concatenate 512-bit chunks. It won't work for appending "case" to "test", because the first run of the state machine is polluted by the padding used to turn "case" into a 512-bit chunk.

Additionally, the padding isn't just a bunch of zeros. The message is always first padded with a 1 bit, so that "case" and "case\0" produce different hashes. Thus you can't rely on "case" having the same hash with or without padding.

请别遗忘我 2024-10-11 21:48:58

MD5 算法具有以下步骤:

1) pad input string to a multiple of 64 bytes
2) split input string into blocks of 64 bytes
3) initialise state (a 4-element array)
4) for each block: state <= transform(state,block)
5) encode state as string

为了支持您想要分阶段散列某些内容(例如大文件)的情况,可以按如下方式重构。

初始化:

1) initialise state
2) leftover bytes <= ""

更新:

1) append leftover bytes to start of input string
2) split input string into blocks of 64 bytes
3) for each complete block: state <= transform(state,block)
4) leftover bytes <= contents of the incomplete block, if one exists

摘要:

1) pad a copy of the leftover bytes
2) split the padded leftover bytes into blocks of 64 bytes
2) tmp_state <= state
2) for each block: tmp_state <= transform(tmp_state,block)
3) encode tmp_state as string

我实际上已经在 VBA 中实现了这种方法 - 它似乎工作得很好。关于我应该在哪里上传代码有什么建议吗?

The MD5 algorithm has the following steps:

1) pad input string to a multiple of 64 bytes
2) split input string into blocks of 64 bytes
3) initialise state (a 4-element array)
4) for each block: state <= transform(state,block)
5) encode state as string

To support situations where you want to hash something in stages (e.g. large files), this can be refactored as follows.

Initialise:

1) initialise state
2) leftover bytes <= ""

Update:

1) append leftover bytes to start of input string
2) split input string into blocks of 64 bytes
3) for each complete block: state <= transform(state,block)
4) leftover bytes <= contents of the incomplete block, if one exists

Digest:

1) pad a copy of the leftover bytes
2) split the padded leftover bytes into blocks of 64 bytes
2) tmp_state <= state
2) for each block: tmp_state <= transform(tmp_state,block)
3) encode tmp_state as string

I've actually implemented this approach in VBA - it seems to work fine. Any suggestions for where I should upload the code?

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文