Top Banner
Cryptographic hash functions
19

Cryptographic hash functions - University Of Maryland · Applications of hash functions •Virus fingerprinting •Deduplication •Password hashing ... •Uses hash function to index

Apr 24, 2018

Download

Documents

hatuong
Welcome message from author
This document is posted to help you gain knowledge. Please leave a comment to let me know what you think about it! Share it to your friends and learn new things together.
Transcript
Page 1: Cryptographic hash functions - University Of Maryland · Applications of hash functions •Virus fingerprinting •Deduplication •Password hashing ... •Uses hash function to index

Cryptographic hash functions

Page 2: Cryptographic hash functions - University Of Maryland · Applications of hash functions •Virus fingerprinting •Deduplication •Password hashing ... •Uses hash function to index

Definition of hash function

• 𝐻 ≔ {ℎ1, … , ℎ𝑚}• ℎ𝑖 ∶ 0,1 𝑛 → 0,1 ℓ(𝑛)

• Compression : ℓ 𝑛 < 𝑛

• 𝐺𝑒𝑛 1𝑠 picks an index between 1 and m.

Page 3: Cryptographic hash functions - University Of Maryland · Applications of hash functions •Virus fingerprinting •Deduplication •Password hashing ... •Uses hash function to index

Collision resistance

𝑥, 𝑥′

𝑖 ← 𝑔𝑒𝑛({1}𝑠)i

𝑤𝑖𝑛𝑠 if ℎ𝑖 𝑥 = ℎ𝑖(𝑥′)

Page 4: Cryptographic hash functions - University Of Maryland · Applications of hash functions •Virus fingerprinting •Deduplication •Password hashing ... •Uses hash function to index

Second-collision resistant

𝑥′

𝑖 ← 𝑔𝑒𝑛({1}𝑠)𝑥 ∈𝑅 0,1 𝑠𝑖, 𝑥

𝑤𝑖𝑛𝑠 if ℎ𝑖 𝑥 = ℎ𝑖(𝑥′)

Page 5: Cryptographic hash functions - University Of Maryland · Applications of hash functions •Virus fingerprinting •Deduplication •Password hashing ... •Uses hash function to index

Preimage resistance

𝑥

𝑖 ← 𝑔𝑒𝑛({1}𝑠)

y ∈𝑅 0,1 ℓ(𝑠)𝑖, 𝑦

𝑤𝑖𝑛𝑠 if ℎ𝑖 𝑥 = 𝑦

Page 6: Cryptographic hash functions - University Of Maryland · Applications of hash functions •Virus fingerprinting •Deduplication •Password hashing ... •Uses hash function to index

Comparison between different security

𝑥, 𝑥′

𝑖 ← 𝑔𝑒𝑛({1}𝑠)i

𝑤𝑖𝑛𝑠 if ℎ𝑖 𝑥 = ℎ𝑖(𝑥′)

𝑥′

𝑖 ← 𝑔𝑒𝑛({1}𝑠)𝑥 ∈𝑅 0,1 𝑠𝑖, 𝑥

𝑤𝑖𝑛𝑠 if ℎ𝑖 𝑥 = ℎ𝑖(𝑥′)

𝑥

𝑖 ← 𝑔𝑒𝑛({1}𝑠)

y ∈𝑅 0,1 ℓ(𝑠)𝑖, 𝑦

𝑤𝑖𝑛𝑠 if ℎ𝑖 𝑥 = 𝑦

𝑐𝑜𝑙𝑙𝑖𝑠𝑖𝑜𝑛 𝑟𝑒𝑠𝑖𝑠𝑡𝑎𝑛𝑡 𝑡𝑎𝑟𝑔𝑒𝑡 − 𝑐𝑜𝑙𝑙𝑖𝑠𝑖𝑜𝑛 𝑟𝑒𝑠𝑖𝑠𝑡𝑎𝑛𝑐𝑒 𝑝𝑟𝑒𝑖𝑚𝑎𝑔𝑒 𝑟𝑒𝑠𝑖𝑠𝑡𝑎𝑛𝑡

Page 7: Cryptographic hash functions - University Of Maryland · Applications of hash functions •Virus fingerprinting •Deduplication •Password hashing ... •Uses hash function to index

Birthday attack

• What is the probability that in a class of 23 people there are at least two people with the same birthday. • Answer: more than 50% chance

• General question: Suppose you sample m values from n values, what is the probability that there exists at least two values that are the same.• Answer: if 𝑚 = 𝑛 then probability is about one-half

