Cryptographic Hash Functions Rocky K. C. Chang, February 2013 1.

Slides:



Advertisements
Similar presentations
Lecture 5: Cryptographic Hashes
Advertisements

Hash Function. What are hash functions? Just a method of compressing strings – E.g., H : {0,1}*  {0,1} 160 – Input is called “message”, output is “digest”
Digital Signatures and Hash Functions. Digital Signatures.
Session 5 Hash functions and digital signatures. Contents Hash functions – Definition – Requirements – Construction – Security – Applications 2/44.
1 Chapter 5 Hashes and Message Digests Instructor: 孫宏民 Room: EECS 6402, Tel: , Fax :
Chapter 4  Hash Functions 1 Overview  Cryptographic hash functions are functions that: o Map an arbitrary-length (but finite) input to a fixed-size output.
Information Security and Management 11
Csci5233 Computer Security & Integrity 1 Cryptography: Basics (2)
CS470, A.SelcukHash Functions1 Cryptographic Hash Functions CS 470 Introduction to Applied Cryptography Instructor: Ali Aydin Selcuk.
Hash Functions Nathanael Paul Oct. 9, Hash Functions: Introduction Cryptographic hash functions –Input – any length –Output – fixed length –H(x)
Cryptography and Network Security Chapter 11 Fourth Edition by William Stallings Lecture slides by Lawrie Brown/Mod. & S. Kondakci.
CS526Topic 5: Hash Functions and Message Authentication 1 Computer Security CS 526 Topic 5 Cryptography: Cryptographic Hash Functions And Message Authentication.
Hash Functions 1 Hash Functions Hash Functions 2 Cryptographic Hash Function  Crypto hash function h(x) must provide o Compression  output length is.
Cryptography1 CPSC 3730 Cryptography Chapter 11, 12 Message Authentication and Hash Functions.
1 Message Authentication and Hash Functions Authentication Requirements Authentication Functions Message Authentication Codes Hash Functions Security of.
CRYPTOGRAPHIC DATA INTEGRITY ALGORITHMS
Chapter 8.  Cryptography is the science of keeping information secure in terms of confidentiality and integrity.  Cryptography is also referred to as.
Lecture 2: Message Authentication Anish Arora CSE5473 Introduction to Network Security.
Cryptography and Network Security Chapter 11 Fifth Edition by William Stallings Lecture slides by Lawrie Brown.
The RSA Algorithm Rocky K. C. Chang, March
Lecture 15 Lecture’s outline Public algorithms (usually) that are each other’s inverse.
Acknowledgements: William Stallings.William Stallings All rights Reserved Session 4 Public Key Cryptography (Part 2) Network Security Essentials Application.
Digital Signatures Good properties of hand-written signatures: 1. Signature is authentic. 2. Signature is unforgeable. 3. Signature is not reusable (it.
Message Authentication  message authentication is concerned with: protecting the integrity of a message protecting the integrity of a message validating.
Information Security Principles Assistant Professor Dr. Sana’a Wafa Al-Sayegh 1 st Semester ITGD 2202 University of Palestine.
1 Chapter 11: Message Authentication and Hash Functions Fourth Edition by William Stallings Lecture slides by Lawrie Brown (modified by Prof. M. Singhal,
Hash Functions A hash function H accepts a variable-length block of data M as input and produces a fixed-size hash value h = H(M) Principal object is.
EE515/IS523 Think Like an Adversary Lecture 4 Crypto in a Nutshell Yongdae Kim.
Message Authentication Code July Message Authentication Problem  Message Authentication is concerned with:  protecting the integrity of a message.
Lecture 4.1: Hash Functions, and Message Authentication Codes CS 436/636/736 Spring 2015 Nitesh Saxena.
1 Hashes and Message Digests. 2 Hash Also known as –Message digest –One-way function Function: input message -> output One-way: d=h(m), but not h’(d)
CSCI 172/283 Fall 2010 Hash Functions, HMACs, and Digital Signatures.
11.1 Copyright © The McGraw-Hill Companies, Inc. Permission required for reproduction or display. Chapter 11 Message Integrity and Message Authentication.
1 Hash Functions. 2 A hash function h takes as input a message of arbitrary length and produces as output a message digest of fixed length
Chapter 4 Message Authentication MSc. NGUYEN CAO DAT Dr. TRAN VAN HOAI 1.
11.1 Copyright © The McGraw-Hill Companies, Inc. Permission required for reproduction or display. Chapter 11 Message Integrity and Message Authentication.
Chapter 2 Advanced Cryptography (Part C)
Cryptographic Hash Functions and Protocol Analysis
CIT 380: Securing Computer SystemsSlide #1 CIT 380: Securing Computer Systems Modern Cryptography.
Chapter 11 Message Authentication and Hash Functions.
Cryptography and Network Security Chapter 12 Fifth Edition by William Stallings Lecture slides by Lawrie Brown.
Cryptographic Hash Functions Prepared by Dr. Lamiaa Elshenawy
Cryptography and Network Security (CS435) Part Nine (Message Authentication)
Giuseppe Bianchi Message Authentication: hash functions and hash-based constructions.
Hash Functions Ramki Thurimella. 2 What is a hash function? Also known as message digest or fingerprint Compression: A function that maps arbitrarily.
Lecture 4.1: Hash Functions, and Message Authentication Codes CS 436/636/736 Spring 2014 Nitesh Saxena.
Cryptographic Hash Functions
CS426Fall 2010/Lecture 51 Computer Security CS 426 Lecture 5 Cryptography: Cryptographic Hash Function.
CSCE 715: Network Systems Security Chin-Tser Huang University of South Carolina.
Hashes Lesson Introduction ●The birthday paradox and length of hash ●Secure hash function ●HMAC.
1 Authenticated Key Exchange Rocky K. C. Chang 20 March 2007.
11.1 Copyright © The McGraw-Hill Companies, Inc. Permission required for reproduction or display. Chapter 11 Message Integrity and Message Authentication.
IT 221: Introduction to Information Security Principles Lecture 5: Message Authentications, Hash Functions and Hash/Mac Algorithms For Educational Purposes.
1 4.1 Hash Functions and Data Integrity A cryptographic hash function can provide assurance of data integrity. ex: Bob can verify if y = h K (x) h is a.
1 Diffie-Hellman (Key Exchange) Protocol Rocky K. C. Chang 9 February 2007.
1 The RSA Algorithm Rocky K. C. Chang February 23, 2007.
CS480 Cryptography and Information Security Huiping Guo Department of Computer Science California State University, Los Angeles 13.Message Authentication.
Cryptography Hyunsung Kim, PhD University of Malawi, Chancellor College Kyungil University February, 2016.
Data Integrity / Data Authentication. Definition Authentication (Signature) algorithm - A Verification algorithm - V Authentication key – k Verification.
CS555Spring 2012/Topic 141 Cryptography CS 555 Topic 14: CBC-MAC & Hash Functions.
Cryptographic Hash Function. A hash function H accepts a variable-length block of data as input and produces a fixed-size hash value h = H(M). The principal.
@Yuan Xue 285: Network Security CS 285 Network Security Hash Algorithm Yuan Xue Fall 2012.
Cryptographic Hash Functions
Cryptographic Hash Function
Cryptographic Hash Functions
Cryptographic Hash Functions Part I
Outline Using cryptography in networks IPSec SSL and TLS.
Lecture 4.1: Hash Functions, and Message Authentication Codes
Presentation transcript:

Cryptographic Hash Functions Rocky K. C. Chang, February

This set of slides addresses 2

Outline 3  Cryptographic hash functions  Unkeyed and keyed hash functions  Security of cryptographic hash functions  Iterated hash functions  Two weaknesses  Message authentication codes  What does an MAC do?  MAC security  HMAC  Using MAC properly

Cryptographic hash functions 4

Hash functions 5  A hash function (or message digest function) takes an arbitrarily long string of bits and produces a fixed-sized result.  The hash result is also known as digest or fingerprint.  Cryptographic hash function vs. hashing used in data structures and algorithms.  Cryptographic hash function vs. error detection codes, such as checksum and CRC

For examples, 6  For a message m, compute x = h(m).  Assume that x is stored in a safe place, but m is not.  Whenever retrieving m, compute h(m).  If h(m)= x, one should be confident that m has not been altered.  Alice and Bob share a secret key K, and use h K () to protect the integrity of their messages.  Assume that K is only known to Alice and Bob.  Alice (or Bob) computes x = h K (m) and sends (m, x) to Bob (or Alice).  At Bob’s (or Alice) side, he computes h K (m).  If h K (m) = x, (s)he should be confident that both m and x have not been altered.

Many uses of cryptographic hash functions 7  Message authentication (or message integrity) and digital signature  Map a variable-sized value to a fixed-size value.  Serve as a cryptographic pseudo-random generators to generate several keys from a single shared secret.  Their one-way property isolates different parts of a system.

A (keyed) hash family consists of 8  M: a set of possible messages  X: a finite set of possible message digests  K: the key space, a finite set of possible keys  For each K  K, there is a hash function h K  H. Each h K : M  X.  Moreover,  Usually assume that |M| ≥ 2|X|.  A pair (m, x) is valid under the key K if h K (m) = x.  |K| = 1 for unkeyed hash functions.

Security of a cryptographic hash function 9  The basic requirement for a cryptographic hash function is that  The only efficient way to produce a valid pair (m, x) is to first choose m, and then compute x = h(m).  As a counter example, consider a message: (m 1, m 2 ) with h(m 1, m 2 ) = am 1 + bm 2 mod n, where m 1, m 2, a, b  Z n, n>1.  Given h(m 1, m 2 ) and h(m’ 1, m’ 2 ), one can determine the value of h() for other messages.  For a message (rm 1 +sm’ 1, rm 2 +sm’ 2 ), h(rm 1 +sm’ 1, rm 2 +sm’ 2 ) = r h(m 1, m 2 ) + s h(m’ 1, m’ 2 ).  Security of a cryptographic hash function can be evaluated based on the difficulty of solving three problems.

Problem 1: The preimage problem 10  The preimage problem:  Given a hash function h: M  X and an element x  X,  Find m  M such that h(m) = x.  If the preimage problem can be solved, then (m, x) is a valid pair.  A hash function for which the preimage problem cannot be efficiently solved is said to be one-way or preimage resistant.

Problem 2: The second preimage problem 11  The second preimage problem:  Given a hash function h: M  X and an element m  M,  Find an m’  M such that m’  m and h(m’) = h(m).  If the 2 nd preimage problem can be solved, then (m’, h(m)) is a valid pair.  A hash function for which the 2 nd preimage problem cannot be efficiently solved is said to be second preimage resistant.

Problem 3: The collision problem 12  The collision problem:  Given a hash function h: M  X,  Find m, m’  M such that m’  m and h(m’) = h(m).  If (m, x) is a valid pair, and m, m’ is a solution to the collision problem, then (m’, x) is also a valid pair.  A hash function for which the collision problem cannot be efficiently solved is said to be collision resistant.  Which problem is the easiest to solve?

Solving the preimage problem 13  Consider the following algorithm to solve the preimage problem. 1. Choose a subset M 0  M and |M 0 | = q. 2. For each m  M 0, if h(m) = x, return m. 3. Return “unsuccessful.”  Pr[success] = 1 – Pr[all q attempts are unsuccessful].  Assuming independent events, Pr[all q attempts are unsuccessful] = Pr[an attempt is unsuccessful] q.  Let |X|=B and Pr[an attempt is unsuccessful] = 1–1/B.  Therefore, Pr[success] = 1–(1–1/B) q ≈ q/B if q is small compared to B.

Solving the 2 nd preimage problem 14  Consider the following algorithm to solve the 2 nd preimage problem. 1. Compute h(m). 2. Choose a subset M 0  M\{m} and |M 0 | = q–1. 3. For each m’  M 0, if h(m’) = h(m), return m’. 4. Return “unsuccessful.”  Pr[success] = 1–(1–1/B) q–1.

Solving the collision problem 15  Consider the following algorithm to solve the collision problem. 1. Choose a subset M 0  M and |M 0 | = q. 2. For each m  M, evaluate h(m). 3. If h(m) = h(m’) for some m’  m, return m’, m. 4. Else, return “unsuccessful.”  To conduct step 3, one can sort the values of h().

Solving the collision problem 16  Problem: what is the success probability of the algorithm to solve the collision problem given q attempts?  Assume uniform probability and independence.  Pr[unsuccessful] = Pr[all the q values of h() are different] = (B/B)((B–1)/B)((B–2)/B) … ((B–q+1)/B).  Pr[successful] = 1–Pr[unsuccessful] = 1–(B/B)((B– 1)/B)((B–2)/B) … ((B–q+1)/B).  Pr[successful]  1 – e -q(q-1)/2B for a sufficiently large B.

The birthday attack 17  Q: How many attempts are needed so that Pr[successful] ≥ p? (birthday problem if B = 365)  After performing more approximation for Pr[successful]  1 – e -q(q-1)/2B, we have  q  (2B ln(1/(1- Pr[successful]))) 1/2.  For p = 0.5, q  1.17  B.  Hashing just over  B random elements of M yields a collision probability of 0.5.  Different values of p will give different constant factors, but q is still proportional to  B.  For a n-bit hash function, a birthday attack (or square root attack) needs 2 n/2 random hashes.  Answer for the birthday problem?  Which problem is the easiest to solve?

Re-examining the 3 problems 18  If we can solve the 2 nd preimage problem, we can also solve the collision problem.  Randomly choose an m  M.  Use the solution to the 2 nd preimage problem to find m’.  Return (m, m’).  If we can solve the preimage problem, we can also solve the collision problem.  Randomly choose an m  M.  Compute h(m).  Use the solution to the preimage problem to find m’.  Return (m, m’).  Collision resistant => 2 nd preimage resistant and collision resistant => preimage resistant.

Iterated hash functions 19  Almost all hash functions put into practice are iterated hash functions.  h: M  X, where X = {0, 1} p (i.e., n-bit hash function).  An iterated hash function h() usually consists of three main steps:  (1) Preprocessing  (2) Processing  (3) Output transformation  Require a compression function for step (2):  Compress : {0,1} n+t  {0,1} n, t ≥ 1.

Iterated hash functions 20

(1) Preprocessing 21  Given an input string m, where |m| ≥ n + t + 1, construct a string y, such that |y|  0 (mod t).  Let y = y 1 || y 2 || … || y r, where |y i | = t, i = 1, 2, …, r.  t is the block size and r is the number of blocks.  This step must ensure that the mapping m  y is one-to- one.  Else, it is possible to find m ≠ m’ so that y = y’.  Then h(m) = h(m’), i.e., h() would not be collision-resistant.  Moreover, |y| = rt ≥ |m| because of the one-to-one requirement on the mapping m  y.  A commonly used preprocessing step is to add padding: y = m || pad(m).

(2) Processing and (3) output transformation 22  (2) Processing  Let IV be a public initial value of length n. Compute  z o  IV  z 1  compress (z o || y 1 )  z 2  compress (z 1 || y 2 ) ……  z r  compress (z r-1 || y r ).  (3) Optional output transformation  Let g: {0,1} n  {0,1} p be a public function. Without this transformation, we have n = p.

Merkle–Damgård construction 23  The construction is based on the iterated hash function construction with  The last block is padded with 0 and a binary string that encodes the length of the original message ( Merkle–Damgård strengthening ).  The compress function is collision-resistant.  Ralph Merkle and Ivan Damgård independently proved that the hash function is collision resistant if the compress function is collision-resistant.  This construction was used in the design of many popular hash algorithms such as MD5 and SHA1.

Two main hash functions 24  Message Digest (MD5) and Secure Hashing Algorithm (SHA-1)  MD5  t = 512 bits and p = 128 bits (4 x 32-bit)  The compress function is made from an “encryption function” by the Davies-Meyer scheme.  The hash output is a concatenation of the 4 output words.  MD5 makes four passes over each block of data.  SHA-1  t = 512 bits and p = 160 bits (5 x 32-bit)  The compress function is also made from an “encryption function” by the Davies-Meyer scheme.  The hash output is a concatenation of the 5 output words.  SHA-1 makes five passes over each block of data.

Security of MD5 and SHA-1 25  If the compress function is collision resistant, then the iterated hash function is also collision resistant.  Security of MD5  The Compress function in MD5 is known to have collisions.  The 128-bit hash size is also insufficient.  Security of SHA-1  SHA-1 was broken by a research team from Shandong University in  Collisions in the full SHA-1 in 2 69 hash operations, much less than the brute-force attack of 2 80 operations.  SHA-2 (SHA-224, SHA-256, SHA-384, SHA-512)  SHA-3, originally known as Keccak which was the winner of the NIST hash function competition in 2012.

Weakness 1: length extensions 26  Consider a message m is split into blocks m 1, m 2, …, m k without padding and hashed to a value h(m).  Choose a message m ’ that splits into the block m 1, m 2, …, m k, m k+1 (the first k blocks are identical to m ’ s).  Therefore, h(m) is the intermediate hash value after k blocks in the computation of h(m ’ ).  Thus, h(m ’ ) = Compress (h(m), m k+1 ).  Even with padding, one can show that a similar length extension attack can be launched.

What is the problem? 27  The main problem is that there is no special processing at the end of the hash function computation.  Consider that Alice sends a message to Bob and wants to authenticate it by sending h(K||m), where K is a secret shared by Alice and Bob.  Now an attacker can append text to m, and update the hash value without knowing K.

Weakness 2: partial message collision  Suppose an attacker can get a system to authenticate a single message only, e.g.,  How can the attacker use the hash value to send another “ authenticated ” message to Bob? 28

Partial message collision 29  First, the attacker has to find 2 strings m and m ’ that lead to a collision when hashed by h(), i.e., the birthday attack.  Then he gets Bob to authenticate m, i.e., receiving h(m||K) from Bob.  Since h() is computed iteratively,  Once there is a collision (h(m) = h(m ’ )) and  the rest of the hash inputs are the same (K),  the hash value stays the same too (h(m||K) = h(m ’ ||K)).

Message authentication codes 30

Message authentication codes 31  An MAC is a construction that prevents tampering (modify, replay) with messages.  Encryption does not prevent an attacker from manipulating messages.  Like encryption, MACs use a secret key K known only to both Alice and Bob.  Alice sends a message m to Bob with a MAC value MAC(K,m).  Bob checks that the MAC value of the message is equal to MAC(K,m).

Security of MAC 32  Similar to hash functions, an ideal MAC(K,m) should be computationally indistinguishable from a random mapping.  An attack on MAC is successful if  Given (m 1,MAC(K,m 1 )), (m 2,MAC(K,m 2 )), …, (m k,MAC(K,m k )),  An attacker is able to find a message m (not m 1, m 2, …,m k ) together with its valid MAC(K,m).  The success of the attack does not necessarily require a full knowledge of K.

Generating the MAC 33  There are 2 main approaches to generating MACs.  (CBC-MAC) Use of CBC and the MAC is the last block of the ciphertext.  (HMAC) Use keyed hash functions.  The CBC-MAC is generally considered secure if the underlying cipher is secure.  A number of different collision attacks that limit its security level.  Avoid using the same key for encryption and authentication.

Keyed hash functions 34  Hash functions were not originally designed for message authentication.  Authentication of what?  A message is sent from a certain source.  A message has not been modified after being sent.  A message is not an old message.  The main problem is how to encode a shared secret into a hash function.

A few possibilities 35  The secret-prefix method: MAC(K,m) = h(K||m).  Subject to the length extension attack  The secret-suffix method: MAC(K,m) = h(m||K).  Subject to the partial message collision attack  The secret-prefix-suffix method: MAC(K,m) = h(K||m||K).  A 128-bit key can be recovered using 2 67 known text-MAC pairs.

HMAC 36  HMAC computes h(K  opad || h(K  ipad || m)).  opad and ipad are specified constants, and they should have a large Hamming distance from each other.  The message m is hashed only once and the output is hashed again with the key.  HMAC uses hash function as a black-box.  h() can be any of the iterative hash functions, such as MD5 and SHA-1.  The main idea is to “ key ” the initial states for a hash function.  HMAC was chosen as the mandatory-to-implement authentication transform for IPSec (RFC 2104).

Using MAC properly 37  What information should be authenticated?  Or, what part of a packet should be included in MAC(K,m)?  The Horton Principle: Authenticate what is being meant, not what is being said.  An MAC only authenticates a string of bytes (what is being said), but  Not necessary the interpretation of the message (what is meant).

For example, 38  The authenticated message may include  A “ message ID ” that prevents replay attack,  The source and destination of the message,  Protocol field, etc.  In another case, Alice may use MAC to authenticate m = a || b || c, where a, b, and c are some data fields.  Additional (authenticated) information may be sent to Bob on how to interpret these data fields, in terms of their lengths, for example.

Summary 39  Examined the problems connected to the security of a cryptographic hash function.  The birthday attack is a major attack on hash functions.  All the practical hash functions, such as MD5 and SHA-1, are based on iterated hash functions which can be subject to  Length extension attacks and  partial message collision attacks  Message authentication is based on MAC computed on a message and a shared secret.  The MAC ’ s security can be compromised for some keyed hash functions.  Authenticate what is being meant, not what is being said.

Acknowledgments 40  The notes are prepared mostly based on  D. Stinson, Cryptography: Theory and Practice, Chapman & Hall/CRC, Second Edition,  N. Ferguson and B. Schneier, Practical Cryptography, Wiley, 2003.