RFC1312 Chinese version
Organization: China Interactive Publishing Network (http://www.china-pub.com/)
RFC documents Chinese Translation Project (http://www.china-pub.com/compters/emook/aboutemook.htm)
E-mail: ouyang@china-pub.com
Translator: ()
Published: 2001-2002-11 - 7
Copyright: Chinese translation of this document belongs to China all the interactive publishing network. Can be used for non-commercial purposes reproduced free, but must retain this document translation and copyright information.
Network Working Group R. Rivest
Request for Comments: 1321 MIT Laboratory for Computer Science
And RSA Data Security, Inc.
April 1992
MD5 reported digest algorithm (RFC1321 - The MD5 Message-Digest Algorithm)
In this paper, this position is not designated an Internet standards, but to provide information to the Internet, the paper can be spread unrestricted.
Thanks
Don Coppersmith, Burt Kaliski, Ralph Merkle, David Chaum, and Noam Nisan to provide great help in this, I said that in this loyal gratitude.
Contents
1 Executive Introduction 1
2 terminology and symbols 1
3 MD5 algorithm description 2
4 Summary 4
5 MD4 and MD5 distinction 4
6 Reference 4
Appendix A-7 reference applications 4
8 security matters 18
9 The author addresses 18
This paper describes the implementation of a brief summary of the report MD5 algorithm, the algorithm will be of arbitrary length of the input information, have a length of 128 "fingerprint" or "to digest", on the assumption that two different documents have the same Abstract or reported by the newspaper to be a summary of the original information in the calculation is not feasible. MD5 algorithm is suitable for use in data Signed applications, in this application, a large documents must be in a similar RSA public key algorithm private key encryption system used before "compression" in a safe mode.
MD5 algorithm to 32 machines can run fast. In addition, the MD5 algorithm does not require any large-scale replacement list.
The encoding algorithm is very simple. MD5 algorithm is reported MD4 digest algorithm expansion. MD5 algorithm to embark on MD4 algorithm, but in the design of more than MD4 algorithm "conservative." Design MD5 because MD4 algorithm was used too fast, so it is also impossible to prove the correctness because MD4 algorithm very quickly, it is in secret to the success of the attacks "marginal." MD5 taking one step back,
It sacrifice some speed to better security. It focuses on a variety of the recommendations made by the commentators, and take a number of additional optimization measures. It was placed on public places to public comment, it may be adopted as a standard.
Based on OSI as the application of the object identifier MD5 is:
Md5 OBJECT IDENTIFIER:: =
Iso (1) member-body (2) US (840) rsadsi (113,549) digestAlgorithm (2) 5)
In X.509 type AlgorithmIdentifier [3], MD5 algorithm parameters should include NULL type.
2 In this paper, terminology and symbols in a "word" is 32, a "byte" is eight. A series of strings can be seen as a series of bytes of general form,
The consecutive eight as a byte, the previous high, empathy can be viewed as a byte string is a series of 32 characters, each of the four consecutive bytes as a single word, the former status.
We definition x_i represent "I x minus." If underlined the left is an expression, including live with square brackets, such as:
X_ (i +1). Similarly, we use ^ representatives exponentiation, such x ^ x i is the i representatives of the power.
Symbol "+" represents the word Canada, X <<<32 s on behalf of the value of the left circle X-s, not (X), on behalf of the X-by-bit computing, X v Y said that the X and Y position or by computing , XxorY representatives of the X and Y by bit XOR operation, XY representatives
X and Y-and computing-on.
3 MD5 algorithm description we assume that there is a b length of the input signal to a summary of its report, here b is a non-negative integer, b may be 0, does not need the whole eight several times, it may be Arbitrary length. We envision signals in the bit stream as follows:
M_0 m_1 … m_ (b)-1
Below the five-step calculation of the reported information to digest.
(1) fill the seats
MD5 algorithm is on the importation of data fill the seats, making LEN if the data length for the 512 is the result of more than 448. That the data extended to K * 512 +448 bit. Namely, K * 64 +56 bytes, K integer. Fill the seats should always be the implementation of operation, even if the data length LEN
For the 512 is the result of more than 448.
Operation-specific meeting: fill a 1-0 and then to meet those requirements. At least have to pay a total of up to fill 512.
(2) Additional data length
With a 64-bit digital data that the original length b, b with two 32 median said. B then only from the low 64.
When faced b> 2 ^ 64 rarely encountered such a situation, then, was to fill data on the growth of the multiples for 512. In other words,
At this point the data is the length of 16 characters (32-bit) integer multiples. By M [0 … N-1] said that at this time the data, which is 16 N
In multiples.
(3) buffer initialization MD
The words of a buffer (A, B, C, D) was calculated summary, A, B, C and D respectively, a 32-bit register initialization using the hexadecimal number of
A = 0X01234567
B = 0X89abcdef
C = 0Xfedcba98
D = 0X76543210
(4) dealing with the definition of operational functions first four auxiliary function, the function of each of the three 32-bit input is a word, the output is a 32-bit word.
X, Y, Z for the 32-bit integer.
F (X, Y, Z) = XY v not (X) Z
G (X, Y, Z) = XZ v Y not (Z)
H (X, Y, Z) = X xor Y xor Z
I (X, Y, Z) = Y xor (X v not (Z))
This step in the use of a 64-element array regular T [1 … 64], which constitute the sine function, T [i] that the first i array elements, and its equivalent value in the abs after 4294967296 (sin ( i)) after the value of the integer part (which i is the arc). T [i] for the 32-bit integers with 16 hexadecimal, and the array elements are given in the Appendix.
Specific process is as follows:
/ * Data processing text * /
For i = 0 to N/16-1 do
/ * Each time, the data stored in the original 16 elements in the array X * /
For j = 0 to 15 do
Set X to M [j] [i + j * 16].
End / J end of the cycle
/ * Save A as AA, B as BB, C as CC, and D as DD * /
AA = A
BB = B
CC = C
DD = D
/ * 1 * /
/ * [Abcd ksi] that the following operation
A = b + ((a + F (b, c, d) + X + T [k] [i]) <<<s) * /
/ * Do the following 16 operations * /
[ABCD 0 7 1] [DABC 1 12 2] [CDAB 2 17 3] [BCDA 3 22 4]
[ABCD 4 7 5] [DABC 5 12 6] [CDAB 6 17 7] [BCDA 7 22 8]
[ABCD 8 7 9] [DABC 9 12 10] [10 17 11 CDAB BCDA] [11 22 12]
[ABCD 12 7 13] [DABC 13 12 14] [14 17 15 CDAB BCDA] [15 22 16]
/ * 2 * * /
/ * [Abcd ksi] that the following operation
A = b + ((a + G (b, c, d) + X + T [k] [i]) <<<s) * /
/ * Do the following 16 operations * /
[ABCD 1 5 17] [DABC 6 9 18] [11 14 19 CDAB BCDA] [0 20 20]
[ABCD 5 5 21] [DABC 10 9 22] [15 14 23 CDAB BCDA] [4 20 24]
[ABCD 9 5 25] [DABC 14 9 26] [CDAB 3 14 27] [BCDA 8 20 28]
[ABCD 13 5 29] [DABC 2 9 30] [CDAB 7 14 31] [BCDA 12 20 32]
/ * 3 * /
/ * [Abcd ksi] that the following operation
A = b + ((a + H (b, c, d) + X + T [k] [i]) <<<s) * /
/ * Do the following 16 operations * /
[ABCD 5 4 33] [DABC 8 11 34] [11 16 35 CDAB BCDA] [14 23 36]
[ABCD 1 4 37] [DABC 4 11 38] [CDAB 7 16 39] [BCDA 10 23 40]
[ABCD 13 4 41] [DABC 0 11 42] [CDAB 3 16 43] [BCDA 6 23 44]
[ABCD 9 4 45] [DABC 12 11 46] [15 16 47 CDAB BCDA] [2 23 48]
/ * 4 * /
/ * [Abcd ksi] that the following operation
A = b + ((a + I (b, c, d) + X + T [k] [i]) <<<s) * /
/ * Do the following 16 operations * /
[ABCD 0 6 49] [DABC 7 10 50] [14 15 51 CDAB BCDA] [5 21 52]
[ABCD 12 6 53] [DABC 3 10 54] [10 15 55 CDAB BCDA] [1 21 56]
[ABCD 8 6 57] [DABC 15 10 58] [CDAB 6 15 59] [BCDA 13 21 60]
[ABCD 4 6 61] [11 10 62 DABC CDAB] [2 15 63] [BCDA 9 21 64]
/ * Then proceed as follows * /
A = A + AA
B = B + BB
C = C + CC
D = D + DD
End / * end of the cycle of I * /
(5) summary of output results reported after the formation of the form: A, B, C, D. A byte is low, the high end of D bytes.
MD5 now completed its description, are given in Appendix C in the form of the procedure.
Abstract 4
MD5 algorithm is easy, it provides information of arbitrary length of the "fingerprint" (otherwise known as summary report). Presumably to be achieved at two different text produced a summary of the same needs 2 ^ 64 operations to restore to the summary of the message requires 2 ^ 128 operation.
In order to find defects, MD5 algorithm has been a very detailed inspection. The conclusion was also relevant to the needs of a better algorithm and further safety analysis.
5 MD4 and MD5 Following is the difference between the MD4 and MD5 different points:
1. With the fourth round cycle.
2. Each step adds a constant value only.
In the second round from the function g (XY v XZ v YZ) into the (XZ v Y not (Z)), in order to reduce the balance of g function.
6 References
[1] Rivest, R., "The MD4 Message Digest Algorithm," RFC 1320, MIT and RSA Data Security,
Inc, April 1992.
[2] Rivest, R., "The MD4 message digest algorithm," in AJ Menezes and SA Vanstone,
Editors, Advances in Cryptology - CRYPTO'90Proceedings, pages 303-311, Springer-Verlag,
1991.
[3] CCITT Recommendation X.509 (1988), "The Directory - Authentication
Framework. "
Appendix A-7 reference application of the appendix includes the following documents: (from RSAREF: A Cryptographic Toolkit for Privacy-Enhanced Mail:)
Global.h - the first overall document
Md5.h - MD5 header files
Md5c.c - MD5 source code (RSAREF to get more information, please send an e-mai: <rsaref@rsa.com>.)
Appendix also includes:
Mddriver.c-MD2, MD4 and MD5 test driver.
Driver compiled MD5 default, but if the C compiler MD5 order parameters will be set to 2 or 4, you can also compile
MD2 and MD4
This application is easy to use, available in different platforms, in particular on the platform of optimization it is not difficult for the reader as this practice. For example, in the "little-endian" platform, the platform 32-character byte address the most meaningless minimum of bytes,
And there was no queue restrictions in the MD5 transform decoder can be called an order of the corresponding type of alternative.
A1 global.h
/ * GLOBAL.H - RSAREF type and constants * /
/ * If and only if compiler support function prototype statement, PROTOTYPES must be set if it is not a definition of the C compiler markings, the following code to PROTOTYPES home to 0. * /
# Ifndef PROTOTYPES
0 # define PROTOTYPES
# Endif
/ * POINTER defined as a general indicator of type * /
Typedef unsigned char * POINTER;
/ * UINT2 definition of the word into two bytes * /
Typedef unsigned short int UINT2;
/ * Set a UINT4 a four-byte characters * /
Typedef unsigned long int UINT4;
/ * PROTO_LIST dependent on the definition of the definition above PROTOTYPES, if used PROTOTYPES, then
PROTO_LIST return to this list, it returns an empty list. * /
# If PROTOTYPES
# Define PROTO_LIST (list) list
# Else
# Define PROTO_LIST (list) ()
# Endif
A.2 md5.h
/ * MD5.H - MD5C.C headers * /
/ * This software allows the reproduction or use, it must be in all the places mentioned and the reference mark "RSA Data Security, Inc. MD5
Message-Digest Algorithm, "also allows the creation or use of derivative software, it must be mentioned and reference in all areas marked" derived from the RSA Data Security, Inc. MD5 Message-Digest Algorithm "
RSA Data Security Inc. (RSA Data Security, Inc.) Has never for any particular purpose of this statement through the software can be bought and practicality, it provides "as is" without any express or implied reasons.
This declaration must be in any of this document and any copies of the software to retain. * /
/ * MD5 context * /
Typedef struct
(
UINT4 state [4]; / * state (ABCD) * /
UINT4 count [2]; / * bit number, mode 2 ^ 64 (the previous low) * /
Unsigned char buffer [64]; / * input buffer * /
MD5_CTX);
Void MD5Init PROTO_LIST ((MD5_CTX *));
Void MD5Update PROTO_LIST
((MD5_CTX *, unsigned char *, unsigned int));
Void MD5Final PROTO_LIST ((unsigned char [16], MD5_CTX *));
A.3 md5c.c
/ * MD5C.C - RSA data security company, reported MD5 digest algorithm * /
/ * This software allows the reproduction or use, it must be in all the places mentioned and the reference mark "RSA Data Security, Inc. MD5
Message-Digest Algorithm "will allow the creation or use of derivative software, it must be mentioned and reference in all areas marked" derived from the RSA Data RSA Data Security Inc. (RSA Data Security, Inc.) Has never for any particular purpose statement clearance of this software can be bought and practicality, it provides "as is" without any express or implied reasons.
This declaration must be in any of this document and any copies of the software to retain. * /
# Include "global.h"
# Include "md5.h"
/ * Constants for MD5Transform routine.
* /
# Define S11 7
# Define S12 12
# Define S13 17
# Define S14 22
5 # define S21
# Define S22 9
# Define S23 14
# Define S24 20
# Define S31 4
# Define S32 11
# Define S33 16
# Define S34 23
# Define S41 6
# Define S42 10
# Define S43 15
# Define S44 21
Static void MD5Transform PROTO_LIST ((UINT4 [4], [64] unsigned char));
Static void Encode PROTO_LIST
((Unsigned char *, UINT4 *, unsigned int));
Static void Decode PROTO_LIST
((UINT4 *, unsigned char *, unsigned int));
Static void MD5_memcpy PROTO_LIST ((POINTER, POINTER, unsigned int));
Static void MD5_memset PROTO_LIST ((POINTER, int, unsigned int));
Static unsigned char PADDING [64] = (
0×80, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0
);
/ * F, G, H and I is the basic MD5 function * /
# Define F (x, y, z) (((x) and (y)) | ((~ x) & (z)))
# Define G (x, y, z) (((x) & (z)) | ((y) & (~ z)))
# Define H (x, y, z) ((x) ^ (y) ^ (z))
# Define I (x, y, z) ((y) ^ ((x) | (~ z)))
/ * ROTATE_LEFT the left circle to x n-* /
# Define ROTATE_LEFT (x, n) (((x) <<(n)) | ((x)>> (32 - (n))))
/ * Cycle isolated from the additive is to prevent double counting * /
# Define FF (a, b, c, d, x, s, ac) (\
(A) = F + ((b), (c), (d)) + (x) + (UINT4) (ac); \
(A) = ROTATE_LEFT ((a), (s)); \
(A) + = (b); \
)
# Define GG (a, b, c, d, x, s, ac) (\
(A) + G = ((b), (c), (d)) + (x) + (UINT4) (ac); \
(A) = ROTATE_LEFT ((a), (s)); \
(A) + = (b); \
)
# Define HH (a, b, c, d, x, s, ac) (\
(A) + H = ((b), (c), (d)) + (x) + (UINT4) (ac); \
(A) = ROTATE_LEFT ((a), (s)); \
(A) + = (b); \
)
# Define II (a, b, c, d, x, s, ac) (\
(A) = I + ((b), (c), (d)) + (x) + (UINT4) (ac); \
(A) = ROTATE_LEFT ((a), (s)); \
(A) + = (b); \
)
/ * Initialize MD5. MD5 start a write operation of a new context * /
Void MD5Init (context)
MD5_CTX * context; / * context * /
(
Context-> [0] = count context-> count [1] = 0;
Context-> state [0] = 0×67452301;
Context-> state [1] = 0xefcdab89;
Context-> state [2] = 0×98badcfe;
Context-> state [3] = 0×10325476;
)
/ * Packet MD5 update operation. MD5 continue to operate a deal with another context and update information packet * /
Void MD5Update (context, the input, inputLen)
MD5_CTX * context; / * context * /
Unsigned char * input; / * Enter packet * /
Unsigned int inputLen; / * Enter the length of the packet * /
(
Unsigned int i, index, partLen;
/ * Bytes of the 64-value * /
Index = (unsigned int) ((context-> count [0]>> 3) & 0×3F);
/ * Update number of bits * /
If ((context-> [0] + count = ((UINT4) inputLen <<3))
<((UINT4) inputLen <<3))
Context-> count [1] + +;
Context-> count [1] + = ((UINT4) inputLen>> 29);
PartLen = 64 - index;
/ * Can be reached by the largest number of conversion * /
If (inputLen> = partLen) (
MD5_memcpy
((POINTER) & context-> buffer [index], (POINTER) input, partLen);
MD5Transform (context-> state, context-> buffer);
For (i = partLen; i + 63 <inputLen; i + = 64)
MD5Transform (context-> state, & input [i]);
Index = 0;
)
Else
I = 0;
/ * Buffer reservation entry * /
MD5_memcpy
((POINTER) & context-> buffer [index], (POINTER) & input [i]
InputLen-i);
)
/ * MD5 final result. MD5 reported in a summary of the end of operations, wrote to digest value * /
Void MD5Final (digest, context)
Unsigned char digest [16]; / * reported summary * /
MD5_CTX * context; / * context * /
(
Unsigned char bits [8];
Unsigned int index, padLen;
/ * Save-bit values * /
Encode (bits, context-> count, 8);
Index = (unsigned int) ((context-> count [0]>> 3) & 0×3f);
PadLen = (index <56) - (56 - index): (120 - index);
MD5Update (context, PADDING, padLen);
/ * Additional length (fill-in before) * /
MD5Update (context, bits, 8);
/ * Digest will be deposited in the state * /
Encode (digest, context-> state, 16);
MD5_memset ((POINTER) context, 0, sizeof (* context));
)
/ * MD5 basic conversion. State packet-based conversion * /
Static void MD5Transform (state, block)
UINT4 state [4];
Unsigned char block [64];
(
UINT4 a state [0] = b = state [1], c = state [2], d = state [3], x [16];
Decode (x, block, 64);
/ * Round 1 * /
FF (a, b, c, d, x [0], S11, 0xd76aa478) / * 1 * /
FF (d, a, b, c, x [1], S12, 0xe8c7b756) / * 2 * /
FF (c, d, a, b, x [2], S13, 0×242070db) / * 3 * /
FF (b, c, d, a, x [3], S14, 0xc1bdceee) / * 4 * /
FF (a, b, c, d, x [4], S11, 0xf57c0faf) / * 5 * /
FF (d, a, b, c, x [5], S12, 0×4787c62a) / * 6 * /
FF (c, d, a, b, x [6], S13, 0xa8304613) / * * /
FF (b, c, d, a, x [7], S14, 0xfd469501) / * 8 * /
FF (a, b, c, d, x [8], S11, 0×698098d8) / * 9 * /
FF (d, a, b, c, x [9], S12, 0×8b44f7af) / * 10 * /
FF (c, d, a, b, x [10], S13, 0xffff5bb1) / * 11 * /
FF (b, c, d, a, x [11], S14, 0×895cd7be) / * 12 * /
FF (a, b, c, d, x [12], S11, 0×6b901122) / * 13 * /
FF (d, a, b, c, x [13], S12, 0xfd987193) / * 14 * /
FF (c, d, a, b, x [14], S13, 0xa679438e) / * 15 * /
FF (b, c, d, a, x [15], S14, 0×49b40821) / * 16 * /
/ * Round 2 * /
GG (a, b, c, d, x [1], S21, 0xf61e2562) / * 17 * /
GG (d, a, b, c, x [6], S22, 0xc040b340) / * 18 * /
GG (c, d, a, b, x [11], S23, 0×265e5a51) / * 19 * /
GG (b, c, d, a, x [0], S24, 0xe9b6c7aa) / * 20 * /
GG (a, b, c, d, x [5], S21, 0xd62f105d) / * 21 * /
GG (d, a, b, c, x [10], S22, 0×2441453) / * 22 * /
GG (c, d, a, b, x [15], S23, 0xd8a1e681) / * 23 * /
GG (b, c, d, a, x [4], S24, 0xe7d3fbc8) / * 24 * /
GG (a, b, c, d, x [9], S21, 0×21e1cde6) / * 25 * /
GG (d, a, b, c, x [14], S22, 0xc33707d6) / * 26 * /
GG (c, d, a, b, x [3], S23, 0xf4d50d87) / * 27 * /
GG (b, c, d, a, x [8], S24, 0×455a14ed) / * 28 * /
GG (a, b, c, d, x [13], S21, 0xa9e3e905) / * 29 * /
GG (d, a, b, c, x [2], S22, 0xfcefa3f8) / * 30 * /
GG (c, d, a, b, x [7], S23, 0×676f02d9) / * 31 * /
GG (b, c, d, a, x [12], S24, 0×8d2a4c8a) / * 32 * /
/ * Round 3 * /
HH (a, b, c, d, x [5], S31, 0xfffa3942) / * 33 * /
HH (d, a, b, c, x [8], S32, 0×8771f681) / * 34 * /
HH (c, d, a, b, x [11], S33, 0×6d9d6122) / * 35 * /
HH (b, c, d, a, x [14], S34, 0xfde5380c) / * 36 * /
HH (a, b, c, d, x [1], S31, 0xa4beea44) / * 37 * /
HH (d, a, b, c, x [4], S32, 0×4bdecfa9) / * 38 * /
HH (c, d, a, b, x [7], S33, 0xf6bb4b60) / * 39 * /
HH (b, c, d, a, x [10], S34, 0xbebfbc70) / * 40 * /
HH (a, b, c, d, x [13], S31, 0×289b7ec6) / * 41 * /
HH (d, a, b, c, x [0], S32, 0xeaa127fa) / * 42 * /
HH (c, d, a, b, x [3], S33, 0xd4ef3085) / * 43 * /
HH (b, c, d, a, x [6], S34, 0×4881d05) / * 44 * /
HH (a, b, c, d, x [9], S31, 0xd9d4d039) / * 45 * /
HH (d, a, b, c, x [12], S32, 0xe6db99e5) / * 46 * /
HH (c, d, a, b, x [15], S33, 0×1fa27cf8) / * 47 * /
HH (b, c, d, a, x [2], S34, 0xc4ac5665) / * 48 * /
/ * Round 4 * /
II (a, b, c, d, x [0], S41, 0xf4292244) / * 49 * /
II (d, a, b, c, x [7], S42, 0×432aff97) / * 50 * /
II (c, d, a, b, x [14], S43, 0xab9423a7) / * 51 * /
II (b, c, d, a, x [5], S44, 0xfc93a039) / * 52 * /
II (a, b, c, d, x [12], S41, 0×655b59c3) / * 53 * /
II (d, a, b, c, x [3], S42, 0×8f0ccc92) / * 54 * /
II (c, d, a, b, x [10], S43, 0xffeff47d) / * 55 * /
II (b, c, d, a, x [1], S44, 0×85845dd1) / * 56 * /
II (a, b, c, d, x [8], S41, 0×6fa87e4f) / * 57 * /
II (d, a, b, c, x [15], S42, 0xfe2ce6e0) / * 58 * /
II (c, d, a, b, x [6], S43, 0xa3014314) / * 59 * /
II (b, c, d, a, x [13], S44, 0×4e0811a1) / * 60 * /
II (a, b, c, d, x [4], S41, 0xf7537e82) / * 61 * /
II (d, a, b, c, x [11], S42, 0xbd3af235) / * 62 * /
II (c, d, a, b, x [2], S43, 0×2ad7d2bb) / * 63 * /
II (b, c, d, a, x [9], S44, 0xeb86d391) / * 64 * /
State [0] = a +;
State [1] + = b;
State [2] + = c;
State [3] + = d;
MD5_memset ((POINTER) x, 0, sizeof (x));
)
/ * Input (UINT4) encoding output (unsigned char). Assumptions len is a multiple of 4 * /
Static void Encode (output, input, len)
Unsigned char * output;
UINT4 * input;
Unsigned int len;
(
Unsigned int i, j;
For (i = 0, j = 0, j <len; i + +, j + = 4) (
Output [j] = (unsigned char) (input [i] & 0xff);
Output [j +1] = (unsigned char) ((input [i]>>
& 0xff);
Output [j +2] = (unsigned char) ((input [i]>> 16) & 0xff);
Output [j +3] = (unsigned char) ((input [i]>> 24) & 0xff);
)
)
/ * Input (unsigned char) decoder output (UINT4). Assumptions len is a multiple of 4 * /
Static void Decode (output, input, len)
UINT4 * output;
Unsigned char * input;
Unsigned int len;
(
Unsigned int i, j;
For (i = 0, j = 0, j <len; i + +, j + = 4)
Output [i] = ((UINT4) input [j]) | (((UINT4) input [j +1]) <<8) |
(((UINT4) input [j +2]) <<16) | (((UINT4) input [j +3]) <<24);
)
Static void MD5_memcpy (output, input, len)
POINTER output;
POINTER input;
Unsigned int len;
(
Unsigned int i;
For (i = 0; i <len; i + +)
Output [i] [i] = input;
)
Static void MD5_memset (output, value, len)
POINTER output;
Int value;
Unsigned int len;
(
Unsigned int i;
For (i = 0; i <len; i + +)
((Char *) output) [i] = (char) value;
)
A.4 mddriver.c
/ * MDDRIVER.C - MD2, MD4 and MD5 test procedure * /
/ * Data security company RSA (RSA Data Security, Inc.) Has never for any particular purpose of this statement through the software can be bought and practicality, it provides "as is" without any express or implied reasons.
This declaration must be in any of this document and any copies of the software to retain. * /
/ * If there is no definition of the value of signs C compiler, the default state of MD5 for MD5 * /
# Ifndef MD
# Define MD MD5
# Endif
# Include
# Include
# Include
# Include "global.h"
# If MD == 2
# Include "md2.h"
# Endif
# If MD == 4
# Include "md4.h"
# Endif
== 5 # if MD
# Include "md5.h"
# Endif
/ * Packet length and the number of test * /
# Define TEST_BLOCK_LEN 1000
# Define TEST_BLOCK_COUNT 1000
Static void MDString PROTO_LIST ((char *));
Static void MDTimeTrial PROTO_LIST ((void));
Static void MDTestSuite PROTO_LIST ((void));
Static void MDFile PROTO_LIST ((char *));
Static void MDFilter PROTO_LIST ((void));
Static void MDPrint PROTO_LIST ((unsigned char [16]));
# If MD == 2
# Define MD_CTX MD2_CTX
# Define MDInit MD2Init
# Define MDUpdate MD2Update
# Define MDFinal MD2Final
# Endif
# If MD == 4
# Define MD_CTX MD4_CTX
# Define MDInit MD4Init
# Define MDUpdate MD4Update
# Define MDFinal MD4Final
# Endif
== 5 # if MD
# Define MD_CTX MD5_CTX
# Define MDInit MD5Init
# Define MDUpdate MD5Update
# Define MDFinal MD5Final
# Endif
/ * Main program.
Variables:
- Sstring - Abstract string
- T - run-time test
- X - running test scripts
Filename - Summary
(None) - Abstract standard input
* /
Int main (argc, argv)
Int argc;
Char * argv [];
(
Int i;
If (argc> 1)
For (i = 1; i <argc; i + +)
If (argv [i] [0] == '-' & argv [i] [1] == 's')
MDString (argv [i] + 2);
Else if (strcmp (argv [i], "-t") == 0)
MDTimeTrial ();
Else if (strcmp (argv [i], "-x") == 0)
MDTestSuite ();
Else
MDFile (argv [i]);
Else
MDFilter ();
Return (0);
)
/ * Calculate and print a summary of the string values * /
Static void MDString (string)
Char * string;
(
MD_CTX context;
Unsigned char digest [16];
Unsigned int len = strlen (string);
MDInit (& context);
MDUpdate (& context, string, len);
MDFinal (digest, & context);
Printf ( "% d MD (\"% s \ ") =", MD, string);
MDPrint (digest);
Printf ( "\ n");
)
/ * Test calculation TEST_BLOCK_COUNT TEST_BLOCK_LEN-byte
Summary of the packet * /
Static void MDTimeTrial ()
(
MD_CTX context;
Time_t endTime, startTime;
Unsigned char block [TEST_BLOCK_LEN], digest [16];
Unsigned int i;
Printf
( "MD% d time trial. Digesting% d% d-byte blocks …", MD,
TEST_BLOCK_LEN, TEST_BLOCK_COUNT);
/ * Initialize packet * /
For (i = 0; i <TEST_BLOCK_LEN; i + +)
Block [i] = (unsigned char) (i & 0xff);
/ * Start * Clock /
Time (& startTime);
/ * Abstract packet * /
MDInit (& context);
For (i = 0; i <TEST_BLOCK_COUNT; i + +)
MDUpdate (& context, block, TEST_BLOCK_LEN);
MDFinal (digest, & context);
/ * Stop the clock * /
Time (& endTime);
Printf ( "done \ n");
Printf ( "Digest =");
MDPrint (digest);
Printf ( "\ nTime =% ld seconds \ n", (long) (endTime-startTime));
Printf
( "Speed =% ld bytes / second \ n",
(Long) TEST_BLOCK_LEN * (long) TEST_BLOCK_COUNT / (endTime-startTime));
)
/ * String components of a reference and print a summary of results * /
Static void MDTestSuite ()
(
Printf ( "% d test suite MD: \ n", MD);
MDString ("");
MDString ( "a");
MDString ( "abc");
MDString ( "message digest");
MDString ( "abcdefghijklmnopqrstuvwxyz");
MDString
( "ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789");
MDString
( "1234567890123456789012345678901234567890 \
1234567890123456789012345678901234567890 ");
)
/ * A summary of a document and print the results * /
Static void MDFile (filename)
Char * filename;
(
FILE * file;
MD_CTX context;
Int len;
Unsigned char buffer [1024], digest [16];
If ((file = fopen (filename, "rb")) == NULL)
Printf ( "% s can't be opened \ n", filename);
Else (
MDInit (& context);
While (len = fread (buffer, 1, 1024, file))
MDUpdate (& context, buffer, len);
MDFinal (digest, & context);
Fclose (file);
Printf ( "MD% d (% s) =", MD, filename);
MDPrint (digest);
Printf ( "\ n");
)
)
/ * Calculate standard input and print a summary of results * /
Static void MDFilter ()
(
MD_CTX context;
Int len;
Unsigned char buffer [16], [16] digest;
MDInit (& context);
While (len = fread (buffer, 1, 16, stdin))
MDUpdate (& context, buffer, len);
MDFinal (digest, & context);
MDPrint (digest);
Printf ( "\ n");
)
/ * Print a summary of a 16-band * /
Static void MDPrint (digest)
Unsigned char digest [16];
(
Unsigned int i;
For (i = 0; i <16; i + +)
Printf ( "% 02x" digest [i]);
)
A.5 test components
MD5 test components (Driver option "- x") should print the following values:
MD5 test suite:
MD5 ( "") = d41d8cd98f00b204e9800998ecf8427e
MD5 ( "a") = 0cc175b9c0f1b6a831c399e269772661
MD5 ( "abc") = 900150983cd24fb0d6963f7d28e17f72
MD5 ( "message digest") = f96b697d7cb7938d525a2f31aaf161d0
MD5 ( "abcdefghijklmnopqrstuvwxyz") = c3fcd3d76192e4007dfb496cca67e13b
MD5 ( "ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789") =
D174ab98d277d9f5a5611c2c9f419d9f
MD5 ( "123456789012345678901234567890123456789012345678901234567890123456
78901234567890 ") = 57edf4a22be3c955ac49da2e2107b67a
8 security matters discussed in this paper, the safety standards are considered high enough to achieve the requirements of public key-based system and digital signature algorithm MD5 system.
9 The author addresses
Ronald L. Rivest
Massachusetts Institute of Technology
Laboratory for Computer Science
NE43-324
545 Technology Square
Cambridge, MA 02139-1986
Phone: (617) 253-5880
EMail: rivest@theory.lcs.mit.edu
RFC1321 - The MD5 Message-Digest Algorithm MD5 algorithm to digest
2
RFC documents Chinese Translation Project








0 Comments to “RFC1312 Chinese version”
No Comments. Send your comment.
Leave a Reply
You must be logged in to post a comment.