[Day 1] 5. Hash Function
What is Hashing?
- Hashing is not encryption.
- A hash function is a mathematical function that takes a variable-length input (message) and generates a fixed-length output called a hash value.
- Creates a unique "fingerprint" of data.
Key Characteristics of Hash Functions
- Uniqueness:
- Hash values are technically unique for each input.
- Ensures data integrity as even a small change in input drastically changes the hash value.
- One-Way Function:
- Hashing is a one-way process (infeasible to reverse mathematically).
- Note: While theoretically irreversible, some decrypters can reverse weak hashes like using precomputed tables. Not possible for a human to reverse it.
md5
- Integrity Assurance:
- Hashing ensures the Integrity aspect of the CIA Triad.
- Efficient Searching:
- Hashing reduces the computational load during data searches.
Hashing Commands in Linux
-
:
md5sum-
Calculate the MD5 hash of a file:
bashmd5sum file.txt -
Verify MD5 sums from a file (e.g.,
):hash.md5bashmd5sum -c hash.md5here
is a file that contains the file names and their hashed values.hash.md5
-
-
Other Useful Commands:
- : View the hexadecimal content of a file.
hexdump - : Similar to
xxd, but often more human-readable.hexdump - : Compare files line by line for differences.
diff
Hash Collision
- A hash collision occurs when two different inputs generate the same hash value.
- MD5 Vulnerability:
- MD5 is prone to collisions and is therefore considered broken and deprecated.
- Algorithms like SHA-256 or higher are recommended for better security.
- Impact
- Hash collisions can undermine the security of cryptographic systems, as they may allow attackers to substitute one input for another without detection.
Note: Hash collisions occur in the MD5 hashing algorithm because it produces a fixed 128-bit hash value, meaning there are a finite number of possible outputs. As the input space is vastly larger than the output space, different inputs can map to the same hash value. Additionally, vulnerabilities in MD5's design, such as weaknesses in its compression function and lack of resistance to differential cryptanalysis, make it easier to deliberately craft collisions.
Important Notes on Hash Collisions
- Hashing works on content, not file names.
- Example: Files with different names but identical content will have the same hash value.
- Cause of Collision:
- Hashing reduces a large key to a smaller hash value, increasing the likelihood of two different inputs producing the same hash.
Read Next
[Day 1] 6. TCPdump
### **1. About TCPDump** - **TCPDump** is a command-line packet capturing tool. - It is considered the **father of Wireshark** but lacks a GUI....
[Day 1] 7. Extra
1. **Ping Command Behavior** - Using the `-c` flag in the `ping` command to limit the number of packets sent to the target IP. - In **Linux*...