SHA-2 (Secure Hash Algorithm 2) is a set of cryptographic hash functions. It is a signature for a data set. SHA256 algorithm generates an almost-unique, fixed 256-bit hash. It is a one way function. This makes it suitable for checking integrity of your data.
This step involves pre-processing input message to make it compatibile with the hash function. It can be divided into two main steps:
-
Padding bits
The total length of the message must be multiple of 512. In this step bits are appended to the end of message so that the final length of the message is 64 bits less than a multiple of 512. The formula below describes this step:
$m + p = (n * 512) - 64$ where:
-
$m$ - length of the message -
$p$ - length of the padding -
$n$ - constant value
The first bit appended is 1 and it is followed by all 0 bits.
Next the modulus of the original message with
$2^32$ is taken to get 64 bits of data. This makes the processed message exact multiple of 512. -
The default eight buffer values are initialized (these are hard-coded constant values representing hash values). Moreover an array k
containing 64 constants is initialized.
Pre-processed message that is
After 64 rounds the whole message is hashed and it has the length of 256 bits.