Sunday, October 31, 2021

Introduction of MAC (Mesage Authentication Code) | Application of Messsage authentication code | Importance of MAC

Introduction of MAC

Message authentication is a mechanism or service used to verify the integrity of a message. Message authentication guarantees that the sender of the message is authentic.

Figure: Block Diagram of MAC

A MAC algorithm, sometimes called a keyed hash function accepts as input a secret key an arbitrary-length message to be authenticated, and outputs a MAC. MAC value protects both a message’s data integrity as well as its authenticity, by allowing verifies to detect any changes. The MAC is a small fixed-size block of data that is generated based on a message M of variable length using secret key K as follows. MAC is also called cryptographic checksum.

MAC = C (K, M)

 

Application of MAC

#1 Message Authentication


Figure: Message Authentication

Sender A want to send message to B via MAC, then the first condition is to share a secret key K. Sender A calculates the MAC from message M by applying K. Append MAC to the message M. A sends the original message M and the MAC to B. When B receives message, B also uses K to calculate own MAC over message M. B now compares MAC1 and MAC2. If both are same, B assures that message is not altered during transmission. If it is not matched, it means B can reject the message.

 

#2 Message Authentication and Confidentiality; Authentication tied to plain text


Figure: Message Authentication and Confidentiality

Sender A want to send message to B via MAC, then the first condition is to share a secret key K1. Sender A calculates the MAC from message M by applying K1. Append MAC to the message M. Encrypt message and appended MAC using key K2. A sends the generate cipher text (Message + MAC) to B. When B receives cipher text, decrypt using key K2. B also uses K1 to calculate own MAC over message M. B now compares MAC1 and MAC2. If both are same, B assures that message is not altered during transmission. If it is not matched, it means B can reject the message.

 

#3 Message Authentication and Confidentiality; Authentication tied to cipher text


Figure: Message Authentication and Confidentiality

Sender A want to send message to B via MAC, then the first condition is to share a secret key K1. Sender A encrypt the message and generate cipher text using key K 2. Sender A calculates the MAC from cipher text by applying K1. Then append MAC to cipher text. A send appended cipher text plus MAC to B. When B receives message, B also uses K1 to calculate own MAC over message M. Decrypt ciphertext using K2 and get original message. B now compares MAC1 and MAC2. If both are same, B assures that message is not altered during transmission. If it is not matched, it means B can reject the message.

 

Importance of MAC:

MAC ensures that only receiver can identify the original message. Even if attacker modifies the message M, but cannot modify MAC. In case of MAC is modified by attacker, receiver’s calculations of MAC will differ from it. MAC cannot modify easily because MAC is encrypted by secret key K, but key is only known by sender and receiver only. MAC in one-way function. MAC provides data integrity and authentication both. Also apply encryption and achieve confidentiality.

To learn more about Introduction of MAC & it's Applications, Click here

   Watch more videos click here.

Thursday, October 28, 2021

Message Digest 5 algorithm (MD 5 algorithm) | Working of MD 5 | How message digest generate using MD5 algorithm

 

Introduction

128-bit message digest developed by Ron Rivest. This algorithm takes the input length of arbitrary length and 128-bit message digest is produced. The input message is 512-bit blocks. Figure shows processing of message to produce message digest.

Figure: Message Digest generation using MD5

MD 5 Algorithm

Step 1: Append Padding Bits – The message is padded to make the length of message is 448 mod 512. 64 bits is padded with 448 bits and convert into multiple of 512 bits. The padding message consists a single 1-bit followed by 0 bits. The length of padding bits is in between 1 to 512.

Step 2: Append Length – 64 bit of original message is appended to the result of above step 1. It is appended such that least significant bytes to most significant byte. The output of step 2 yields a message of integer multiple of 512 bits. As M0, M1,..., Mq,..., ML-1. The total length of expended message is L * 512 bits.

Figure: Intialized MD Buffer

Step 3: Initialize MD Buffer – A 128-bit buffer is used to store the intermediate as well as final result. A buffer is represented as four 32-bit registers as four 32-bit registers as P, Q, R, S.

     P = 01 23 45 67

     Q = 89 AB CD EF

     R = FE DC BA 98

     S = 76 54 32 10

It is used an initial value (IV).

Step 4: Process Message in 512-bit blocks It consists of four rounds of processing as shown in figure. These four rounds have similar structure as SHA but differ in primitive logical function referred as A, B, C, D. Each round takes input 512-bit block, processed it and produces 128-bit output. The output of fourth round is added to the first round CVq to produce CVq+1.

Step 5: Output – After processing all L 512-bit blocks, the 128-bit message digest is produced as an output.


