Cryptographic Hash Function (CHF)

  • Hash function: binary binary with fixed size
  • Although not necessary, They all have time complexity of O(N)
  • It is expected to have a collision resistance strength of bits, due to Birthday Paradox
  • Uses:
    • Digital Signatures
    • Authentication
    • Checksums
    • Message Digests (example HMAC)
  • MD5 and SHA-1 should be avoided to build critical (like password) systems
  • Examples
    • MD5
    • SHA-1

MD5

  • Message Digest Algorithm
  • Created in 1992
  • Broken in 2004
  • Designed by Robert Rivest
  • Output: 16 bytes
# Linux
md5sum <file>
 
# MacOS
md5 <file>

SHA

  • Secure Hash Algorithm
  • SHA-1
    • Created in 1995
    • Broken in 2005
    • Output: 20 bytes
  • SHA-2
    • SHA-256
      • Created in 2001
      • Output: 32 bytes (256 bits)
    • SHA-512
      • Created in 2001
      • Output: 64 bytes (512 bits)
  • SHA-3
    • Created in 2013
# Linux
shasum <file>
sha256sum <file>
sha512sum <file>
 
# MacOS
shasum <file>
shasum -256 <file>
shasum -512 <file>

Comparison

AlgoOutput Size
(bytes)
RoundsCollision Resistance
(in bits)
First PublishedBroken
MD51646419922004
SHA-120808019952005
SHA-256
(SHA-2)
32641282001-
SHA-512
(SHA-2)
64802562001-

Security

  • Basic security can be calculated using the following:
    • Pre-image resistance
      • Given value , difficult to find such that
      • Given final hash value, find input message
    • Second pre-image resistance (aka Weak Collision resistance)
      • Given message , difficult to find such that
      • Given input message, find another input message with same hash value
    • Collision resistance
      • Nothing given, we need to find and such that
      • find arbitrarily two messages with same hash value
      • Birthday Paradox puts upper bound to collision resistance
      • Automatically implies weak collision resistance but not pre-image resistance
  • A primitive offers  bits of security if the best known attack against that primitive takes roughly  operations
  • Theoretically MD5 and SHA-1 should be collision resistant but they were still broken using various techniques
  • https://crypto.stackexchange.com/questions/86971/bits-of-security-vs-collision-resistance

Birthday Paradox

  • In a set of randomly chosen people, at least two will share same birthday
  • Surprisingly, only 23 people are needed for that probability to exceed 50%
  • For hash function which outputs bits, its security for collision resistance is because of Birthday Paradox
    • which means operations are required to find collision