نسخة ch2-Hash - Function (1)
نسخة ch2-Hash - Function (1)
نسخة ch2-Hash - Function (1)
Applied College
Computer Sciences Program
CYB - 104
Lecture 2 : Hash Functions and
Message authentication code
• Cryptographic Hash Functions
• Security considerations
• Attacks on Hash Functions
• Brute-Force Attacks
Outline •
•
Cryptanalysis Attacks
Type of Hash Functions :
• Secure Hash Functions (SHA)
• The SHA-2 hash function
• The SHA-3 hash function
• Hashing passwords
• Applications of Cryptographic Hash Functions
• A man-in-the-middle (MITM) attack
• Message Authentication
• Message Authentication code
Data Integrity and Source
Authentication
• Encryption does not protect data from modification by
another party.
• Need a way to ensure that data arrives at destination in
its original form as sent by the sender and it is coming
from an authenticated source.
3
• We are concerned with the types of
functions that may be used to produce an
authenticator. These may be grouped into
three classes.
o Hash function: A function that maps a
message of any length into a fixed-length hash
value, which serves as the authenticator
o Message encryption: The cipher text of the
entire message serves as its authenticator (We
learned in the first lecture )
o Message authentication code (MAC):
A function of the message and a secret key
that produces a fixed-length value that serves
as the authenticator
Hash Functions
o A hash function H accepts a variable-length block of data M as input and produces a
fixed-size hash value h = H(M).
o A “good” hash function has the property that the results of applying the function to a
large set of inputs will produce outputs that are evenly distributed and random. In general
terms, the principal object of a hash function is data integrity. A change to any bit or bits
in M results in a high
probability of a change to the hash value.
o The kind of hash function needed for security applications is called a cryptographic hash
function.
o The output of a hash function is often called a digest or a hash.
o The input of this function can be of any size. It can even be empty.
o The output is always of the same length and is deterministic; it always produces the
same result if given the same input.
o Hash functions are one-way, meaning that one shouldn’t be able to find the input from
just the output.
• The above figure depicts the general
operation of a cryptographic hash function.
• Typically, the input is padded out to an
integer multiple of some fixed length (e.g.,
1024 bits), and the padding includes the
value of the length of the original message
in bits.
• The length field is a security measure to
increase the difficulty for an attacker to
produce an alternative message with the
same hash value.
Security considerations
Three security properties of a hash function:
1- Pre-image resistance:
Security considerations
2- Second pre-image resistance
Security considerations
3- Collision resistance
Attacks on Hash Functions
1-Brute-Force attacks:
▪A brute-force attack does not depend on the specific algorithm but depends only on bit
length.
▪In the case of a hash function, a brute-force attack depends only on the bit length of the
hash value.
▪A cryptanalysis, in contrast, is an attack based on weaknesses in a particular
cryptographic algorithm.
• Collision-resistant attacks
▪For a collision-resistant attack, an adversary wishes to find two message data blocks, x and y, that
yield the same hash function: H(x) = H(y).
Attacks on Hash Functions
2- Birthday Attacks
might think a 64-bit hash is secure
but by Birthday Paradox is not
birthday attack works thus:
•given user prepared to sign a valid message x
•have a user sign the valid message, then substitute the forgery which will have a valid signature
conclusion is that need to use a larger MAC/hash
3- Cryptanalysis Attacks
As with encryption algorithms, cryptanalytic attacks on hash functions seek to exploit
some property of the algorithm to perform some attack other than an exhaustive search.
Type of Hash Functions
Secure Hash Functions (SHA)
• Secure Hash Algorithms, also known as SHA, are a family of
cryptographic functions designed to keep data secured.
It works by transforming the data using a hash function:
• an algorithm that consists of bitwise operations, modular
additions, and compression functions.
• The hash function then produces a fixed-size string that
looks nothing like the original.
• These algorithms are designed to be one-way functions,
meaning that once they’re transformed into their
respective hash values, it’s virtually impossible to
transform them back into the original data.
Type Secure Hash Functions (SHA):
SHA-1, SHA-2, and SHA-3, each of which was successively
designed with increasingly stronger encryption in response to
hacker attacks.
• It all starts with a special function called a compression function. A compression function takes
two inputs of some size and produces one output of the size of one of the inputs. Put simply, it takes
some data and returns less data.
The SHA-2 hash function
• While there are different ways of building a compression function, SHA-2 uses the
Davies–Meyer method, which relies on a block cipher (a cipher that can encrypt a fixed-size
block of data)
Padding means appending specific bytes to the input to make its length a multiple of some block size. Cutting the padded
input into chunks of the same block size allows us to fit these in the first argument of the compression function. For example,
SHA-256 has a block size of 512 bits.
2- it iteratively applies the compression function to the message blocks, using the previous output of the compression
function as the second argument to the compression function. The final output is the digest
The SHA-3 hash function
The most versatile cryptographic algorithm is the cryptographic hash function. It is used in a wide variety of security
applications and Internet protocols. The following are various applications where it is employed.
1. Message Authentication:
Message authentication is a mechanism or service used to verify the integrity of a message.
Message authentication assures that data received are exactly as sent (i.e., there is no modification, insertion, deletion, o r
replay).
When a hash function is used to provide message authentication, the hash function value is often referred to as a message
digest.
2. Digital Signatures
Another important application, which is similar to the message authentication application, is the digital signature.
The operation of the digital signature is similar to that of the MAC
We will learn about it later
3. Other Applications:
Hash functions are commonly used to create a one-way password file.
Hash functions can be used for intrusion detection and virus detection.
A cryptographic hash function can be used to construct a pseudorandom function (PRF) or a pseudorandom number
generator (PRNG).
Message Authentication
c. It is possible to use a hash function but no encryption for message authentication. The technique
assumes that the two communicating parties share a common secret value S. A computes the hash
value over the concatenation of M and S and appends the resulting hash value to M. Because B
possesses S, it can re-compute the hash value to verify. Because the secret value itself is not sent,
an opponent cannot modify an intercepted message and cannot generate a false message.
d. Confidentiality can be added to the approach of method (c) by encrypting the entire message
plus the hash code.
Message Authentication Code
• An alternative authentication technique involves the use of a secret key to generate a small fixed-
size block of data, known as a cryptographic checksum or MAC, that is appended to the message.
• This technique assumes that two communicating parties, say A and B, share a common secret key K.
• When A has a message to send to B, it calculates the MAC as a function of the message and the key:
MAC = C(K, M)
where
M = input message
C = MAC function
K = shared secret key
MAC = message authentication code
• The message plus MAC are transmitted to the intended recipient.
• The recipient performs the same calculation on the received message, using the same secret key, to
generate a new MAC.
Reference: