NTC Unit 5
NTC Unit 5
UNIT 5
Cryptographic Hash Functions:
Applications of Cryptographic Hash Functions, Two Simple Hash Functions, Message
Authentication Requirements, Message Authentication Functions, MACs based on Hash
functions: HMAC
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.
More commonly, message authentication is achieved using a message authentication code (MAC), also
known as a keyed hash function.
Typically, MACs are used between two parties that share a secret key to authenticate information
exchanged between those parties.
A MAC function takes as input a secret key and a data block and produces a hash value, referred to as the
MAC, which is associated with the protected message.
If the integrity of the message needs to be checked, the MAC function can be applied to the message and
the result compared with the associated MAC value.
An attacker who alters the message will be unable to alter the associated MAC value without knowledge
of the secret key.
Information Technology II Year II Semester
Unit-5:EM-IV [19BS1403] Number Theory & Cryptography
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.
In the case of the digital signature, the hash value of a message is encrypted with a user’s private key.
Anyone who knows the user’s public key can verify the integrity of the message that is associated with
the digital signature.
In this case, an attacker who wishes to alter the message would need to know the user’s private key.
Following figures illustrates, in a simplified fashion, how a hash code is used to provide a digital signature.
a. The hash code is encrypted, using public-key encryption with the sender’s private key. As with
Figure b, this provides authentication. It also provides a digital signature, because only the sender
could have produced the encrypted hash code. In fact, this is the essence of the digital signature
technique.
b. If confidentiality as well as a digital signature is desired, then the message plus the private-key-
encrypted hash code can be encrypted using a symmetric secret key. This is a common technique.
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).
Measures to deal with the first two attacks are in the realm of message confidentiality and are dealt with
in Encryption techniques.
Measures to deal with items (3) through (6) in the foregoing list are generally regarded as message
authentication.
Mechanisms for dealing specifically with item (7) come under the heading of digital signatures.
Generally, a digital signature technique will also counter some or all of the attacks listed under items (3)
through (6). Dealing with item (8) may require a combination of the use of digital signatures and a
protocol designed to counter this attack.
In summary, message authentication is a procedure to verify that received messages come from the alleged
source and have not been altered.
Message authentication may also verify sequencing and timeliness.
A digital signature is an authentication technique that also includes measures to counter repudiation by
the source.
Message Encryption:
Message encryption by itself can provide a measure of authentication. The analysis differs for
symmetric and public-key encryption schemes.
Symmetric Encryption:
Consider the straightforward use of symmetric encryption (Figure a).
A message M transmitted from source A to destination B is encrypted using a secret key K shared by
A and B. If no other party knows the key, then confidentiality is provided: No other party can recover
the plaintext of the message.
Public-Key Encryption:
The straightforward use of public-key encryption (Figure b) provides confidentiality but not
authentication.
The source (A) uses the public key PUb of the destination (B) to encrypt M. Because only B has the
corresponding private key PRb, only B can decrypt the message. This scheme provides no
authentication, because any opponent could also use B’s public key to encrypt a message and claim to
be A.
To provide authentication, A uses its private key to encrypt the message, and B uses A’s public key to
decrypt (Figure c). This provides authentication using the same type of reasoning as in the symmetric
encryption case: The message must have come from A because A is the only party that possesses PR a
and therefore the only party with the information necessary to construct ciphertext that can be decrypted
with PUa.
There must be some internal structure to the plaintext so that the receiver can distinguish between
well-formed plaintext and random bits.
Assuming there is such structure, then the scheme of Figure c does provide authentication. It also
provides what is known as digital signature.
Only A could have constructed the ciphertext because only A possesses PRa. Not even B, the recipient,
could have constructed the ciphertext. Therefore, if B is in possession of the ciphertext, B has the means
to prove that the message must have come from A.
In effect, A has “signed” the message by using its private key to encrypt.
Note that this scheme does not provide confidentiality. Anyone in possession of A’s public key can
decrypt the ciphertext.
The process depicted in Figure (a) provides authentication but not confidentiality, because the message
as a whole is transmitted in the clear.
Confidentiality can be provided by performing message encryption either after (Figure b) or before
(Figure c) the MAC algorithm.
In both these cases, two separate keys are needed, each of which is shared by the sender and the receiver.
In the first case, the MAC is calculated with the message as input and is then concatenated to the message.
The entire block is then encrypted. In the second case, the message is encrypted first.
Then the MAC is calculated using the resulting ciphertext and is concatenated to the ciphertext to form
the transmitted block.
Typically, it is preferable to tie the authentication directly to the plaintext, so the method of Figure b is
used.
MACs based on hash functions: HMAC
HMAC Design Objectives
RFC 2104 lists the following design objectives for HMAC.
• To use, without modifications, available hash functions. In particular, to use hash functions that perform
well in software and for which code is freely and widely available.
• To allow for easy replaceability of the embedded hash function in case faster or more secure hash
functions are found or required.
• To preserve the original performance of the hash function without incurring a significant degradation.
• To use and handle keys in a simple way.
• To have a well understood cryptographic analysis of the strength of the authentication mechanism based
on reasonable assumptions about the embedded hash function.
HMAC Algorithm
H = embedded hash function (e.g., MD5, SHA-1, RIPEMD-160)
IV = initial value input to hash function
Information Technology II Year II Semester
Unit-5:EM-IV [19BS1403] Number Theory & Cryptography
M = message input to HMAC (including the padding specified in the embedded
hash function)
Yi _ i th block of M, 0 ≤i ≤(L – 1)
L _ number of blocks in M
b _ number of bits in a block
n _ length of hash code produced by embedded hash function
K _ secret key; recommended length is ≥n; if key length is greater than b, the key is input to the hash function
to produce an n-bit key
K+ _ K padded with zeros on the left so that the result is b bits in length
ipad _ 00110110 (36 in hexadecimal) repeated b/8 times
opad _ 01011100 (5C in hexadecimal) repeated b/8 times