Unit - 4
Unit - 4
Cryptographic hash functions are fundamental building blocks in modern cryptography. They
are mathematical algorithms that take an input (or 'message') and produce a fixed-size string of
bytes, typically a hash value or digest. Cryptographic hash functions possess several important
properties that make them valuable for a wide range of security applications:
1. Deterministic: For the same input, a cryptographic hash function will always produce
that corresponds to a specific hash value. In other words, given a hash value ℎh, it should
be difficult to find a message m such that (h)=ℎH(m)=h, where H is the cryptographic
hash function.
4. Second Preimage Resistance: Given an input message 1m1, it should be
messages 1m1 and 2m2 that produce the same hash value, i.e., (1)=(2)H(m1)=H(m2). This
property ensures that it is difficult to find collisions in the hash function.
6. Fixed Output Size: Cryptographic hash functions produce hash values of a fixed size,
regardless of the size of the input message. This property allows for uniform
representation of hash values and facilitates their use in various cryptographic protocols.
7. Avalanche Effect: A small change in the input message should result in a significantly
different hash value. This property ensures that even minor modifications to the input
produce hash values that appear unrelated.
8. Resistance to Birthday Attacks: Cryptographic hash functions should resist birthday
attacks, where an attacker tries to find two messages with the same hash value by
generating a large number of random messages.
Examples of commonly used cryptographic hash functions include SHA-256 (part of the SHA-2
family), SHA-3, and BLAKE2. These hash functions are widely used in various cryptographic
applications, including digital signatures, message authentication codes (MACs), password
hashing, and blockchain technology. It's essential to use cryptographic hash functions that meet
the required security properties for specific applications to ensure the integrity and
confidentiality of sensitive data.
Hash functions have numerous applications across various domains due to their unique
properties, including determinism, fast computation, and resistance to preimage attacks. Here
are some common applications of hash functions:
• Hash functions are widely used to verify the integrity of data during transmission
or storage. By calculating the hash value of a file or message before and after
transmission or storage, one can compare the two hash values. If they match, it
indicates that the data has not been altered or corrupted.
2. Password Hashing:
• Hash functions are essential for securely storing passwords in databases. Instead
of storing plaintext passwords, systems store the hash values of passwords. When
a user logs in, the system hashes the provided password and compares it with the
stored hash value. This way, even if the database is compromised, attackers
cannot easily obtain users' passwords.
3. Digital Signatures:
• In digital signature schemes, hash functions are used to create a digest of the
message being signed. The sender hashes the message, encrypts the hash value
with their private key, and sends both the message and the signature to the
recipient. The recipient can verify the authenticity and integrity of the message by
decrypting the signature with the sender's public key and comparing it with the
hash value of the received message.
• Hash functions are used in conjunction with secret keys to generate message
authentication codes (MACs) for verifying the integrity and authenticity of
messages. The sender calculates a MAC by hashing the message along with a
secret key. The recipient verifies the MAC by hashing the received message with
the same secret key and comparing the resulting MAC with the received MAC.
5. Cryptographic Salting:
6. Blockchain Technology:
• Hash functions play a crucial role in blockchain technology, where they are used
to link blocks together in a chain. Each block contains a cryptographic hash of the
previous block, creating an immutable record of transactions. Changing the
contents of any block would require recalculating the hash values of all
subsequent blocks, making tampering with blockchain data extremely difficult.
7. Data Deduplication:
• Hash functions are used in data deduplication systems to identify duplicate data
blocks efficiently. By hashing the contents of each data block and comparing the
hash values, duplicate blocks can be identified and eliminated, reducing storage
space and improving efficiency.
These are just a few examples of the many applications of hash functions in various fields,
highlighting their versatility and importance in modern computing and cryptography.
Two simple hash functions commonly used in cryptography are the MD5 (Message Digest
Algorithm 5) and SHA-1 (Secure Hash Algorithm 1).
• MD5 is a widely used cryptographic hash function that produces a 128-bit (16-
byte) hash value, typically represented as a 32-digit hexadecimal number.
• It takes an input message of any length and produces a fixed-size hash value.
• MD5 is relatively fast and straightforward to implement, making it popular for
various applications such as digital signatures, message integrity verification, and
password hashing.
• However, MD5 is no longer considered secure for cryptographic purposes due to
vulnerabilities discovered in the algorithm, including collision attacks.
• Here's a Python implementation of MD5 using the hashlib library:
import hashlib
def md5_hash(input_string):
hash_object = hashlib.md5(input_string.encode())
return hash_object.hexdigest()
input_string = "hello"
hash_value = md5_hash(input_string)
• SHA-1 is another widely used cryptographic hash function that produces a 160-
bit (20-byte) hash value, typically represented as a 40-digit hexadecimal number.
• Like MD5, SHA-1 takes an input message of any length and produces a fixed-size
hash value.
• SHA-1 is designed to be more secure than MD5, but it also has weaknesses, and
it is gradually being deprecated in favor of stronger hash functions such as SHA-
256 and SHA-3.
• Despite its weaknesses, SHA-1 is still used in some legacy systems and
applications.
• Here's a Python implementation of SHA-1 using the hashlib library:
import hashlib
def sha1_hash(input_string):
hash_object = hashlib.sha1(input_string.encode())
return hash_object.hexdigest()
input_string = "hello"
hash_value = sha1_hash(input_string)
It's important to note that while MD5 and SHA-1 were once widely used, they are no longer
considered secure for cryptographic purposes due to vulnerabilities discovered in their
algorithms. It's recommended to use stronger hash functions such as SHA-256 or SHA-3 for
cryptographic applications where security is paramount.
Secure Hash Algorithm (SHA)
The Secure Hash Algorithm (SHA) is a family of cryptographic hash functions developed by the
National Security Agency (NSA) in the United States. SHA functions are widely used in various
cryptographic applications, including digital signatures, message authentication, and data
integrity verification. The SHA family includes several algorithms, each distinguished by the
number of bits in the resulting hash value.
The SHA algorithms are designed to provide collision resistance, preimage resistance, and
second preimage resistance, making them suitable for various cryptographic applications.
However, it's crucial to use the appropriate SHA variant based on the security requirements of
the specific application. Additionally, regular updates and adherence to cryptographic best
practices are essential to ensure the security of cryptographic systems.
Message Authentication Codes (MACs) are cryptographic constructs used to verify the
authenticity and integrity of a message or data transmission. They are often employed in
conjunction with cryptographic hash functions and secret keys to provide assurance that a
message has not been altered or tampered with during transmission. MACs are widely used in
various security protocols, including network communication, digital signatures, and data
authentication.
1. Generation:
• To generate a MAC, a cryptographic algorithm takes as input a message M and a
secret key K. The algorithm produces a fixed-size MAC value, typically much
smaller than the message itself.
• The MAC is generated using a pseudorandom function that combines the
message and the secret key in a way that ensures the MAC is unique to both the
message and the key.
2. Verification:
• To verify the authenticity and integrity of a message, the recipient computes the
MAC value for the received message using the same cryptographic algorithm and
the shared secret key.
• The recipient compares the computed MAC value with the MAC value received
along with the message. If the two MAC values match, it indicates that the
message has not been altered or tampered with during transmission.
3. Security Properties:
4. Key Management:
• The security of MACs relies on the secrecy and integrity of the shared secret key.
Therefore, proper key management practices are essential to prevent
unauthorized access to the key.
• Key distribution mechanisms, such as key exchange protocols or trusted third
parties, are used to securely distribute and manage secret keys among
communicating parties.
5. Common Algorithms:
MACs provide a crucial layer of security in ensuring the authenticity and integrity of messages
transmitted over insecure channels. They are widely used in various cryptographic protocols and
applications, including network security, digital signatures, and secure messaging.
Authentication requirement
1. Entity Verification:
2. Data Integrity:
• Authentication ensures that transmitted data remains unchanged during
transmission. By verifying the integrity of messages, authentication protects
against data tampering or unauthorized modifications by attackers.
3. Non-repudiation:
4. Secure Communication:
6. Access Control:
party has a public-private key pair. Digital signatures and digital certificates are
commonly used for asymmetric authentication.
• Message Authentication Codes (MACs): Cryptographic constructs generated using a
shared secret key and attached to messages to verify their authenticity and integrity.
• Digital Signatures: Cryptographic techniques that provide proof of the origin and
another party to prove its identity by responding with a correct authentication token or
credential.
Authentication function
There are several types of authentication functions used in cryptography, each serving different
purposes and employing different techniques:
2. Digital Signatures:
3. Hash-based Authentication:
• Hash functions are used to generate cryptographic hashes of data, which can be
used for authentication purposes.
• Hash-based authentication involves computing a hash value (digest) of the
message using a cryptographic hash function, such as SHA-256 or SHA-3.
• The hash value serves as a unique fingerprint of the message, and any alterations
to the message will result in a different hash value.
• Hash-based authentication is commonly used in digital certificates, public key
infrastructures (PKIs), and secure communication protocols.
4. Challenge-Response Authentication:
MAC
MAC stands for Message Authentication Code. It is a cryptographic construct used to provide
authentication and integrity protection for messages or data transmitted between parties. MACs
are essential for ensuring that messages have not been altered or tampered with during
transmission and that they originate from a trusted source.
1. Purpose: The primary purpose of a MAC is to verify the authenticity and integrity of a
message. It allows the recipient to confirm that the received message has not been
modified or forged by an attacker.
2. Generation: MACs are generated using a secret key and a cryptographic algorithm. The
sender computes the MAC over the message using a secret key known only to the
sender and recipient. The MAC is then appended to the message before transmission.
3. Verification: Upon receiving the message, the recipient recalculates the MAC using the
same algorithm and secret key. If the computed MAC matches the received MAC, the
recipient can be confident that the message has not been altered and that it originated
from the expected sender.
4. Symmetric-key Cryptography: MACs are typically based on symmetric-key
cryptographic algorithms, where the same secret key is used for both generating and
verifying the MAC. This ensures that only parties with knowledge of the secret key can
generate or verify the MAC.
5. Security Properties: A secure MAC algorithm should possess properties such as collision
6. Common Algorithms: There are various MAC algorithms used in practice, including
7. Applications: MACs are widely used in network protocols (e.g., TLS, IPsec), secure
messaging systems, digital signatures, and data authentication mechanisms. They play a
critical role in ensuring the security of communication and data exchange in various
applications.
Overall, MACs are essential cryptographic constructs that provide authentication and integrity
protection for messages exchanged between parties. By using MACs, cryptographic systems can
verify the authenticity and integrity of data, preventing unauthorized modification or tampering
by attackers.
HMAC
allows communicating parties to verify that a message has not been altered or tampered
with during transmission and that it originated from the expected sender.
256 or SHA-3, along with a secret key known only to the sender and recipient. The
HMAC algorithm applies a specific process to the message and secret key to generate a
fixed-size hash value, known as the MAC.
4. Keyed Hash Function: HMAC is a keyed hash function, meaning that it uses both the
message and a secret key to compute the hash value. This ensures that only parties
possessing the secret key can generate or verify the MAC, providing authentication and
message integrity protection.
message and secret key, including key derivation, padding, and hash computation. The
resulting MAC is appended to the message and transmitted along with it.
including network communication (e.g., TLS, IPsec), secure messaging systems, digital
signatures, and authentication mechanisms. It provides a critical layer of security for data
transmitted over insecure channels.
cryptographic hash function and a sufficiently long secret key to ensure security. The
length of the secret key and the underlying hash function's strength directly impact the
security of the HMAC construction.
Overall, HMAC is a widely used and trusted message authentication code that provides strong
security guarantees for verifying message integrity and authenticity. By employing HMAC,
cryptographic systems can ensure the secure transmission and reception of data, preventing
unauthorized tampering or modification by attackers.
CMAC
1. Purpose: CMAC is designed to authenticate the integrity and origin of a message, similar
to HMAC. It allows communicating parties to verify that a message has not been altered
or tampered with during transmission and that it originated from the expected sender.
(Advanced Encryption Standard), in combination with a secret key known only to the
sender and recipient. CMAC applies a specific process to the message and secret key to
generate a fixed-size authentication tag, known as the MAC.
4. Keyed Cipher Function: CMAC is a keyed cipher-based function, meaning that it uses
both the message and a secret key to compute the authentication tag. This ensures that
only parties possessing the secret key can generate or verify the MAC, providing
authentication and message integrity protection.
encryption, key derivation, and finalization, to the message and secret key using the
block cipher algorithm. The resulting authentication tag is appended to the message and
transmitted along with it.
network communication (e.g., TLS, IPsec), secure messaging systems, digital signatures,
and authentication mechanisms. It provides a critical layer of security for data
transmitted over insecure channels.
strong block cipher algorithm (e.g., AES) and a sufficiently long secret key to ensure
security. The length of the secret key directly impacts the security of the CMAC
construction.
Overall, CMAC is a widely used and trusted message authentication code that provides strong
security guarantees for verifying message integrity and authenticity. By employing CMAC,
cryptographic systems can ensure the secure transmission and reception of data, preventing
unauthorized tampering or modification by attackers.
Digital signatures and authentication protocols are cryptographic techniques used to verify the
authenticity, integrity, and origin of data and communications in secure systems. They play a
crucial role in ensuring trustworthiness and preventing unauthorized access or tampering with
sensitive information. Here's an overview of digital signatures and authentication protocols:
1. Digital Signatures:
• Digital signatures provide a way to verify the authenticity and integrity of digital
messages or documents.
• They are created using asymmetric cryptography, where a signer uses their
private key to sign a message, and anyone with access to the signer's public key
can verify the signature.
• The process involves the following steps:
2. Authentication Protocols:
These techniques and protocols are essential for ensuring the security and integrity of digital
communications and transactions in various domains, including e-commerce, online banking,
healthcare, and government services. They provide the foundation for establishing trust and
confidentiality in modern information systems
Digital Signature Standards
Several digital signature standards are widely used in various applications and industries to
ensure the authenticity, integrity, and non-repudiation of digital documents and transactions.
Some of the most commonly adopted digital signature standards include:
1. PKCS #1:
• Public Key Cryptography Standards (PKCS) #1 defines the syntax and encoding
rules for digital signatures using RSA (Rivest-Shamir-Adleman) encryption
algorithm.
• PKCS #1 specifies the format of digital signatures and the process for generating
and verifying RSA-based signatures.
2. X.509:
• X.509 is a standard format for public key certificates used in many cryptographic
protocols, including digital signatures.
• X.509 certificates contain information about the certificate holder, the certificate
issuer, the public key, and digital signatures from trusted certificate authorities
(CAs).
• X.509 certificates are commonly used in SSL/TLS for secure web browsing, email
encryption, and other secure communication protocols.
These digital signature standards provide interoperability, security, and compliance with legal
and regulatory requirements for digital signatures in various applications and industries,
including e-commerce, finance, healthcare, and government services. Organizations and
software developers often rely on these standards to implement secure and legally binding
digital signature solutions
Digital Signatures Schemes
• ECDSA is a variant of DSA that uses elliptic curve cryptography (ECC) instead of
traditional integer factorization-based cryptography.
• ECDSA offers the same security level as DSA but with shorter key lengths, making
it more efficient for resource-constrained environments such as mobile devices
and IoT (Internet of Things) devices.
• ECDSA signatures provide the same security guarantees as DSA signatures,
including authenticity, integrity, and non-repudiation.
These digital signature schemes provide robust security guarantees and are widely used in
various applications and industries, including e-commerce, finance, healthcare, and government
services. Organizations and developers can choose the most appropriate scheme based on their
security requirements, performance considerations, and compatibility with existing systems and
standards.
Digital Certificate
A digital certificate, also known as a public key certificate or identity certificate, is a digital
document that binds cryptographic keys to an entity's identity. Digital certificates are issued and
signed by trusted certificate authorities (CAs) and are used to establish trust and authenticity in
various online transactions and communications.
1. Issuer: The issuer of the digital certificate is the trusted entity (Certificate Authority) that
verifies the identity of the certificate holder and signs the certificate. The issuer's digital
signature on the certificate ensures its authenticity and integrity.
2. Subject: The subject of the digital certificate is the entity (individual, organization,
device, etc.) to which the certificate is issued. The subject's identity is typically specified
in the certificate, along with other relevant information such as email address,
organization name, etc.
3. Public Key: The digital certificate contains the public key of the certificate subject, which
is used for encryption, digital signatures, and secure communication. The public key is
bound to the subject's identity and can be freely distributed to other parties for secure
communication.
4. Validity Period: Digital certificates have a specified validity period during which they are
considered valid and trusted. After the expiration date, the certificate is no longer valid,
and its use is restricted.
5. Digital Signature: The digital certificate is signed by the issuing Certificate Authority
using its private key. This digital signature ensures the authenticity and integrity of the
certificate and allows recipients to verify its validity using the CA's public key.
6. Certificate Chain: In some cases, digital certificates are organized into a chain of trust,
where intermediate CAs issue certificates to subordinate CAs, and these CAs, in turn,
issue certificates to end entities. This chain of trust allows clients to verify the authenticity
of certificates by following the trust path from the end entity's certificate to a trusted
root CA certificate.
Digital certificates are widely used in various applications and protocols, including:
• SSL/TLS: In web browsers, digital certificates are used to authenticate web servers and
• Email Encryption: Digital certificates are used to encrypt and sign email messages,
• Code Signing: Software developers use digital certificates to sign software applications
• Document Signing: Digital certificates are used to sign electronic documents, such as
Overall, digital certificates play a crucial role in establishing trust and security in online
transactions and communications, enabling secure and authenticated interactions between
parties on the internet.
1. Key Generation:
2. Key Storage:
3. Key Distribution:
Effective key management and distribution practices are essential for maintaining the security,
confidentiality, and integrity of cryptographic systems and protecting sensitive information from
unauthorized access, disclosure, or tampering. Organizations should implement robust key
management strategies and controls to mitigate security risks and ensure the effectiveness of
cryptographic protections.