Cryptocurrency · 2015
Secure Hash Standard (SHS): SHA-256
Excerpt · FIPS PUB 180-4 · August 2015
- Source
- nvlpubs.nist.gov
- Retrieved
- 27 September 2026
- License
- Public domain (U.S. Government work)
- Rights holder
- National Institute of Standards and Technology, 2015
- Language
- English
About this edition and its rights
Edition
FIPS PUB 180-4, Secure Hash Standard (SHS), August 2015 (https://doi.org/10.6028/NIST.FIPS.180-4), the PDF published by NIST (36 pages, 833315 bytes, SHA-256 0455b406d89648d20cbde375561e19c245b9815e894164c2670772e3d54deb82). Excerpt: the abstract (its two sentences, without the key words) in the header, then the sections that define SHA-256, complete and in their order: 2.2.1 Parameters, 2.2.2 Symbols and Operations, 4.1.2 SHA-224 and SHA-256 Functions, 4.2.2 SHA-224 and SHA-256 Constants, 5.1.1 (padding), 5.2.1 (parsing), 5.3.3 (initial hash value of SHA-256), 6.2 SHA-256 with 6.2.1 and 6.2.2; the other sections, and the headings of sections 2.2, 5, 5.1, 5.2 and 5.3 with their introductions, are left out. The prose comes from pdftotext and was checked word for word against the pages; four words split at a line end are rejoined with the hyphen of the printed page (w-bit, 32-bit, right-most, SHA-256). Formulas, the padding example and the hash computation, which pdftotext cannot read, are set in KaTeX from the page scans, with the symbols of the Standard (the assignments of 6.2.2 are “=” as printed). The 64 constants of 4.2.2 are set eight to a row as printed; they and the initial hash value were checked against the cube and square roots of the first primes. Superscript ordinals (ith, jth, tth, (i-1)st) and the italics and bold of the page are kept.
Rights
In the United States, a work of the federal government (17 U.S.C. 105): the Standard was prepared and issued by the National Institute of Standards and Technology, an agency of the U.S. Department of Commerce, and carries no copyright notice. In France, the rule of the shorter term (article L. 123-12 of the Code de la propriété intellectuelle, after article 7(8) of the Berne Convention): for a work whose country of origin is outside the European Union and whose author is not a national of a member state, the protection lasts as long as in the country of origin, which grants none.
NIST, Copyrights and Disclaimers (https://www.nist.gov/oism/copyrights, read on 27 September 2026): “With the exception of material marked as copyrighted, information presented on NIST sites are considered public information and may be distributed or copied. Use of appropriate byline/photo/image credits is requested.” The PDF has no copyright mark.
Abstract This standard specifies hash algorithms that can be used to generate digests of messages. The digests are used to detect whether messages have been changed since the digests were generated.
2.2.1 Parameters#
The following parameters are used in the secure hash algorithm specifications in this Standard.
Working variables that are the -bit words used in the computation of the hash values, .
The ith hash value. is the initial hash value; is the final hash value and is used to determine the message digest.
The jth word of the ith hash value, where is the left-most word of hash value .
Constant value to be used for the iteration of the hash computation.
Number of zeroes appended to a message during the padding step.
Length of the message, , in bits.
Number of bits in a message block, .
Message to be hashed.
Message block , with a size of bits.
The jth word of the ith message block, where is the left-most word of message block .
Number of bits to be rotated or shifted when a word is operated upon.
Number of blocks in the padded message.
Temporary -bit word used in the hash computation.
Number of bits in a word.
The tth -bit word of the message schedule.
2.2.2 Symbols and Operations#
The following symbols are used in the secure hash algorithm specifications; each operates on -bit words.
Bitwise AND operation.
Bitwise OR (“inclusive-OR”) operation.
Bitwise XOR (“exclusive-OR”) operation.
Bitwise complement operation.
Addition modulo .
Left-shift operation, where is obtained by discarding the left-most bits of the word and then padding the result with zeroes on the right.
Right-shift operation, where is obtained by discarding the right-most bits of the word and then padding the result with zeroes on the left.
The following operations are used in the secure hash algorithm specifications:
The rotate left (circular left shift) operation, where is a -bit word and is an integer with , is defined by .
The rotate right (circular right shift) operation, where is a -bit word and is an integer with , is defined by .
The right shift operation, where is a -bit word and is an integer with , is defined by .
4.1.2 SHA-224 and SHA-256 Functions#
SHA-224 and SHA-256 both use six logical functions, where each function operates on 32-bit words, which are represented as , , and . The result of each function is a new 32-bit word.
4.2.2 SHA-224 and SHA-256 Constants#
SHA-224 and SHA-256 use the same sequence of sixty-four constant 32-bit words, . These words represent the first thirty-two bits of the fractional parts of the cube roots of the first sixty-four prime numbers. In hex, these constant words are (from left to right)
5.1.1 SHA-1, SHA-224 and SHA-256#
Suppose that the length of the message, , is bits. Append the bit “1” to the end of the message, followed by zero bits, where is the smallest, non-negative solution to the equation . Then append the 64-bit block that is equal to the number expressed using a binary representation. For example, the (8-bit ASCII) message “abc” has length , so the message is padded with a one bit, then zero bits, and then the message length, to become the 512-bit padded message
The length of the padded message should now be a multiple of 512 bits.
5.2.1 SHA-1, SHA-224 and SHA-256#
For SHA-1, SHA-224 and SHA-256, the message and its padding are parsed into 512-bit blocks, . Since the 512 bits of the input block may be expressed as sixteen 32-bit words, the first 32 bits of message block are denoted , the next 32 bits are , and so on up to .
5.3.3 SHA-256#
For SHA-256, the initial hash value, , shall consist of the following eight 32-bit words, in hex:
These words were obtained by taking the first thirty-two bits of the fractional parts of the square roots of the first eight prime numbers.
6.2 SHA-256#
SHA-256 may be used to hash a message, , having a length of bits, where . The algorithm uses 1) a message schedule of sixty-four 32-bit words, 2) eight working variables of 32 bits each, and 3) a hash value of eight 32-bit words. The final result of SHA-256 is a 256-bit message digest.
The words of the message schedule are labeled . The eight working variables are labeled , , , , , , , and . The words of the hash value are labeled , which will hold the initial hash value, , replaced by each successive intermediate hash value (after each message block is processed), , and ending with the final hash value, . SHA-256 also uses two temporary words, and .
6.2.1 SHA-256 Preprocessing#
- Set the initial hash value, , as specified in Sec. 5.3.3.
- The message is padded and parsed as specified in Section 5.
6.2.2 SHA-256 Hash Computation#
The SHA-256 hash computation uses functions and constants previously defined in Sec. 4.1.2 and Sec. 4.2.2, respectively. Addition (+) is performed modulo .
Each message block, , is processed in order, using the following steps:
For =1 to :
{
1. Prepare the message schedule, :
2. Initialize the eight working variables, , , , , , , , and , with the (i-1)st hash value:
3. For =0 to 63:
4. Compute the ith intermediate hash value :
}
After repeating steps one through four a total of times (i.e., after processing ), the resulting 256-bit message digest of the message, , is