SHA-256 is a part of the SHA-2 cryptographic algorithm, it is a hash function with digest length of 256 bits. It's a keyless hash function (Manipulation Detection Code)
We want to ensure that the message has length multpile to 512 bits, thus:
- first a bit 1 is appended.
- next,
$k$ bits 0 are appended with$k$ being the solution of the equation$l+1+k = 448 \ [512]$ with$l$ the length in bits of the initial message. - finally we represent the length
$l$ with exactly 64 bits and we add these at the end of the message.
So by now, we have a message that is a multiple of 512 bits with the bit representation of the length of the initial message as the 64 last bits.
For each block
- the first 16 bits are obtained by splitting
$M$ in 32-bit blocks:$$M=W_1||W_2||...||W_{15}||W_{16}$$ - the remaining 48 are obtained as follows:
$$\forall i \in [17,64] \quad W_i = \sigma_1(W_{i-2})+W_{i-7}+\sigma_0(W_{i-15})+W_{i-16}$$ with$\sigma_0(x) = RotR(x, 7) \bigoplus RotR(x, 18) \bigoplus ShR(x, 3)$ and$\sigma_1(x) = RotR(x,17) \bigoplus RotR(x, 19) \bigoplus ShR(x, 10)$ .
The hash is the following:
- we set
$$(a,\ b,\ c,\ d,\ e,\ f,\ g,\ h)=(H_1^{(k-1)},\ H_2^{(k-1)},\ H_3^{(k-1)},\ H_4^{(k-1)},\ H_5^{(k-1)},\ H_6^{(k-1)},\ H_7^{(k-1)},\ H_8^{(k-1)})$$ - 64 times the following operations:
And then we have the new values
Real tests lol