I've been trying to work out how SHA-256 works. One thing I've been doing for other algorithms is I've worked out a sort of step by step pseudocode function for the algorithm.
I've tried to do the same for SHA256 but thus far I'm having quite a bit of trouble.
I've tried to work out how the Wikipedia diagram works but besides the text part explaining the functions I'm not sure I've got it right.
Here's what I have so far:
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.bitwise AND 2^(32-1)
I can't figure out how the modulus adding lines up, but I think it is like this:
H
+ Ch + ( (Wt+Kt) AND 2^31 ) ) AND 2^31 As mod1
sum1
+ mod1
) AND 2^31 as mod2
mod2
) AND 2^31 into output E
mod2
) AND 2^31 as mod3
sum0
+ mod3
) AND 2^31 into output A
Did I get all of those addition modulos right?
what are Wt and Kt?
Would this get run once, and you're done or does it need to be run a certain number of times, with the output being re-used as input?
Here's the link by the way. http://en.wikipedia.org/wiki/SHA-2#Hash_function
Thanks alot, Brian
Have a look at the official standard that describes the algorithm, the variables are described here: http://csrc.nist.gov/publications/fips/fips180-4/fips-180-4.pdf
(Oh, now I see I'm almost a year late with my answer, ah, never mind...)