Module3 Hash Function
Module3 Hash Function
Approaches to Message
Authentication
• A message is authentic when
• It is not altered(Genuine)
• It has come from the alleged source
• It has not be artificially delayed and replayed
3
Authentication using conventional
Encryption
• Symmetric encryption- genuine sender would be able to encrypt a
message
• If the message also includes a timestamp, the receiver is assured that the
message has not been delayed beyond that normally expected for
network transit.
• Symmetric encryption alone is not a suitable tool for data authentication.
• To give one simple example, in the ECB mode of encryption, if an
attacker reorders the blocks of ciphertext, then each block will still
decrypt successfully.
Message Authentication without
Message Encryption
• An authentication tag is generated and appended to each message for transmission.
• The message itself is not encrypted and can be read at the destination independent
of the authentication function at the destination.
• This technique assumes that two communicating parties, say A and B, share a common secret key KAB.
• The recipient performs the same calculation on the received message, using the same secret key, to generate a
new message authentication code.
• The receiver is assured that the message has not been altered. If an attacker alters the message but does not
alter the code, then the receiver’s calculation of the code will differ from the received code.
• If the message includes a sequence number (such as is used with HDLC and TCP), then the receiver can be
assured of the proper sequence.
MAC
MAC
MAC
• The domain of the function consists of messages of some arbitrary length, whereas
the range consists of all possible MACs and all possible keys
• For example, suppose that we are using 100-bit messages and a 10-bit MAC.
• Then, there are a total of 2100 different messages but only 210 different MACs.
• So, on average, each MAC value is generated by a total of 2 100 /2 10 = 290 different
messages.
5
• If a 5-bit key is used, then there are 2 = 32 different mappings from the set of
messages to the set of MAC values
Limitation of MAC
• Establishment of Shared Secret.
• It can provide message authentication among pre-decided legitimate users
who have shared key.
• This requires establishment of shared secret prior to use of MAC.
• Inability to Provide Non-Repudiation
• Non-repudiation is the assurance that a message originator cannot deny
any previously sent messages and commitments or actions.
• MAC technique does not provide a non-repudiation service. If the sender
and receiver get involved in a dispute over message origination, MACs
cannot provide a proof that a message was indeed sent by the sender.
• Both these limitations can be overcome by using the public key based
digital signatures
Hash Function
• A hash function is a mathematical function that converts a
numerical input value into another compressed numerical value.
The input to the hash function is of arbitrary length but output is
always of fixed length.
• Values returned by a hash function are called message digest or
simply hash values.
One Way Hash Functions
• Like message authentication code, a hash function
accepts a variable-size message M as input and
produces a fixed-size message digest H(M) as
output.
• Unlike the MAC, a hash function does not take a
secret key as input.
• To authenticate a message, the message digest is
sent with the message in such a way that the
message digest is authentic.
One way Hash Functions
Hash function
• MD5
Popular Hash Functions
• was most popular and widely used hash function for quite some years.
• The MD family comprises of hash functions MD2, MD4, MD5 and MD6..It is a 128-bit
hash function.
Given one message, can’t find another message that has the same message digest. An attack that
finds a second message with the same message digest is a second pre-image attack.
It would be easy to forge new digital signatures from old signatures if the hash function used
weren’t second preimage resistant
Collision Resistant
Can’t find any two different messages with the same message digest
Collision resistance implies second preimage resistance
Collisions, if we could find them, would give signatories a way to repudiate their signatures
Hash function property-Summary
Deterministic
Fast computation
Pre Image Resistance
Avalanche Effect
Collision resistance
Simple hash function
Simple hash function
• All hash functions operate using the following
general principles.
• The input (message, file, etc.) is viewed as a
sequence of n-bit blocks.
• The input is processed one block at a time in an
iterative fashion to produce an n-bit hash function.
• The two simple techniques are given.
Simple Hash Function
One of the simplest hash function is the bit by bit
X-OR operation.
Ci = bi1 bi2 ….. bim
Ci = ith bit of the hash code, 1 ≤ i ≤ n
M = number of n-bit blocks of the input
b ij = ith bit in jth block
Two way Hash function
• A simple way to improve is to perform a one bit circular shift
, or rotation, on the hash value after each block is processed.
• The procedure can be summarized as follows:
1. Initially set the n-bit hash value to zero
2. Process each successive n-bit block of data as follows
• Rotate the current hash value to the left by each bit.
• X-OR the block into the Hash value
Simple hash function
• bit-by-bit exclusive-OR (XOR) of every block
• Ci = bi1 xor bi2 xor . . . xor bim
• a longitudinal redundancy check
• reasonably effective as data integrity check
• one-bit circular shift on hash value
• for each successive n-bit block
• rotate current hash value to left by1bit and XOR block
• good for data integrity but useless for security
• The second procedure provides a good measure of data integrity, it is virtually useless for data
security when an encrypted hash code is used with a plaintext message.
• Given a message, it is an easy matter to produce a new message that yields that hash code:
Simply prepare the desired alternate message and then append an n-bit block that forces the
combined new message plus block to yield the desired hash code.
MD5 Overview
2. Append
length
(64bits)
1. Append padding
bits
(to 448 mod 512)
16 steps
Single step
Secure Hash functions
Requirements of secure hash functions are
1. H can be applied to a block of data of any size.
2. H produces a fixed-length output.
3. H(x) is relatively easy to compute for any given x, making both hardware and software
implementations practical.
4. For any given code h, it is computationally infeasible to find x such that H(x) = h. A hash
function with this property is referred to as one-way or preimage resistant.3
5. For any given block x, it is computationally infeasible to find y ≠ x with H(y)= H(x). A
hash function with this property is referred to as second preimage resistant. This is
sometimes referred to as weak collision resistant.
6. It is computationally infeasible to find any pair (x, y) such that H(x) H(y).A hash function
with this property is referred to as collision resistant. This is sometimes referred to as
strong collision resistant. It is resistant against birthday attacks
SHA-512 Overview
Secure Hash Algorithms (SHAs)
• (SHA) was developed by the National Institute of Standards and Technology
(NIST) and published as a federal information processing standard (FIPS
180) in 1993.
• A revised version was issued in 1995 and is generally referred to as SHA-1.
• SHA is based on the hash function MD4 and its design closely models MD4
• Several Hash Algorithms (SHA) were designed by Ron Rivest.
• These are referred to as MD2, MD4 and MD5 where MD stands for message
digest.
• MD5 is the strengthened version of MD4 and uses messages of blocks of
512 bits and creates a 128 bits digest.
Secure Hash Algorithms (SHAs)
Message Digest Generation using SHA-512
Message Digest Generation using
SHA-512
• The algorithm takes as input a message with a
maximum length of less than 2 128 bits and produces
as output a 512-bit message digest.
Message Digest Generation using
SHA-512
• Step 1. Append Padding bits: Padding is always added even if the
message is desired length. Thus, the number of padding bits is in the range
of 1 to 1024. The padding consists of a single 1-bit followed by the
necessary number of 0-bits.
• Step 2. Append length: A block of 128 bits is appended to the message.
This block is treated as an unsigned 128-bit integer (most significant byte
first) and contains the length of the original message (before the padding).
• Step 3. Initialize hash buffer: A 512-bit buffer is used to hold
intermediate and final results of the hash function. The buffer can be
represented as eight 64-bit registers (a, b, c, d, e, f, g, h). These registers
are initialized to the following 64-bit integers (hexadecimal values).
Message Digest Generation using
SHA-512
Step 4: Process Message in 1024 bit (128-word) blocks: The heart of the algorithm is a
module that consists of 80 rounds.
Step 5: After all N 1024-bit blocks have been processed, the output from the Nth stage is
the 512 bit message digest;
We can summarize the behavior of SHA-512 as follows:
H0 = IV
Hi = SUM 64 (Hi-1, abcdefghi)
IV = Initial value,
MD=Message digest =
HN , where N= no. of blocks in the messg.,
SUM 64 = Addition Module 264 performed separately on each word of the pair of I/Ps
Message Digest Generation using
SHA-512
• a = 6A09E667F3BCC908
• b = BB67AE8584CAA73B
• c = 3C6EF372FE94F82B
• d = A54FF53A5F1D36F1
• e = 510E527FADE682D1
• f = 9B05688C2B3E6C1F
• g = 1F83D9ABFB41BD6B
• h = 5BE0CDI9137E2179
SHA-512 Processing for a block
SHA processing for a round
SHA processing for a round
SHA processing for a round
• where
• T = step number; 0 <t <79
• Ch(e, f, g)= (e AND f) XOR (NOT e AND g) the conditional function: If e then f else g
• Maj(a, b, c) = (a AND b) XOR(a AND c)XOR (b AND c) the function is true only of the majority (two or
three) of the arguments are true.
• What makes HMAC more secure than Message Authentication Code is that the key and the message are hashed in
separate steps.
• HMAC(key, msg) = H(mod1(key) || H(mod2(key) || msg))
• This ensures the process is not susceptible to extension attacks that add to the message and can cause elements of the
key to be leaked as successive MACs are created.
• Once the server receives the request and regenerates its own unique HMAC, it compares the two HMACs. If they're
equal, the client is trusted and the request is executed. This process is often called a secret handshake