我一直在尝试弄清SHA-256的工作原理。我为其他算法所做的一件事是我为算法制定了一种逐步的伪代码功能。
我已经尝试对SHA256执行相同的操作,但到目前为止,我遇到了很多麻烦。
我试图弄清楚维基百科图的工作方式,但是除了文本部分解释的功能之外,我不确定我是否理解正确。
这是我到目前为止的内容:
Input is an array 8 items long where each item is 32 bits.
Output is an array 8 items long where each item is 32 bits.
Calculate all the function boxes and store those values.
|I'll refer to them by function name
Store input, right shifted by 32 bits, into output.
| At this point, in the out array, E is the wrong value and A is empty
Store the function boxes.
| now we need to calculate out E and out A.
| note: I've replaced the modulo commands with a bitwise AND 2^(32-1)
| I can't figure out how the modulus adding lines up, but I think it is like this
Store (Input H + Ch + ( (Wt+Kt) AND 2^31 ) ) AND 2^31 As mod1
Store (sum1 + mod1) AND 2^31 as mod2
Store (d + mod2) AND 2^31 into output E
|now output E is correct and all we need is output A
Store (MA + mod2) AND 2^31 as mod3
Store (sum0 + mod3) AND 2^31 into output A
|output now contains the correct hash of input.
|Do we return now or does this need to be run repeatedly?
我所有这些加法模数都正确吗?还有Wt和Kt?
同样,它会运行一次就完成了吗,还是需要运行一定次,然后将输出重新用作输入。
顺便说一下,这是链接。
http://en.wikipedia.org/wiki/SHA-2#Hash_function
非常感谢,
布赖恩
最佳答案
看一下描述算法的官方标准,这里描述变量:http://csrc.nist.gov/publications/fips/fips180-4/fips-180-4.pdf
(哦,现在我知道我的答案快迟到了一年,啊,没关系...)
关于cryptography - SHA 256伪代码?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/11937192/