Detailed explanation of the characteristics, application and implementation method of Hash algorithm

What is Hash algorithm? Hash algorithm, referred to as hash algorithm, also known as hash algorithm (English translation), is to map a large file into a small string of characters. Like a fingerprint, it is a sign that uses shorter information to ensure the uniqueness of the file. This sign is related to every byte of the file, and it is difficult to find the reverse rule.

Features of Hash Algorithm

Forward fast: given the plaintext and hash algorithm, the hash value can be calculated within limited time and limited resources.

Reverse Difficulty: Given (several) hash values, it is difficult (basically impossible) to reverse the plaintext within a limited time.

Input Sensitive: If the original input information is modified a little bit, the resulting hash values ​​should look very different.

Conflict avoidance: It is difficult to find two pieces of plaintext with different contents so that their hash values ​​are consistent (collision occurs). That is, for any two different data blocks, the possibility of having the same hash value is extremely small; for a given data block, it is extremely difficult to find a data block with the same hash value.

Hash algorithm in information security

(1) File verification

The check algorithms we are more familiar with include parity check and CRC check. These two checks have no ability to resist data tampering. They can detect and correct channel errors in transmitted data to a certain extent, but they cannot prevent data from being tampered with. Malicious destruction of data.

The "digital fingerprint" feature of the MD5 Hash algorithm makes it the most widely used file integrity checksum (Checksum) algorithm. Many Unix systems provide commands to calculate the md5 checksum.

(2) Digital signature

The Hash algorithm is also an important part of the modern password system. Because the operation speed of the asymmetric algorithm is relatively slow, the one-way hash function plays an important role in the digital signature protocol. Digitally signing the Hash value, also known as "digital digest", is statistically equivalent to digitally signing the file itself. And this agreement has other advantages.

(3) Authentication protocol

For example, the following authentication protocol is also called challenge-authentication mode: it is a simple and safe method in the case that the transmission channel can be intercepted but cannot be tampered with.

How is the Hash algorithm implemented?

With the development of cryptography and information security, various encryption algorithms and hash algorithms can no longer be explained in a few words. Here we only provide a few simple concepts for your reference.

As a hash algorithm, the primary function is to use an algorithm to record the original large file information with several characters, and to ensure that each byte will have an impact on the final result. Then you may have thought that the algorithm of modulus can meet our needs.

In fact, as an irreversible calculation method, the modulo algorithm has become the foundation of the entire modern cryptography. As long as it involves the field of computer security and encryption, there will be modular computing. Hash algorithm is no exception. One of the most primitive hash algorithms is to simply select a number for modulo operation, such as the following program.

Obviously, the above program completes the primary goal that a hash algorithm should achieve: use less text to represent very long content (the number after the modulus must be less than 8). But you may have noticed that the results calculated by simply using the modulo algorithm have obvious regularity, which will make it difficult for the algorithm to guarantee irreversibility. So we will use another method, which is XOR.

Let's look at the following program again. We add an XOR process to the hash function.

Obviously, after adding a layer of XOR process, the regularity of the result after calculation is not so obvious.

Of course, you may think that such an algorithm is still very unsafe. If the user uses a series of continuously changing texts to compare with the calculation results, it is very likely to find the laws contained in the algorithm. But we have other options. For example, modify the original text before performing calculations, or add additional operations (such as shifting), such as the following program.

The hash algorithm obtained in this way is difficult to find its internal laws, that is to say, we cannot easily give a number so that the result after the above hash function operation is equal to 4—unless we exhaustively enumerate test.

Isn't the above algorithm very simple? In fact, the common algorithms MD5 and SHA1 that we will introduce below, their essential algorithms are so simple, but more cycles and calculations will be added to strengthen the reliability of the hash function.

Common Hash Algorithms

The main Hash implementations mainly include the following categories, among which MD5 and SHA-1 are the most widely used Hash algorithms.

MD4

MD4 was designed by Rivest of MIT in 1990, and MD is the abbreviation of Message Digest. It is implemented based on bit manipulation of 32-bit operands.

MD5

MD5 is Rivest's improvement of MD4 in 1991. MD5 is more complicated than MD4, so it is slower, but it has better security.

SHA-1

SHA-1 was designed by NIST NSA, which produces a hash value with a length of 160 bits for input lengths less than 264 bits. Therefore, the resistance to exhaustion is better. SHA-1 imitates the algorithm of MD4.

The above is to share with you the whole content of "Detailed Explanation of the Characteristics, Application and Implementation Method of Hash Algorithm".

Guess you like

Origin blog.csdn.net/lavin1614/article/details/131089352