SHA
Slide deck 14: SHA-1 history and family, 512-bit block processing with the F/W/K machinery, SHA-1 versus MD5, and the SHA-512 round function.
SHA history and familySearch on YouTube
OriginsSearch on YouTube
- NIST and NSA designed SHA in 1993.
- In 1995, it was revised as SHA-1.
- It is the US standard for use with the DSA signature scheme.
- The standard is FIPS 180-1 1995, also Internet RFC 3174.
- The algorithm is SHA. The standard is SHS.
- It is based on the design of MD5, with key differences.
- It produces 160-bit hash values.
- Results from 2005 on the security of SHA-1 raised concerns about its use in future applications.
SHA familySearch on YouTube
| Version | Year | What to recall |
|---|---|---|
| SHA-0 | 1993 | First version, later withdrawn due to security flaws |
| SHA-1 | 1995 | 160-bit (20-byte) hash; widely used in SSL/TLS, Git, digital signatures; broken: collision attacks are feasible, not secure now |
| SHA-2 | 2001 | SHA-224, SHA-256, SHA-384, SHA-512, SHA-512/224, SHA-512/256; still secure; Merkle-Damgard construction, 512 or 1024 bit blocks; used in SSL/TLS, certificates, Bitcoin, blockchain |
| SHA-3 | 2015 | Keccak algorithm, designed differently from SHA-2, resistant even if SHA-2 is broken; SHA3-224/256/384/512, plus extendable-output functions SHAKE128 and SHAKE256 |
The bit length in the name gives the output size.
Family order by year: 0-1-2-3 = withdrawn, broken, secure, new. SHA-0 is withdrawn. Collision attacks break SHA-1. SHA-2 is still secure. SHA-3 (Keccak) is a different design.
Revised secure hash standardSearch on YouTube
- NIST issued the revision FIPS 180-2 in 2002.
- It adds 3 more versions of SHA: SHA-256, SHA-384, SHA-512. Each has a different digest length in bits.
- Their design gives security compatible with the increased security of the AES cipher.
- The structure and detail are similar to SHA-1, so the analysis is similar.
- The security levels are higher.
SHA-1 algorithmSearch on YouTube
ParametersSearch on YouTube
The "How SHA works" slide gives these values for SHA-1:
| Parameter | Value |
|---|---|
| Digest length | 160 bit |
| Input text (block) | 512 bit |
| Sub-block size | 32 bit |
| Total sub-blocks | |
| Number of rounds | 4 |
| Iterations per round | 20 |
| Chaining variable | bit |
| constant | to |
The slide gives the output as "four 32-bit blocks". This is an error. The buffer has five 32-bit words, and bits.
All sizes are multiples of the 32-bit word:
One 512-bit block expands to 80 words. The 80 words go through 4 rounds of 20 steps and update a 5-word chaining buffer.
Overview stepsSearch on YouTube
- Padding: pad the message until its length is 64 bits short of a multiple of 512.
- Append length: append a 64-bit value that gives the length of the original message.
- Divide the input into 512-bit blocks.
- Initialise the CV, a 5-word (160-bit) buffer .
- Process the blocks in 16-word (512-bit) chunks:
- Copy the CV into a single register. This register holds the intermediate and the final results.
- Divide the current 512-bit block into 16 sub-blocks of 32 bits each.
- Do 4 rounds of 20 steps each on the message block and the buffer.
- Expand the 16 words into 80 words () by mixing and shifting. Use for to .
- Add the output to the input to get the new buffer value.
- Output: the hash value is the final buffer value.
Initial bufferSearch on YouTube
The slide gives the initial values byte by byte:
| Word | Slide value | FIPS 180 word value |
|---|---|---|
| A | 01 23 45 67 | 67452301 |
| B | 89 AB CD EF | EFCDAB89 |
| C | FE DC BA 98 | 98BADCFE |
| D | 76 54 32 10 | 10325476 |
| E | C3 D2 E1 F0 | C3D2E1F0 |
The slide lists the bytes of A to D from low-order to high-order. The standard writes each word as a big-endian hex number.
SHA-1 compression functionSearch on YouTube
Block processingSearch on YouTube
Figure 12.5 shows how SHA-1 processes one 512-bit block :
| Round | Function | Words used | Steps |
|---|---|---|---|
| 1 | , | 20 | |
| 2 | , | 20 | |
| 3 | , | 20 | |
| 4 | , | 20 |
The chaining value comes in as 160 bits (five 32-bit words ). After round 4, five adders add each word to the matching word of . The result is (160 bits). Addition is mod .
Step functionSearch on YouTube
The slide gives the step as:
The slide says that the buffer shifts "right by 1 bit" for the next step. The figure shows a shift of one word position, not one bit. In full notation, each of the 20 steps in a round replaces the 5 buffer words thus:
| Term | Meaning |
|---|---|
| The 5 words of the buffer | |
| Step number, | |
| Non-linear function for the round | |
| Word derived from the message block | |
| Constant value | |
| Circular left shift of the 32-bit sub-block by bits |
How to read the update:
- The new is the sum .
- The old moves to .
- The old rotates left 30 bits and moves to .
- The old moves to , and the old moves to .
Round functionsSearch on YouTube
| Round | Steps | Function |
|---|---|---|
| Round 1 | , same as MD5 | |
| Round 2 | ||
| Round 3 | ||
| Round 4 |
Round 1 is a selection: if then , else . Rounds 2 and 4 give the parity. Round 3 gives the majority, which is true when two or three of are true.
Round functions in order: If, Parity, Majority, Parity (IPMP).
ConstantsSearch on YouTube
The slides define as a constant for each step, to . The standard (FIPS 180-1) uses one value for each round:
| Round | range | (hex) | Source |
|---|---|---|---|
| 1 | floor | ||
| 2 | floor | ||
| 3 | floor | ||
| 4 | floor |
Message scheduleSearch on YouTube
Figure 12.7 shows the creation of the 80-word input . The expansion adds redundancy and interdependence among message blocks.
- Words are the 16 words of the 512-bit block .
- For to , four earlier words go into an XOR, and rotates the result 1 bit to the left:
| Word built | Inputs (figure) |
|---|---|
| , then | |
| , then |
Each new word depends on many earlier words. Thus a change in one message word spreads through the schedule.
ComparisonsSearch on YouTube
SHA-1 versus MD5Search on YouTube
| Point | SHA-1 | MD5 |
|---|---|---|
| Brute-force attack | Harder: 160-bit digest | Easier: 128-bit digest |
| Known attacks | Not vulnerable to any known attacks (compared to MD4/5), at the time of the slide | MD4/5 have known attacks |
| Speed | A little slower (80 steps) | Faster (64 steps) |
| Design | Simple and compact | Simple and compact |
| Endianness | Optimised for big-endian CPUs (SUN) | Optimised for little-endian CPUs (PC) |
SHA-1 has 32 more digest bits than MD5, but it needs 16 more steps. MD5 is faster. SHA-1 is stronger.
Table 12.3Search on YouTube
| Property | SHA-1 | SHA-256 | SHA-384 | SHA-512 |
|---|---|---|---|---|
| Message digest size | 160 | 256 | 384 | 512 |
| Message size | ||||
| Block size | 512 | 512 | 1024 | 1024 |
| Word size | 32 | 32 | 64 | 64 |
| Number of steps | 80 | 80 | 80 | 80 |
| Security | 80 | 128 | 192 | 256 |
Notes from the table: all sizes are in bits. "Security" means that a birthday attack on a message digest of size produces a collision with a work factor of approximately .
SHA-1 versus SHA-512Search on YouTube
| Stage | SHA-1 | SHA-512 |
|---|---|---|
| Block size | 512 bits | 1024 bits |
| Length field | 64 bits | 128 bits |
| Buffer | (160 bits) | (512 bits) |
| Word size | 32 bits | 64 bits |
| Steps | 4 rounds of 20 steps | 80 rounds |
| Schedule | 16 words to 80, of a four-way XOR | 16 words to 80, with and |
| Addition | mod | mod |
| Constants | , one for each round | from cube roots of the first 80 primes |
SHA-512Search on YouTube
Setup stepsSearch on YouTube
- Padding.
- Append length.
- Divide the input into 1024-bit blocks. The padded message is the message ( bits), then a 1 and zeros (100...0), then a 128-bit length field. The total is bits.
- Initialise the chaining variable: bits, in eight 64-bit words .
- Process the blocks. This is the heart of the algorithm:
- Process the message in 1024-bit blocks.
- Each block goes through 80 rounds that update the 512-bit buffer (the temporary chaining variables).
- Each round uses a 64-bit value from the current message block.
- Each round uses a round constant based on the cube roots of the first 80 prime numbers.
The chaining is as follows. and block go into function . Word-by-word addition mod of and the output of gives . This continues to , which is the hash code.
Round functionSearch on YouTube
The slide describes each of the 80 steps for one block. The slide says "512-bit block", but the block is 1024 bits and the buffer is 512 bits. Each round uses these equations:
| Term | Definition |
|---|---|
| Step (round) number, | |
| , the conditional function: if then else | |
| , true only if a majority (two or three) of the arguments are true | |
| Circular right shift (rotation) of the 64-bit argument by bits | |
| A 64-bit word derived from the current input block | |
| A 64-bit additive constant | |
| Addition modulo |
collects , Ch, , and . collects and Maj. The new gets both: . The new gets only : . All other words move down one register.
Message scheduleSearch on YouTube
The schedule expands the 16 words of block (64 bits each) into 80 words. For to , the figure combines four earlier words:
For example, uses , , and . The figure labels the combining box "XOR". The standard (FIPS 180) uses addition mod .
| Symbol | Meaning |
|---|---|
| Rotate right by bits (within 64 bits) | |
| Logical right shift by bits (zero-fill) | |
| Bitwise XOR |
The slide prints the line as and . The correct exponents are and .
Quick self-testSearch on YouTube
Who designed SHA, and what are the standards and revisions?
NIST and NSA designed SHA in 1993. It was revised in 1995 as SHA-1. The standard is FIPS 180-1 (1995), also Internet RFC 3174. The algorithm is SHA, and the standard is SHS. FIPS 180-2 (2002) adds SHA-256, SHA-384 and SHA-512 for compatibility with AES security.
Summarise the four SHA family generations.
SHA-0 (1993): first version, withdrawn due to security flaws. SHA-1 (1995): 160-bit hash, used in SSL/TLS, Git and signatures, now broken by collision attacks. SHA-2 (2001): SHA-224/256/384/512, SHA-512/224 and SHA-512/256, Merkle-Damgard, still secure. SHA-3 (2015): Keccak, a different design, includes SHAKE128 and SHAKE256.
Give the SHA-1 parameters from the "How SHA works" slide.
Digest length 160 bit. Input text 512 bit. Sub-block size 32 bit, so sub-blocks. 4 rounds with 20 iterations each. Chaining variable bit. constant for to .
List the six SHA-1 overview steps and the buffer initial values.
Pad to 64 bits short of a multiple of 512. Append the 64-bit message length. Divide into 512-bit blocks. Initialise the buffer: A = 01234567, B = 89ABCDEF, C = FEDCBA98, D = 76543210, E = C3D2E1F0. Process each block in 4 rounds of 20 steps and add the output to the input. Output the final buffer.
Write the SHA-1 buffer update equation and name its terms.
. The terms are the 5 buffer words, the step number , the round function , the message word and the constant . is a circular left shift of a 32-bit word by bits.
Give the four SHA-1 round functions.
Round 1: , same as MD5. Round 2: . Round 3: . Round 4: .
How does SHA-1 create the 80-word input , and why?
are the message words. For , . For example, uses . The expansion adds redundancy and interdependence among message blocks.
Compare SHA-1 with MD5.
A brute-force attack is harder on SHA-1 (160 bits against 128 bits). At the time of the slide, SHA-1 had no known attacks, unlike MD4/5. SHA-1 is a little slower (80 steps against 64). Both are simple and compact. SHA-1 is optimised for big-endian CPUs (SUN), MD5 for little-endian CPUs (PC).
Fill table 12.3 for SHA-1 and SHA-512.
SHA-1: digest 160, message , block 512, word 32, steps 80, security 80. SHA-512: digest 512, message , block 1024, word 64, steps 80, security 256. Security is the birthday work factor, about .
Give the SHA-512 round equations and with their functions.
, with . , with . Then and . The other words move down one register.
- NIST and NSA designed SHA in 1993. It became SHA-1 in 1995 (FIPS 180-1, RFC 3174). SHA-0 is withdrawn, SHA-1 is broken for collisions, SHA-2 is secure and SHA-3 (Keccak) is a new design.
- SHA-1: 512-bit blocks, 16 sub-blocks of 32 bits, 4 rounds of 20 steps, a 160-bit buffer and for to .
- Steps: pad, append the 64-bit length, divide into 512-bit blocks, initialise the buffer, process the blocks, output the final buffer.
- The step adds to , and rotates left 30 bits. Round functions: If, Parity, Majority, Parity. The schedule expands 16 words to 80 with a four-way XOR and .
- SHA-1 against MD5: 160 against 128 digest bits, 80 against 64 steps, big-endian against little-endian.
- FIPS 180-2 (2002) adds SHA-256/384/512. Table 12.3 gives security 80, 128, 192 and 256 bits.
- SHA-512: 1024-bit blocks, a 128-bit length field, eight 64-bit words, 80 rounds mod . and .
SHA: Secure Hashing Algorithm - Computerphile
How Does SHA-1 Work - Intro to Cryptographic Hash Functions and SHA-1