优化我更新MD5 / SHA1零流 [英] Optimise updating MD5/SHA1 with streams of zeros
问题描述
是否有可能优化功能:
MD5_Update(&ctx_d, buf, num);
如果您知道 BUF
只包含零?
或者,这是数学上是不可能?
Or is this mathematically impossible?
同样为SHA1。
推荐答案
如果你控制的散列函数的输入,那么你可以使用一个简单的计数,而不是所有的零的,可能使用一些逃避的。例如。 000020十六进制可能意味着32零。 A(非常)基本的COM pression功能可能比MD5或SHA-1快多了。
If you control the input of the hash function then you could use a simple count instead of all the zero's, maybe using some kind of escape. E.g. 000020 in hex could mean 32 zero's. A (very) basic compression function may be much faster than MD5 or SHA1.
显然,如果在保存的散列计算中的一个或多个块这种解决方案将只更快。例如。如果散列3个字节或16个字节,如在使用前的输入将被填充和扩大由散列函数也没关系。
Obviously this solution will only be faster if you save one or more blocks of hash calculations. E.g. it does not matter if you hash 3 bytes or 16 bytes, as the input will be padded and expanded by the hash function before it is used.
这篇关于优化我更新MD5 / SHA1零流的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!