0
0
Gitdevops~10 mins

SHA-1 hashing concept in Git - Step-by-Step Execution

Choose your learning style9 modes available
Process Flow - SHA-1 hashing concept
Input Data
Preprocessing
Split into Blocks
Initialize Hash Values
Process Each Block
Compression Function
Update Hash
Final SHA-1 Hash Output
SHA-1 takes input data, processes it in blocks through a compression function, and produces a fixed 40-character hash string.
Execution Sample
Git
echo -n "hello" | sha1sum
2aae6c35c94fcfb415dbe95f408b9ce91ee846ed  -
This command computes the SHA-1 hash of the string "hello" and outputs the hash.
Process Table
StepActionInput/StateOutput/State
1Input Data"hello""hello"
2Preprocessing"hello""hello" + padding + length info
3Split into BlocksPreprocessed dataOne 512-bit block
4Initialize Hash ValuesN/A5 initial 32-bit words (h0-h4)
5Process Block512-bit block + h0-h480 words prepared for rounds
6Compression Function80 words + h0-h4Updated h0-h4 values
7Update HashUpdated h0-h4Final 160-bit hash
8Output Hash160-bit hash"2aae6c35c94fcfb415dbe95f408b9ce91ee846ed" (hex)
💡 All blocks processed; final 160-bit SHA-1 hash produced as hex string.
Status Tracker
VariableStartAfter Step 4After Step 6Final
Input Data"hello""hello""hello" + padding"hello" + padding
BlocksN/AN/AOne 512-bit blockOne 512-bit block
h0-h4N/AInitial constantsUpdated by compressionFinal hash words
Hash OutputN/AN/AN/A"2aae6c35c94fcfb415dbe95f408b9ce91ee846ed"
Key Moments - 3 Insights
Why does the input data get padded before processing?
Padding ensures the data length is a multiple of 512 bits, which is required for SHA-1 to process data in fixed-size blocks, as shown in step 2 and 3 of the execution table.
What are h0 to h4 in the SHA-1 process?
They are initial fixed 32-bit words used as starting hash values, updated during processing (steps 4 to 6), eventually forming the final hash output.
Why is the final output a 40-character string?
Because SHA-1 produces a 160-bit (20-byte) hash, which is represented as 40 hexadecimal characters (2 hex chars per byte), as shown in step 8.
Visual Quiz - 3 Questions
Test your understanding
Look at the execution table, what is the state of h0-h4 after step 4?
AInitial constants ready for processing
BFinal hash values
CInput data padded
DBlocks split into 512-bit chunks
💡 Hint
Refer to step 4 in the execution table where hash values are initialized.
At which step does the input data get split into blocks?
AStep 5
BStep 2
CStep 3
DStep 7
💡 Hint
Check the 'Split into Blocks' action in the execution table.
If the input string changes, which part of the execution table will definitely change?
AInitialize Hash Values
BCompression Function output
CPadding step only
DFinal output hash remains same
💡 Hint
Look at how the compression function output depends on input data blocks and hash values.
Concept Snapshot
SHA-1 hashing:
- Input data is padded to multiple of 512 bits
- Data split into 512-bit blocks
- Initial hash values (h0-h4) set
- Each block processed with compression function
- Final output is 160-bit hash (40 hex chars)
- Used in git to identify objects uniquely
Full Transcript
SHA-1 hashing takes any input data and processes it to produce a fixed-length 40-character hexadecimal string. The process starts by padding the input so its length is a multiple of 512 bits. Then the data is split into 512-bit blocks. Five initial hash values (h0 to h4) are set as constants. Each block is processed through a compression function that updates these hash values. After all blocks are processed, the final 160-bit hash is output as a 40-character hex string. This hash uniquely represents the input data and is used in git to track files and commits.