SHA- 1 is the first generation of sha algorithm standard, and later SHA-224, SHA-256, SHA-384 and SHA-5 12 are collectively referred to as SHA-2.
Obviously, the longer the information digest, the lower the probability of collision and the more difficult it is to crack. But at the same time, it consumes more performance and occupies more space.
As mentioned earlier, SHA- 1 and SHA-2 are two different versions of the algorithm, with different structures and signature lengths, so SHA-2 can be understood as the successor of SHA- 1.
SSL industry chooses SHA as the hash algorithm of digital signature. SHA- 1 has always been the dominant algorithm from 201to 20 15. However, with the improvement of Internet technology, the shortcomings of SHA- 1 have become more and more prominent. At present, SHA-2 has become a new standard, so the SSL certificate issued now must be signed by SHA-2 algorithm. Some people may occasionally see the SHA-2 384-bit certificate of SHA-2, but rarely see the 224-bit certificate, because the 224-bit certificate is not allowed for public trust, and the 5 12-bit certificate is not supported by the software.
The following is a comparison between SHA- 1 and SHA-2 signatures of SSL certificates.
On the surface, they seem nothing special, but digital signatures play an important role in the security of SSL/TLS. The larger the hash value, the more combinations and the higher the security. SHA-2 is much safer than SHA- 1.
An important function of password hashing algorithm is to generate a unique hash. A so-called conflict occurs when two different values or files can generate the same hash. Only when there is no collision can the security of digital signature be guaranteed. Conflicts are extremely dangerous for hashing algorithms, because conflicts allow two files to produce the same signature. When the computer checks the signature, even if the file has no actual signature, it will be recognized as valid by the computer.
The length of MD5 abstract is 128bit, and the length of SHA- 1 abstract is 160bit. What does one more 32-bit mean? The collision probability of different plaintext is reduced by 2 32 = 324294967296 times.
Because the summary of SHA- 1 is longer than MD5, the performance of SHA- 1 in generating summary is slightly lower than MD5.
Let's first review the core process of MD5 algorithm. If you haven't seen it, you can click this link: What is the MD5 algorithm?
In short, MD5 divides the information summary of 128bit into four segments (words) of 32 bits each, and alternately performs A, B, C and D operations in the loop process, and finally forms the summary result of 128bit.
Let's take a look at the SHA- 1 algorithm. The core processes are similar. The main difference is that the information summary of 160bit is divided into five sections: A, B, C, D and E.
Looking at SHA-2 series algorithms, the core process is more complicated, and the information summary is divided into eight sections: A, B, C, D, E, F, G and H.
SHA-256 has a length of 32bit, and SHA-5 12 has a length of 64bit. SHA-224 and SHA-384 are cut based on the results generated by the former two.
With 60M files as test samples, after 1000 tests, the performances of the three algorithms are as follows:
In terms of security, it is obvious that SHA256 (also known as SHA2) has the highest security, but it takes much more time than the other two. MD5 is easy to collide, so SHA 1 should be the best encryption algorithm among the three.