To learn more about Message Digest Algorithm (MD 5), Click here

   Watch more videos click here.

Wednesday, October 27, 2021

Secure Hash Algorithm – 1 | Working of SHA 1 | Compare differernt version of SHA | Difference between SHA 1 and MD 5

Introduction

The secure hash algorithm (SHA) was developed by National Institute of Standards and Technology (NIST). It is based on MD4 algorithm. Based on different digest lengths, SHA includes algorithms such as SHA-1, SHA-256, SHA-384 and SHA-512. Unlike encryption, given a variable length message x, a secure hash algorithm computes a function H(x) which has a fixed bit. When a message of any length is less than 264 bits is input, the SHA-1 produces a 160-bit output called message digest. SHA-1 called secure because it is computationally infeasible to find a message which corresponds to a given message digest, or to find two different messages which produce the same message digest. The most commonly used hash function from the SHA family is SHA-1. SHA-1 is used in SSL/TLS, PGP, SSH, MIME and IPsec for security and authentication purpose.

 

Features of SHA – 1

Message or data file used as input in SHA-1 to compute a message digest (output of hash function or final hash value). The message or data file should be considered to be a bit string. The length of the message is the number of bits in the message (the empty message has length 0). The purpose of message padding is to make the total length of a padded message a multiple of 512. (If any message length is 1000 bits, so padded 24 bits to make message into multiple of 512 bits). The SHA-1 sequentially processes blocks of 512 bits when computing the message digest.

 

Working of SHA – 1

SHA1 works with any input message that is less than 264 bits in length. The output of SHA is a message digest, which is 160 bits in length.

Figure: Working of SHA-1


Step – 1: Padding - The first step of SHA-1 is added padding to the end of original message to prepare message in multiple of 512 bits.

Step – 2: Append Length – The length of message excluding the length of the padding is now calculated and appended to the end of the padding as 64-bit block. (message length is 64 bits short of multiple of 512).

Step – 3: Divide the input into 512-bit blocks: The input message is now divided into blocks, each of length 512 bits.

Step – 4: Initialize chaining variables: Now, five chaining variables A to E are initialized. Each of 32 bits variable produces 160 bits length of message digest.

Step – 5: Process Block & Output – Combination of A-E chaining variable is called ABCDE, will be considered as a single register. Now divided the current 512-bit block into 16 sub blocks, each consisting of 32 bits. (32x16=512) SHA-1 has perform four rounds. Each round takes the current 512-bit block, the register ABCDE and constant K(t) (where t=0 to 79) as input. SHA consists of four rounds, each round containing 20 iterations. So total iteration is 80. The logical operation of a single SHA-1 iteration looks as shown in figure. Mathematically, an iteration consists of the following operation:

ABCDE = E + Process P + S 5(a) + W(t) + K(t)


Comparison of different SHA version

SHA – 1 was cracked in the year 2005. New hash function SHA-512 is introduced to overcome problem SHA-1.


To learn more about Secure Hash Algorithm (SHA-1), Click here

   Watch more videos click here.

Hash Function based on cipher block chaining

 Hash Function based on cipher block chaining

Two major categories of hash functions are: dedicated hash functions and block cipher-based hash function.

 

Figure: Cipher Block Chaining Mode

Block cipher is a popular encryption-decryption primitives. To encrypt, the block cipher accepts a key K and a plain text block P as input and produces a cipher text block C = E (K, P), also written as C = EK (P).

By the definition of CBC: Cj = E (K, [Cj-1 Pj])

Figure: Hash Function based on CBC

The hash function takes an input message and partitions it into L fixed-sized blocks of b bits each. If necessary, the final block is padded to bits. The final block also includes the value of the total length of the input to the hash function. The inclusion of the length makes the job of the opponent more difficult. Either the opponent must find two messages of equal length that hash to the same value or two messages of differing lengths that, together with their length values, hash to the same value. The hash algorithm involves repeated use of a compression function, f, that takes two inputs (an n-bit input from the previous step, called the chaining variable, and a b-bit block) and produces an n-bit output. At the start of hashing, the chaining variable has an initial value that is specified as part of the algorithm. The final value of the chaining variable is the hash value. Often, hence the term compression.

The hash function can be summarized as:


To learn more about Hash function based on Cipher Block Chaining, Click here

        Watch more videos click here.

Tuesday, October 26, 2021

Security Requirement of Hash Function

Introduction

In hash function H accepts a variable length block of input data called as ‘M’ and produces the fixed size hash value can be represented as h = M(H).

Figure: Block Diagram of Hash Function

When hash function provides security, this is called cryptographic hash functions. Hash function protects the integrity of the message. If encryption process is applying on message with hash function, it is also providing authentication and confidentiality.