Page 8: Cryptographic hash functions - University Of Maryland · Applications of hash functions •Virus fingerprinting •Deduplication •Password hashing ... •Uses hash function to index

Proof of the birthday attack

• If you store 𝑛 output with a given input the probability that a new input gets sent to a previously visited output is 1/ 𝑛

• The probability that 𝑛 elements all get mapped to fresh output is

1 −1

𝑛

𝑛≥ 1/𝑒

Page 9: Cryptographic hash functions - University Of Maryland · Applications of hash functions •Virus fingerprinting •Deduplication •Password hashing ... •Uses hash function to index

Mac using hash functions

𝑚

𝐻𝑖

𝑚𝑎𝑐𝑘

Page 10: Cryptographic hash functions - University Of Maryland · Applications of hash functions •Virus fingerprinting •Deduplication •Password hashing ... •Uses hash function to index

HMAC

• Global constants 𝑣1, 𝑣2• Gen

• 𝑠 ← 𝐺𝑒𝑛 1𝑠

• 𝑘 ∈𝑅 0,1 𝑠

• Auth(m)• 𝑤1 ← (𝑘 ⊕ 𝑣2, 𝑚)

• 𝑤2 ← 𝐻𝑠 𝑤1

• 𝑤3 ← (𝑘 ⊕ 𝑣1, 𝑤1)

• 𝑡 ← 𝐻(𝑤3)

Page 11: Cryptographic hash functions - University Of Maryland · Applications of hash functions •Virus fingerprinting •Deduplication •Password hashing ... •Uses hash function to index

Random oracle heuristic

• Assume that a hash function acts as a random function

• Allows us to prove security for efficient schemes

• Unsound but• Only for contrived example

• Never broken for practical schemes

Page 12: Cryptographic hash functions - University Of Maryland · Applications of hash functions •Virus fingerprinting •Deduplication •Password hashing ... •Uses hash function to index

Applications of hash functions

• Virus fingerprinting

• Deduplication

• Password hashing

• File changes/integrity

Page 13: Cryptographic hash functions - University Of Maryland · Applications of hash functions •Virus fingerprinting •Deduplication •Password hashing ... •Uses hash function to index

Virus fingerprinting

• Hash the virus using the hash function

• To lookup a virus, simply look at the output of the function and see ifit maps to a known virus

• False positives imply collision

Page 14: Cryptographic hash functions - University Of Maryland · Applications of hash functions •Virus fingerprinting •Deduplication •Password hashing ... •Uses hash function to index

Deduplication

• Avoid storing the same thing in memory many times

• Uses hash function to index values so that we don’t need to copy the same thing many times.

Page 15: Cryptographic hash functions - University Of Maryland · Applications of hash functions •Virus fingerprinting •Deduplication •Password hashing ... •Uses hash function to index

File changes / integrity

• To keep track of changes, we keep a list of hash for every function

• The output of the hash function can be much shorter than the size of the files

Page 16: Cryptographic hash functions - University Of Maryland · Applications of hash functions •Virus fingerprinting •Deduplication •Password hashing ... •Uses hash function to index

Proper way to hash passwords

• Naïve way to hash passwords• ℎ ← 𝐻(𝑝𝑤𝑑)

• Same password hashed to same value

• Correct way to hash a password• 𝑟 ∈𝑅 0,1 𝑛

• ℎ ← 𝐻 𝑟, 𝑝𝑤𝑑

• (𝑟, ℎ)

Page 17: Cryptographic hash functions - University Of Maryland · Applications of hash functions •Virus fingerprinting •Deduplication •Password hashing ... •Uses hash function to index

Bad way to hash passwords (xkcd)

Page 18: Cryptographic hash functions - University Of Maryland · Applications of hash functions •Virus fingerprinting •Deduplication •Password hashing ... •Uses hash function to index

Hash tree

• Goal• Client has constant overhead

• Server holds client’s database 𝑥1, … , 𝑥𝑛• Client requests 𝑥𝑖• Server sends 𝑥′𝑖• How can client verify that 𝑥′𝑖 = 𝑥𝑖 with only logarithmic overhead

Page 19: Cryptographic hash functions - University Of Maryland · Applications of hash functions •Virus fingerprinting •Deduplication •Password hashing ... •Uses hash function to index

Hash tree

• 𝐿𝑒𝑎𝑓𝑖 = 𝐻𝑎𝑠ℎ(𝐹𝑖𝑙𝑒𝑖)

• Non-leaf node• Hash(Hash(node.left) || Hash(node.right))

• Client only need to store the root

• To prove that a given file is correct, the server only needs to send the client hashes of nodes that follow the path from the given leaf to the root node.