SHA-256 Padding

随声附和 提交于 2019-12-22 12:17:09

问题


To calculate the SHA-256 hash I need to pad my message. Am using the following description: (taken from http://csrc.nist.gov/groups/STM/cavp/documents/shs/sha256-384-512.pdf)

Pad the message in the usual way: Suppose the length of the message M, in bits, is l. Append the bit "1" to the end of the message, and then k zero bits, where k is the smallest non-negative solution to the equation l+1+k 448 mod 512. To this append the 64-bit block which is equal to the number l written in binary

But what should one do if the message length in bits is less than 64-bits short of a 512bit block... i.e., there isn't room for the end 64-bit block mentioned above? Or the 64-bit length and the "1" bit?

I had a look on wikipedia too, but this doesn't throw any more light on the subject. Google searches haven't been too fruitful either, would appreciate any suggestions :)

Thanks


回答1:


If your message is only just short of a full block (less than 65 bits short), you will need your output to be a block longer than your input. In the worst case, if your message is exactly 64 bits short of a full block, you will add a 1 and then 511 0s before the "number" bits, but that is how the padding has to work.



来源:https://stackoverflow.com/questions/16983301/sha-256-padding

标签
易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!