A hash function provides a property that has function applied on variable amount of data (M) and then it produces the fixed amount of output data. If any bit or bits changes in the data, then whole hash function output data will also change. Cryptographic has function is one-way function, which is practically infeasible to invert. The most popular hashing algorithm is MD5 and SHA.


Security Requirement of Hash Function



The first three properties are requirements for the practical application of a hash function.

The fourth property, preimage resistant, is the one-way property: it is easy to generate a code given a message, but virtually impossible to generate a message given a code. This property is important if the authentication technique involves the use of a secret value. However, if the hash function is not one way, an attacker can easily discover the secret value.

The fifth property, second preimage resistant, guarantees that it is impossible to find an alternative message with the same hash value as a given message. This prevents forgery when an encrypted hash code is used. If this property were not true, an attacker would be capable of the following sequence: First, observe or intercept a message plus its encrypted hash code; second, generate an unencrypted hash code from the message; third, generate an alternate message with the same hash code.

If the sixth property, collision resistant, is also satisfied, then it is referred to as a strong hash function. A strong hash function protects against an attack in which one party generates a message for another party to sign. For example, suppose Bob writes an IOU message, sends it to Alice, and she signs it. Bob finds two messages with the same hash, one of which requires Alice to pay a small amount and one that requires a large payment. Alice signs the first message, and Bob is then able to claim that the second message is authentic.

To learn more about Security Requirement of hash function, Click here

        Watch more videos click here.

Monday, October 25, 2021

Purpose of Hash Function | Application of Hash Function | Real time application of Hash Function

     Purpose of Hash Function

Purpose of a hash function is to verify the integrity of a message. Message authentication is a mechanism or service used to achieve authentication. Message authentication and hash function assure that data received are exactly as sent by sender. (i.e., contain no modification, insertion, deletion, or replay). In many cases, there is a requirement that the authentication mechanism assures that provide identity of the sender is valid. When a hash function is used to provide message authentication, the hash function value is often referred to as a message digest.


Application of hash function Using Symmetric Key Cryptography

#1 - In above figure, hash code is generating from message and then appended to message. The message plus concatenated hash code is encrypted using symmetric encryption. Because only A and B share the secret key(K), the message must have come from A and has not been altered. The hash code provides the structure or redundancy required to achieve authentication. Encryption is applied to the entire message plus hash code, confidentiality is also provided.

#2 - In above figure, hash code is generated from given message. After generation of hash code, it is encrypted using secret key (K). Then encrypted hash code is append with original message and send to the receiver. It reduces the processing burden for those applications that do not require confidentiality.

#3 - 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 compute the hash value over the concatenation of M and S, appends the resulting hash value to M. Because B possesses, it can recompute 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.


#4 - Confidentiality can be added to the approach of previous method by encrypting the entire message plus the hash code. When confidentiality is not required, method (2) has an advantage over methods (1) and (4), which encrypts the entire message, in that less computation is required.


Application of hash function Using Asymmetric Key Cryptography

#1 - Another important application, which is similar to the message authentication application, is the digital signature. Purpose of digital signature is verify sender’s signature to achieve authentication. In the case of the digital signature, the hash value of a message is encrypted with a user’s private key PRa. Anyone who knows the user’s public key PUa can verify the integrity of the message. It also provides a digital signature, because only the sender could have produced the encrypted hash code.

#2 - In above figure, hash code is encrypted using user’s private key. Then encrypted hash code appended to the message. Now, message plus hash is encrypted using symmetric secret key (K). Using above diagram, we can achieve confidentiality as well as authentication. Figure A and B both are hash code based digital signature.


Realtime application of Hash Function

Hash functions are commonly used to create a one-way password file. A hash of a password is stored by an operating system rather than the password itself. Thus, the actual password is not retrievable by a hacker. Who gains access to the password file? 

In simple terms, when a user enters a password, the hash of that password is compared to the stored hash value for verification. This approach to password protection is used by most operating systems. Hash functions also can be used for intrusion detection and virus detection.


To learn more about Application of Hash Function, Click here

        Watch more videos click here.

Introduction of Hash Function | Properties of Hash Function | Characteristics of Hash Function

     Introduction

In hash function H accepts a variable length block of input data called as ‘M’ and produces the fixed size hash value can be represented as h = M(H).

Figure: Block Diagram of hash function

When hash function provides security, this is called cryptographic hash functions. Hash function protects the integrity of the message. If encryption process is applying on message with hash function, it is also providing authentication and confidentiality.

 


