Cryptography Unit-4
Cryptography Unit-4
UNIT-4
Message Authentication
Elaboration:
MACs are cryptographic checksums, like TechTarget notes, that use a secret key to generate
a code (the MAC) that is appended to a message. This MAC is then sent along with the
message. The recipient can independently calculate the MAC using the same secret key and
the received message. If the calculated MAC matches the one received with the message, it
indicates that the message is authentic and has not been altered.
Cryptographic Hashes:
While similar to MACs in some ways, cryptographic hashes don't use a secret key. They
produce a fixed-size output (the hash) based on the input message. Anyone can calculate the
hash of a message without a secret key. This makes them suitable for verifying the integrity
of a message but not for verifying the sender's identity.
Digital Signatures:
Digital signatures, says ScienceDirect Topics, utilize public-key cryptography, meaning they
use both a public key and a private key. The sender uses their private key to sign the
message, and the recipient uses the sender's public key to verify the signature. This ensures
both the sender's identity and the message's integrity.
HMAC is a type of MAC that combines a cryptographic hash function with a secret key. It's
considered a more robust and secure method than traditional MACs. HMAC is widely used in
various applications, including secure communication protocols, authentication of form data,
and generation of secure hashes.
The process of using MAC for authentication is depicted in the following illustration −
The sender uses some publicly known MAC algorithm, inputs the message and the
secret key K and produces a MAC value.
Similar to hash, MAC function also compresses an arbitrary long input into a fixed
length output. The major difference between hash and MAC is that MAC uses secret
key during the compression.
The sender forwards the message along with the MAC. Here, we assume that the
message is sent in the clear, as we are concerned of providing message origin
authentication, not confidentiality. If confidentiality is required then the message
needs encryption.
On receipt of the message and the MAC, the receiver feeds the received message
and the shared secret key K into the MAC algorithm and re-computes the MAC value.
The receiver now checks equality of freshly computed MAC with the MAC received
from the sender. If they match, then the receiver accepts the message and assures
himself that the message has been sent by the intended sender.
If the computed MAC does not match the MAC sent by the sender, the receiver
cannot determine whether it is the message that has been altered or it is the origin
that has been falsified. As a bottom-line, a receiver safely assumes that the message
is not the genuine.
Digital signatures
Digital signatures are the public-key primitives of message authentication. In the physical
world, it is common to use handwritten signatures on handwritten or typed messages. They
are used to bind signatory to the message.
Similarly, a digital signature is a technique that binds a person/entity to the digital data. This
binding can be independently verified by receiver as well as any third party.
Digital signature is a cryptographic value that is calculated from the data and a secret key
known only by the signer.
In real world, the receiver of message needs assurance that the message belongs to the
sender and he should not be able to repudiate the origination of that message. This
requirement is very crucial in business applications, since likelihood of a dispute over
exchanged data is very high.
As mentioned earlier, the digital signature scheme is based on public key cryptography. The
model of digital signature scheme is depicted in the following illustration –
The following points explain the entire process in detail –
Generally, the key pairs used for encryption/decryption and signing/verifying are
different. The private key used for signing is referred to as the signature key and the
public key as the verification key.
Signer feeds data to the hash function and generates hash of data.
Hash value and signature key are then fed to the signature algorithm which produces
the digital signature on given hash. Signature is appended to the data and then both
are sent to the verifier.
Verifier feeds the digital signature and the verification key into the verification
algorithm. The verification algorithm gives some value as output.
Verifier also runs same hash function on received data to generate hash value.
For verification, this hash value and output of verification algorithm are compared.
Based on the comparison result, verifier decides whether the digital signature is
valid.
Since digital signature is created by private key of signer and no one else can have
this key; the signer cannot repudiate signing the data in future.
This makes it essential for users employing PKC for encryption to seek digital signatures
along with encrypted data to be assured of message authentication and non-repudiation.
This can archived by combining digital signatures with encryption scheme. Let us briefly
discuss how to achieve this requirement. There are two possibilities, sign-then-
encrypt and encrypt-then-sign.
The receiver after receiving the encrypted data and signature on it, first verifies the
signature using senders public key. After ensuring the validity of the signature, he then
retrieves the data through decryption using his private key.
The most distinct feature of Public Key Infrastructure (PKI) is that it uses a pair of keys to
achieve the underlying security service. The key pair comprises of private key and public key.
Since the public keys are in open domain, they are likely to be abused. It is, thus, necessary
to establish and maintain some kind of trusted infrastructure to manage these keys.
Key Management
It goes without saying that the security of any cryptosystem depends upon how securely its
keys are managed. Without secure procedures for the handling of cryptographic keys, the
benefits of the use of strong cryptographic schemes are potentially lost.
It is observed that cryptographic schemes are rarely compromised through weaknesses in
their design. However, they are often compromised through poor key management.
There are some important aspects of key management which are as follows −
Cryptographic keys are nothing but special pieces of data. Key management refers to
the secure administration of cryptographic keys.
Key management deals with entire key lifecycle as depicted in the following
illustration −
There are two specific requirements of key management for public key cryptography.
Secrecy of private keys. Throughout the key lifecycle, secret keys must remain secret
from all parties except those who are owner and are authorized to use them.
Assurance of public keys. In public key cryptography, the public keys are in open
domain and seen as public pieces of data. By default there are no assurances of
whether a public key is correct, with whom it can be associated, or what it can be
used for. Thus key management of public keys needs to focus much more explicitly
on assurance of purpose of public keys.
The most crucial requirement of assurance of public key can be achieved through the public-
key infrastructure (PKI), a key management systems for supporting public-key cryptography.
Public Key Infrastructure (PKI)
PKI provides assurance of public key. It provides the identification of public keys and their
distribution. An anatomy of PKI comprises of the following components.
Certification Authority.
Registration Authority.
Digital Certificate
Digital certificates are based on the ITU standard X.509 which defines a standard certificate
format for public key certificates and certification validation. Hence digital certificates are
sometimes also referred to as X.509 certificates.
Public key pertaining to the user client is stored in digital certificates by The Certification
Authority (CA) along with other relevant information such as client information, expiration
date, usage, issuer etc.
CA digitally signs this entire information and includes digital signature in the
certificate.
Anyone who needs the assurance about the public key and associated information of
client, he carries out the signature validation process using CAs public key. Successful
validation assures that the public key given in the certificate belongs to the person
whose details are given in the certificate.
As discussed above, the CA issues certificate to a client and assist other users to verify the
certificate. The CA takes responsibility for identifying correctly the identity of the client
asking for a certificate to be issued, and ensures that the information contained within the
certificate is correct and digitally signs it.
Key Functions of CA
Generating key pairs − The CA may generate a key pair independently or jointly with
the client.
Publishing Certificates − The CA need to publish certificates so that users can find
them. There are two ways of achieving this. One is to publish certificates in the
equivalent of an electronic telephone directory. The other is to send your certificate
out to those people you think might need it by one means or another.
Verifying Certificates − The CA makes its public key available in environment to assist
verification of his signature on clients digital certificate.
The MD5 method was among of the first hashing algorithms to gain global recognition as a
replacement to the MD4 algorithm. Despite of potential security risks, MD5 is an essential
part of data infrastructure in a wide range of situations.
What is Hashing?
Hashing is the process of changing a standard string of information into a complex piece of
data. This is done in order to scramble the information so that it entirely changes the original
value, which produces a hashed value that is completely different from the original.
Hashing transforms regular data into an unreadable form by using a hash function. The
original data is transformed into its hashed values by these hash functions, which are a
series of mathematical operations that are referred to as the hash digest or digest in general.
No matter the size of the input, the digest size for a certain hash function, such as MD5 or
SHA1, is always the same.
Password Verification
To keep passwords secure from attackers, user credentials for websites are frequently stored
in a hashed format. Comparing password hashes is far more private because hash functions
always return the same result for the same input.
File integrity is preserved if the digest matches the initial hash value.
Having established a basic foundation in hashing, you are able to examine the MD5
algorithm, which is the primary focus of this chapter.
The method was created in 1991 by Ronald Rivest to enable the verification of digital
signatures. It was included into several different frameworks in order to improve security
measures.
Because of hashing function suggestions, the digest size is always 128 bits, and even minor
changes to the input string result in considerably different digests. This is needed to reduce
the chance of hash collisions, or the formation of similar hashes.
Padding Bits
Verify that the input string's size is 64 bits less than a multiple of 512 when you receive it. In
order to round off the extra characters, you must add zeroes after adding one (1) to the bits
of padding.
Padding Length
The final string needs to include a few more characters in order to be a multiple of 512. To
achieve this, take the original input's length and represent it as 64 bits. Once the two are
combined, the last string is prepared for hashing.
Initialize MD Buffer
The entire string is divided into several blocks, each having 512 bits. In addition, four buffers
(A, B, C, and D) need to be initialised. Each of these 32-bit buffers is initialised as follows −
A 512-bit block can be further divided into 16 sub-blocks, each containing 32 bits. Each of
the four operation rounds makes use of all of the buffers, constant array values, and sub-
blocks.
Advantages of MD5
Keeping Passwords Secure − Hackers and other attackers can access passwords if
they are not kept in unencrypted format. The database benefits from digests as well
because all hash values have the same size.
Disadvantage of MD5
Sometimes, for different inputs, MD5 creates the similar hash function.
It has been said that the MD5 algorithm is unsafe. SHA256 is currently being used in
place of MD5.
SHA-1 is a cryptographic hash function that generates a 160-bit hash value (also known as a
message digest) from any input message up to 264 - 1 bits.
The National Security Agency (NSA) devised SHA-1, which was published by the National
Institute of Standards and Technology (NIST) in 1995 as part of the Secure Hash Standard
(SHS).
SHA-1 is a one-way function, which means it is impossible to compute to figure out the
original message from its hash value.
In the above image, in one cycle of the SHA-1 compression function, A, B, C, D, and E
represent 32-bit state words.
Algorithm
Initialization
o Set all five variables (h0 to h4) with the correct values.
Pre-processing
o To set a maximum length for the message, append a few '0' bits.
o At the end of the message, include the message's original length (in bits).
Processing
o Divide the message into manageable parts and deal with each one separately.
Main loop
o Based on the position and values of the word, update the temporary
variables.
Finalization
o To get the final hash, combine the hash values.
Properties of SHA-1
The fundamental purpose of a hash function is to generate a different hash value for
each input message. SHA-1 ensures that two different messages are unlikely to
generate the same hash result, making it resistant to collision attacks.
SHA-1 is a one-way function, which means that the original message cannot be
retrieved from its hash value. This attribute is critical for digital signatures, password
storage, and other security-related applications.
SHA-1 has a set output length of 160 bits, no matter the size of the input message.
This allows you to easily compare hash values and save them in databases.
Applications of SHA-1
Password Storage − Passwords are stored in databases using SHA-1. Instead of saving
the actual password, the system stores the password's hash value, making it difficult
for attackers to steal it.
Vulnerabilities of SHA-1
While SHA-1 was previously considered as a secure hash algorithm, it is currently vulnerable
to various types of attacks.
The fundamental risk of SHA-1 is collision resistance, which means two different messages
can generate the same hash value. This can be used in several ways, like −
Birthday Attack − The birthday attack is a form of collision attack in which an attacker
attempts to find two separate messages with the same hash value. A birthday attack
using SHA-1 needs only 280 computations, making it possible for modern computing
power.
Man-in-the-Middle Attack − A man-in-the-middle attack occurs when an attacker
intercepts and modifies data sent between two parties. SHA-1 allows an attacker to
generate an altered message with the same hash value as the original message which
makes it difficult to detect the change.
Alternatives of SHA-1
SHA-2 is a set of hash algorithms that contains SHA-256, SHA-384, and SHA-512,
which generate hash values of 256, 384, and 512 bits, respectively.
SHA-2, which was created to replace SHA-1, is believed to be as far more secure.
SHA-3 is a newer hash function developed by NIST in 2012 that creates hash values
differently than SHA-2 does.
SHA 256 is a part of the SHA 2 family of algorithms, where SHA stands for Secure Hash
Algorithm. Published in 2001, it was a joint effort between the NSA and NIST to introduce a
successor to the SHA 1 family, which was slowly losing strength against brute force attacks.
The significance of the 256 in the name stands for the final hash digest value, i.e.
irrespective of the size of plaintext/cleartext, the hash value will always be 256 bits.
Message length − The cleartext should be less than 264 bits. The size has to be in the
same range to keep the digest as random as possible.
Digest Length − The hash digest should be 256 bits for the SHA 256 method, 512 bits
for SHA-512, and so on. Higher digests typically represent considerably more
calculations at a cost of speed and space.
Irreversible − By design, all hash functions, like SHA 256, are irreversible. You should
not get a plaintext if you already have the digest, nor should the digest return its
original value if you put it over the hash function again.
Algorithm
You can divide the whole procedure into five different sections, as shown below −
Padding Bits
It gives some extra bits to the message so that the length is precisely 64 bits less than a
multiple of 512. In addition, the first bit must be one, and the remaining bits should be
zeros.
Padding Length
We can now add 64 bits of data to the final plaintext, which makes it a multiple of 512. To
determine these 64 bits of characters, apply the modulus to the initial plaintext without
padding.
The default settings for the eight buffers that will be used in the rounds should be set as
follows −
We need to keep 64 different keys in an array, ranging from K*0+ to K*63+.
Compression Functions
The entire message is divided into numerous blocks of 512 bits each. It runs each block over
64 rounds of operations, with the output of each one being used as the input to the next
block.
Since the value of K*i+ in all of those iterations is pre-initialized, W*i+ is another input that is
calculated separately for each block according to the number of iterations being performed
at the time.
Output
With each iteration, the block's final output becomes the input for the next block. The entire
cycle is carried out until we reach the last 512-bit block, at the point where the output is
considered the final hash digest. As the algorithm's name suggests, this digest will be 256
bits in length.
SHA-512, or Secure Hash method 512, is a hashing technique that converts text of arbitrary
length into a fixed-size string. Each output has a SHA-512 length of 512 bits (64 bytes).
This algorithm is frequently used for email address hashing, password hashing, and digital
record verification. SHA-512 is also used in blockchain technology, with the BitShares
network becoming the most known example.
What is SHA-512?
SHA-512 generates a hash value of 512 bits (64 bytes), making it one of the largest hash
functions in the SHA-2 family. SHA-512, like all cryptographic hash algorithms, has the
following basic properties −
Deterministic − The same input will always get the same result.
Fast to compute − The hash for any given data can be calculated very quickly.
Irreversible − You can not determine the original input from its hash.
Avalanche effect − A small change in input (even flipping a single bit) results in a
significantly different hash.
Without going too far into the mathematical concepts, SHA-512 operates as follows −
Initialization − It starts with eight hash values calculated from the square roots of the
initial eight prime numbers.
Main Loop − The main loop analyses each 1024-bit block in 80 rounds, manipulating
the data via logical operations, bitwise shifts, and modular arithmetic.
Output − After all of the blocks have been processed, the resulting 512-bit message
digest is output as the hash.
Algorithm
Message Padding − First, your message is padded to ensure that it is the correct size
for the algorithm. This ensures that it can be broken down into blocks and processed.
Initial hash values − The algorithm starts with eight initial hash values. These set
values serve as the basis for the hashing procedure.
Message processing − The padded message is divided into blocks. Each block
progresses over a series of stages known as rounds. In each round, the block is mixed
and adjusted using specific techniques.
Final hash value − After all blocks have been examined, the hash value is computed.
This hash value serves as a unique fingerprint for the original message.
Output − The SHA-512 algorithm generates the final hash result, which is generally a
string of hexadecimal integers. This is the value returned after hashing your original
message.
Encryption:
Authentication:
It verifies the identity of both the client and the server using digital certificates issued by
trusted Certificate Authorities (CAs).
Data Integrity:
SSL/TLS ensures that the data transmitted is not tampered with during transit, preventing
data corruption.
Handshake:
A handshake process establishes a secure communication channel between the client and
the server, negotiating encryption parameters and verifying identities.
How it Works:
1. Handshake:
The client initiates a handshake to establish a secure connection with the server.
2. Certificate Exchange:
The server presents its SSL/TLS certificate to the client, which contains its public key and
identity information.
3. Key Agreement:
The client and server agree on a shared secret key using public key cryptography.
4. Symmetric Encryption:
This shared key is then used to encrypt and decrypt data exchanged between the client and
server.
5. Data Transmission:
All data transmitted between the client and server is encrypted using the agreed-upon
encryption method.
Importance of SSL/TLS:
Secure Communication:
SSL/TLS is crucial for protecting sensitive data transmitted over the internet, such as
passwords, credit card information, and personal data.
Website Security:
It secures websites by encrypting data between the user's browser and the server, ensuring
a secure and confidential browsing experience.
An older protocol that has been largely replaced by TLS due to security vulnerabilities.
The modern successor to SSL, offering enhanced security and features, such as support for
stronger encryption algorithms.
An encryption program called Pretty Good Privacy (PGP) offers cryptographic privacy and
authentication for data transmission. PGP is used to improve the security of email
conversations as well as to sign, encrypt, and decrypt files, directories, messages, emails,
even complete disc partitions. In 1991, Phil Zimmermann created PGP.
Using the public key method, PGP allows users to have a private key that is known only to
them and a unique encryption key that is known to the public. When a user uses their public
key to transmit a message to someone, it is encrypted; the recipient uses their private key to
decrypt it. To encrypt data as it moves across networks, it combines symmetric and
asymmetric key technologies with private-key and public-key encryption.
While PGP uses a faster algorithm, encrypting a complete message can take some time. PGP
improves cryptographic security and reduces disc space and transmission time by
compressing plaintext data. The minimised version of the message is encrypted using the
public key, exactly like the entire message was. The recipient takes both, decrypts the entire
message using their private key to unlock the shorter key.
At Sender's Site
Message Creation − The sender creates a message they intend to send it safely.
Key Generation − A sender makes a pair of encryption keys where one is shared
publicly and the other stays private.
Encryption of Message − Encrypting the message text with the receiver's public key
ensures that only the receiver would decrypt it through the private key.
Encryption Message Sending with Signatures − The sender forwards the encrypted
message to the recipient and sends along a digital signature. Upon receiving this
message, the receiver will use his private key for decrypting while using the sender's
public key to verify whether the message is authentic or not.
At Receiver's Site
Receive Encrypted Message with Signature − When the sender sends an encrypted
message and its digital signature, the receiver gets it.
Decrypt Message − The receiver decrypts the encrypted message using a private key
that matches the one they have made public.
Digital Signature Verification − To achieve this, the receiver utilizes the sender's
public key to verify the digital signature of the attached message. This way, it can be
confirmed that the message was truly sent by the alleged sender without changing
anything along the way.
Usage of PGP
Authentication and Integrity Checking − Digitally signing with PGP helps in verifying
identities of senders and finding out if messages are changed whatsoever.
Ensuring Message Delivery − Public keys come along with identity certificates which
contain a specific recipient information and alert against any interference attempts.
Email Encryption − In order to keep your data secure, it is normal that you use PGP
to encrypt email messages.
Digital Signature Verification − By using PGP one is able to verify whom the message
was sent from by using their digital signature. It will be in most cases combined with
threat detection tools for increased security.
File Encryption − PGP's robust RSA encryption makes it suitable for securiing files.
Advantages of PGP
This is because PGP prevents hackers, governments, and nation-states from accessing PGP-
encrypted files or emails.
Disadvantages of PGP
It requires that users understand the complexities of the PGP system to avoid
unknowingly destroying their security security measures. This can occur if you use
PGP incorrectly or lose or corrupt your keys, leaving other users at risk in scenarios
where security is important.
PGP encrypts user messages but fails to offer users any privacy. This makes it possible
to determine the source and recipient of emails transmitted over PGP.