SHA-1, MD5, HMAC Algorithms

Source: Internet
Author: User
Tags hmac

This article is all copied from the Internet.

1. SHA-1 and MD5
Md4 (rfc1320) is the ronaldl of MIT. designed in 1990 by Rivest, MD is the abbreviation of messagedigest; MD5 (rfc1321) is an improved version of md4 by Rivest in 1991, and hash any long plaintext into a 128-bit hash value.
Sha1 is designed to be used together with DSA by nist nsa, and Sha is short for secure hash algorithm. It produces a hash value with a length of less than 2 ^ 64 and a length of bits; SHA-1 is designed based on the same principle as md4 and imitates this algorithm.
Information cannot be restored from the message digest; two different messages do not produce the same message digest.

Reference: http://wenda.tianya.cn/wenda/thread? Tid = 7d8ae146f81491e7
Reference: http://blog.csdn.net/candy_whut/archive/2009/02/03/3859830.aspx

2. HMAC
The HMAC algorithm requires a hash algorithm and a key. The implementation of this hash algorithm must meet the requirements of "data is hashed by iterating a basic compression function on blocks of data ".H; Key is shortK.
Hypothesis
BIs the length of blocks (byte) (B = 64 for MD5 and SHA-1 );
LIs the Key Length (byte) (L = 16 for MD5, L = 20 for SHA-1 );
IPad= The byte 0x36 repeated B times;
OPAD= The Byte 0x5c repeated B times;
K can be any length less than or equal to B; if K is greater than B, K = H (k ). It is recommended that the length of K be less than l, otherwise it will reduce the security strength of the algorithm. Formula of this algorithm:H(K XOR OPAD,H (k xor iPad, text)), Where text is the target data, the specific steps:
(1) Add 0 after K to make it length B;
(2) perform bitwise XOR operation on the string (1) generated in bytes B with the iPad;
(3), append to (2) the string of the byte length generated by text streams;
(4), H acts on the streams generated (3;
(5) perform bitwise exclusive or operation on the string generated in bytes B and OPAD;
(6) append to (5) the hash value generated by (4) to a string of B bytes;
(7), H acts on the streams generated by (6.
Reference: rfc2104

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.