Take the 2-minute tour ×
Cryptography Stack Exchange is a question and answer site for software developers, mathematicians and others interested in cryptography. It's 100% free, no registration required.

I have a little confusion in understanding explanation of SHA256 by FIPS

a, b, c, d, e, f, g, h

are being initialized as (this is what i don't understand)

2 . Initialize the eight working variables, $a,b,c,d,e,f,g,$ and $h$, with the $(i-1)^{st}$ hash value:

$\ \ \ \ a = H_0^{(i-1)}$
$\ \ \ \ b = H_1^{(i-1)}$
$\ \ \ \ c = H_2^{(i-1)}$
$\ \ \ \ d = H_3^{(i-1)}$
$\ \ \ \ e = H_4^{(i-1)}$
$\ \ \ \ f = H_5^{(i-1)}$
$\ \ \ \ g = H_6^{(i-1)}$
$\ \ \ \ h = H_7^{(i-1)}$

cause with this, in stage 1 of iteration, variables

a, b, c, d, e, f, g, h

would have (pre-defined) Initial Values of H. But in Calculation Stage of these variables there is no use of next stage Intermediate Hash Values H.

3 . $For\ t=0\ to\ 63:$
$\ \ \ \ \{$
$\ \ \ \ \ \ \ \ T_1=h+\sum_1^{\{256\}}(e)+Ch(e,f,g)+K_t^{\{256\}}+W_t$
$\ \ \ \ \ \ \ \ T_2=\sum_0^{\{256\}}(a)+Maj(a,b,c)$
$\ \ \ \ \ \ \ \ h=g$
$\ \ \ \ \ \ \ \ g=f$
$\ \ \ \ \ \ \ \ f=e$
$\ \ \ \ \ \ \ \ e=d+T_1$
$\ \ \ \ \ \ \ \ d=c$
$\ \ \ \ \ \ \ \ c=b$
$\ \ \ \ \ \ \ \ b=a$
$\ \ \ \ \ \ \ \ a=T_1+T_2$
$\ \ \ \ \}$

and what I see Intermediate Values are calculated with Variables not the other way around.

4 . Compute the $i^{th}$ intermediate hashvalue $H^{(i)}$:

$\ \ \ \ H_0^{(i)}=a+H_0^{(i-1)}$
$\ \ \ \ H_1^{(i)}=b+H_1^{(i-1)}$
$\ \ \ \ H_2^{(i)}=c+H_2^{(i-1)}$
$\ \ \ \ H_3^{(i)}=d+H_3^{(i-1)}$
$\ \ \ \ H_4^{(i)}=e+H_4^{(i-1)}$
$\ \ \ \ H_5^{(i)}=f+H_5^{(i-1)}$
$\ \ \ \ H_6^{(i)}=g+H_6^{(i-1)}$
$\ \ \ \ H_7^{(i)}=h+H_7^{(i-1)}$

Can you please explain to me how 2. Stage (Initialization) fit in Iteration Process of SHA256.

share|improve this question
    
I looked that code again.! It says the same thing but simpler though.. So You agree with it that we should initialize both variables (a b c d....h) and intermediate values (H0-H7) with same pre-defined initial values ?? –  Ahmad May 12 at 17:14

1 Answer 1

up vote 2 down vote accepted

The variables a, b, c, d, e, f, g, h are assigned on each round of the compression function main loop, but the interim hash values are considered only per message chunk (i.e. after all rounds have completed)

I found the Wikipedia pseudo-code easier to understand than the description in your question, and it is clear there how the variables relate to interim hash values. Note where your reference relates previous hash components $H_0^{(i)}=a+H_0^{(i-1)}$ the pseudocode just assigns h0 = a + h0, because there is no need to keep previous hash values, just a current one which is updated after processing each chunk.

Just before calculating the rounds for the each chunk, both the current H array and a, b, c, d, e, f, g, h hold the same data. This changes during calculation of the rounds, and you need to keep the value of H so it can be added back in at the end of the chunk.

When starting the first message chunk, before any processing rounds, H and a, b, c, d, e, f, g, h hold the "initial values of H" (based on square roots of first 8 primes). You do not use those initial values again.

share|improve this answer
    
So, H and Variables would be initialized with same values and on 1st round Variables would be calculated and added with H values (which would still have initial values)! and for Next 512_block H values would be preserved but Variables would be re-initialized with (pre-defined) initial values. please just verify this. –  Ahmad May 12 at 17:27
    
Not quite. For each message chunk, a, b, c, d, e, f, g, h are set to current (interim) hash. Only for the first message iteration will this be the same as the initial hash. –  Neil Slater May 12 at 17:29
1  
and this i represents the 512_block or chunk number, not the round (iteration) number? i.e: H and calculated Variables are only added once for 1 chunk. Not after every iteration. right? –  Ahmad May 12 at 17:40
    
@Ahmad: Yes. With i=0 being initial values. –  Neil Slater May 12 at 17:47
    
Thanx Man! I gotta submit this my semester project tomorrow. Really appreciate quick reply. –  Ahmad May 12 at 17:52

Your Answer

 
discard

By posting your answer, you agree to the privacy policy and terms of service.

Not the answer you're looking for? Browse other questions tagged or ask your own question.