##### HASH functions

**HASH FUNTIONS**

Hash and mac functions are actually the part of cryptographic and data integrity algorithms in the information assurance and security.

**What is a hash actually?**

A hash function takes the input value and compresses the input and produces the output as the hash value which is shorter than the input. It accepts the various sizes of block data or message and produces the fixed size hash value depends on the algorithms. Say if the message is M, then it will produce the hash value h= H (M). It follows the principle of data integrity to encrypt the stuff. A well-defined hash function has the property of accepting the large set of input and produces the evenly distributed and random output. A small deflection in the input effect the output to the extreme level. It is computationally infeasible to find the data, so it is often used to find whether data is remained unchanged or not.

**Block representation of hash**

**Applications of hash**

· message authentication

· digital signature

· Block chain.

**Message authentication:**

It is the service offered by hash functions used to check the integrity of the message. It validates the contents if the message and checks the changed things in the message.

Let’s see how a hash will be integrated to provide mac as a service.

Hash function uses symmetric key encryption to provide the mac service, hash provide different ways to serve this.

The above method follows the symmetric encryption with un-keyed hash. In this the message is concatenated with the hash and both are encrypted using the symmetric encryption. Encryption is provided to entire hash and message, so this also provides confidentiality.

This method also follows symmetric encryption with un-keyed hash. In this the message is un-encrypted and the hash is encrypted and then concatenated with the plain text, this will reduce the processing at the receiver side and it does not provide confidentiality.

The above method follows the symmetric encryption with keyed hash( s). in this method, both the communication parties shares a common value S. sender sends the concatenated values of both S and the hash values and are again combined with the message, the receiver does the reverse methodology. Receiver cannot modify the contents of the message.

This method is also same as the above method the additional benefit if this method is it provides confidentiality of the message as the message is encrypted with the key and then send to the receiver.

Whenever confidentiality is not required, method 2 is best to approach as it requires less computation.

**Digital signatures**

Digital signatures are used to check the integrity of the message. It id same as the MAC. The hash values is encrypted using the user private key. The attackers who wants to alter the contents of the message, shall know the private key of the sender.

The hash code is encrypted using public key cryptographic technique with senders private key, it ensures the authentications and digital signatures as the service.

This provides all the facilities provided by the above model, apart from that it also provides the confidentiality as the service.

**One-way password file**

Hash of a password is stored in the os. When the user enters the password, hash of that password is compared with the stored hash value for verification. It is also used for intrusion detection and virus detection.

**Block chain technology**

In block chain technology, hash function is used to encrypt the ledger for every individual. It makes the data visible to every user, but they cannot modify the contents. It supports the block chain principles.

Hash is also used in the pseudo random number generator. PRF is the commonly applied hash function for the pseudo random number generator.

**Two simple hash functions**

· First simple hash function

· Second simple hash function

**First simple hash function**

It is one of the simplest hash function uses the bit-wise exclusive OR operation. This can be expressed as

Ci= bi1Å bi2Å bi3Å bi4Å….. bim

Where Ci is termed as ith bit of the hash code.

M= no. of blocks in the input

bij= ith bit in the jth block

**Example:**

OSL

Alphabetical indices of O is 14, S is 18, L is 11.

Hash values of OSL is 010111

**Second simple hash function**

In this method, we perform the circular shift or rotation on the hash value after each block is processed.

Steps involved in second simple hash function

1) Initially set the n-bit hash value to 0

2) Process each n-bit block of data as follows

3) Rotate the resultant hash value to left by one-bit

4) Apply XOR to the block into the next value

**Example:**

OSL

Alphabetical indices of O is 14, S is 18, L is 11.

Initially consider 0

Hash values of OSL is 010111

**Property of hash function**

· Pre-image resistant

· Secondary pre-image resistant

· Collision resistance

**Pre-image resistant**

It is also called as one-way property of hash function. It says that the hash digest can be found easily for a given message but message cannot be found for the given hash digest.

**Secondary pre-image resistant**

This says that it impossible to find the same hash digest for two different messages. This makes sure to avoid the forgery when we use hash encryption

**Collision resistance**

A hash function without following this property is said to be a weak hash function. A strong hash function protects against an attack in which one party generates a message for another party to sign.

**SECURE HASH ALGORITHM**

SHA is a n-bit hash algorithm which takes the input as the maximum of 2128 bits and produces the length of 512 bits. It will process the input as the 1024 bit blocks. Comparison of n-bit SHA algorithms.

**Block representation of SHA-512**

**Steps involved in SHA-512:**

1) Append padding bits

2) Append the length

3) Initialize the hash buffer

4) Process the message in 1024 bit

5) Output the final state value as the resultant hash

**Append padding bits**

The length of the message should be padded so that it must be congruent to 896 mod 1024. The padding bits consists of single 1 and remaining bits will be 0’s.

**Append the length**

A 128 bit block is appended to the message, by doing this the output is an integer which is the multiple of 1024.

**Initialize the hash buffer**

A 512-bit buffer is used to hold the intermediate results of hash function. The buffer is represented as 8-64 bit regiters, a,b,c,d,e,f,g .

**Process the message in 1024 bit**

This process the heart of the algorithm where it undergoes 80 rounds of execution to produce the output. Each round takes the 512-bit value and updates the contents of buffer.

**Output the final state value as the resultant hash**

After all 1024-bit blocks have been processed; the output from the Nth stage is the 512-bit message digest.