A hash function provides a property that has function applied on variable amount of data (M) and then it produces the fixed amount of output data. If any bit or bits changes in the data, then whole hash function output data will also change. Cryptographic has function is one-way function, which is practically infeasible to invert. The most popular hashing algorithm is MD5 and SHA.

 

Properties of hash Function

Compression: As per compression properties, output of the hash function is much smaller than the size of input.

Pre-image resistance: Pre-image resistance means difficult to find the input from given hash function output. i.e., x=H(m). So if x is given, it is difficult to message m.

Weak Collision Resistance: Given message m1, weak collision resistance means that it is difficult to produce another message m2 such that H(m1)=H(m2).  i.e, it means it is infeasible to find two different messages with the same hash value.

Strong Collision Resistance: Strong collision resistance means that is difficult to find any two different messages that hash to the same value. i.e., it means it is hard to find m1 & m2 such that same hash value H(m1) = H(m2).

 

Characteristics of hash Function

1. It is quick to calculate hash value (h) for any given message. i.e., x = H(m).

2. Hash function (H) can be applied to variable length of data block.

3. A small change in a message should change the hash value.

4. Hash function has one-way property; it is impossible to generate message from given hash value.

5. The hash function uses all the input data.

6. The hash function "uniformly" distributes the data across the entire set of possible hash values. 

7. The hash function generates very different hash values for similar message.


To learn more about Introduction of Hash Function & its properties, Click here

        Watch more videos click here.

Friday, October 22, 2021

Man in the middle attack in diffie - hellman key exchange algorithm | How to prevent man in the middle attack in diffie hellman key exchange algorithm

Introduction to man in the middle attack

Man-in-the-middle attack (Meet-in-the-middle attack) is a common type of security attack that allows attackers to eavesdrop on the communication between two users.

The attack takes place in between two users, allowing the attacker to “listen” to a conversation, without permission of users, hence the name “man-in-the-middle.”

Here’s an analogy: Alice and Bob are having a conversation; Darth (Attacker) wants to eavesdrop on the conversation but also remain transparent.

Darth could tell Alice that he was Bob and tell Bob that she was Alice.

This would lead Alice to believe she’s speaking to Bob, while actually revealing her part of the conversation to Darth.

Darth could then gather information from this, alter the response, and pass the message along to Bob (who thinks he’s talking to Alice).

As a result, Darth is able to transparently hijack their conversation.

Purpose of Diffie-Hellman key exchange algorithm is exchanging public keys and calculate secret keys using public keys.

Then subsequent messages (further communications) are encrypted using secret keys.


Man-in-the-middle attack in Diffie-Hellman Key exchange algorithm

Man in the middle attack in Diffie-Hellman key exchange is takes place during exchanges of public keys, it may be attacker capture the both keys and new values of keys are share with both the users.

Subsequent encrypted messages are read and modified by attacker. Then send to the respective user. Using this attack attacker may read and modify messages and get the benefits of user communication. Let see one scenario….


As per Diffie-Hellman key exchange algorithm Alice wants to exchange key with Bob:

As per Above Diagram

Alice, Select XA.

Calculate YA.

Bob, Select XB.

Calculate YB.

Darth prepares for the attack,

Generating two random private keys XD1 and XD2

Calculate public key YD1

Calculate public key YD2

As per key exchange algorithm, Alice transmits her public key YA to Bob.

Darth intercepts YA

Darth calculate secret key KAlice for more conversation with Alice. KAlice = (YA)XD2 mod q.

Darth transmits YD1 (in place of YA) to Bob. Bob doesn’t have an idea, YD1 is shared by Darth.

Bob calculate secret key K1 using YD1. Secret Key K1 = (YD1) XB mod q.

Bob transmits his public key YB to Alice.

Darth intercepts YB.

Darth calculate secret key KBob for more conversation with Bob.  KBob = (YB) XD1 mod q.


Darth transmits YD2 (in place of YB) to Alice. Alice doesn’t have an idea, YD2 is shared by Darth.

Alice calculates secret key K2 using YD2. Secret Key K2 = (YD2) XA mod q.

Now, Darth will capture all subsequent messages of Alice and Bob. Read and modify all the message and send to the alice and Bob.

It means Alice communicate with Darth and Bob also communicate with Darth.  But Alice and Bob have think, they are communicate with each others.

This type of attack is called man in the middle attack in Diffie-Hellman Key Exchange.

We cannot easily detect man-in-the-middle attack, so we need to prevent man-in-the-middle attack before communication.

 

How to prevent from Man-in-the-Middle Attack

Strong WEP/WAP Encryption on Access Points

Strong Router Login Credentials

Virtual Private Network

Use of HTTPS

To learn more about man in the middle attack in diffied-hellman key exchange algorithm, Click here

        Watch more videos click here.