* / 无效MD5Final(摘要,ctx) unsigned char digest [16]; struct MD5Context * ctx; { 无符号数; unsigned char * p; / *计算字节数mod 64 * / count =(ctx-> bits [0]>> 3)& 0x3F; / *将填充的第一个字符设置为0x80。这是安全的,因为 总是至少有一个字节免费* / p = ctx-> in + count; * p ++ = 0x80; / *填充字节需要64字节* / count = 64 - 1 - count; / *填充56 mod 64 * / if(count< 8){ / *两个填充:填充第一个块到64字节* / memset(p,0,count); byteReverse(ctx-> in,16); MD5Transform( ctx-> buf,(uint32 *)ctx-> in); / *现在用56字节填充下一个块* / memset (ctx-> in,0,56); } else { / * Pad块到56个字节* / memset( p,0,count - 8); } byteReverse(ctx-> in,14); / *以位为单位追加长度并转换* / ((uint32 *)ctx-> in)[14] = ctx-> bits [0]; ( (uint32 *)ctx-> in)[15] = ctx-> bits [1]; MD5Transform(ctx-> buf,(uint32 *)ctx-> ;在); byteReverse((unsigned char *)ctx-> buf,4); memcpy(digest,ctx-> buf,16); memset(ctx,0,sizeof(ctx)); / *如果它很敏感* / } / *四个核心功能 - F1有所优化* / / * #define F1(x,y,z)(x& y | ~x& z)* / #define F1(x,y,z)(z ^ (x&(y ^ z))) #define F2(x,y,z)F1(z,x,y) #define F3(x ,y,z)(x ^ y ^ z) #define F4(x,y,z)(y ^(x | ~z)) / *这是MD5算法的核心步骤。 * / #define MD5STEP(f,w,x,y,z,data,s)\ (w + = f(x,y,z) +数据,w = w<< s | w>>(32-s),w + = x) / * * MD5算法的核心,它将现有的MD5哈希值改为 *,反映了新数据的16个长字的增加。 MD5Update阻止 *数据并将字节转换为此例程的长字。 * / 无效MD5Transform(buf,in) uint32 buf [4]; uint32 in [16]; { 注册uint32 a,b,c,d; a = buf [0] ; b = buf [1]; c = buf [2]; d = buf [3]; MD5STEP(F1,a,b,c,d,在[0] + 0xd76aa478,7); MD5STEP(F1,d,a,b,c,在[1 ] + 0xe8c7b756,12); MD5STEP(F1,c,d,a,b,在[2] + 0x242070db,17); MD5STEP(F1,b ,c,d,a,in [3] + 0xc1bdceee,22); MD5STEP(F1,a,b,c,d,in [4] + 0xf57c0faf,7); MD5STEP(F1,d,a,b,c,[5] + 0x4787c62a,12); MD5STEP(F1,c,d,a,b,in [6 ] + 0xa8304613,17); MD5STEP(F1,b,c,d,a,在[7] + 0xfd469501,22); MD5STEP(F1,a ,b,c,d,在[8] + 0x698098d8,7); MD5STEP(F1,d,a,b,c,在[9] + 0x8b44f7af,12); MD5STEP(F1,c,d,a,b,[10] + 0xffff5bb1,17); MD5STEP(F1,b,c,d,a,in [11 ] + 0x895cd7be,22); MD5STEP(F1,a,b,c,d,[12] + 0x6b901122,7); MD5STEP(F1,d ,a,b,c,在[13] + 0xfd中987193,12); MD5STEP(F1,c,d,a,b,在[14] + 0xa679438e,17); MD5STEP(F1,b,c ,d,a,in [15] + 0x49b40821,22); MD5STEP(F2,a,b,c,d,in [1] + 0xf61e2562,5); MD5STEP(F2,d,a,b,c,[6] + 0xc040b340,9); MD5STEP(F2,c,d,a,b,in [11] + 0x265e5a51,14); MD5STEP(F2,b,c,d,a,在[0] + 0xe9b6c7aa,20); MD5STEP(F2 ,a,b,c,d,在[5] + 0xd62f105d,5); MD5STEP(F2,d,a,b,c,在[10] + 0x02441453,9); MD5STEP(F2,c,d,a,b,在[15] + 0xd8a1e681,14); MD5STEP(F2,b,c,d,a,in [4] + 0xe7d3fbc8,20); MD5STEP(F2,a,b,c,d,[9] + 0x21e1cde6,5); MD5STEP(F2 ,d,a,b,c,in [14] + 0xc33707d6,9); MD5STEP(F2,c,d,a,b,in [3] + 0xf4d50d87,14); MD5STEP(F2,b,c,d,a,[8] + 0x455a14ed,20); MD5STEP(F2,a,b,c,d,in [13] + 0xa9e3e905,5); MD5STEP(F2,d,a,b,c,[2] + 0xfcefa3f8,9); MD5STEP(F2 ,c,d,a,b,in [7] + 0x676f02d9,14); MD5STEP(F2,b,c,d,a,in [12] + 0x8d2a4c8a,20); MD5STEP(F3,a,b,c,d,[5] + 0xfffa3942,4); MD5STEP(F3,d,a,b ,c,在[8] + 0x8771f681,11); MD5STEP(F3,c,d,a,b,在[11] + 0x6d9d6122,16); MD5STEP(F3,b,c,d,a,在[14] + 0xfde5380c,23); MD5STEP(F3,a,b,c,d,在[1] + 0xa4beea44中, 4); MD5STEP(F3,d,a,b,c,在[4] + 0x4bdecfa9,11); MD5STEP(F3,c,d,a ,b,在[7] + 0xf6bb4b60,16); MD5STEP(F3,b,c,d,a,在[10] + 0xbebfbc70,23); MD5STEP(F3,a,b,c,d,在[13] + 0x289b7ec6,4中); MD5STEP(F3,d,a,b,c,在[0] + 0xeaa127fa中, 11); MD5STEP(F3,c,d,a,b,在[3] + 0xd4ef3085,16); MD5STEP(F3,b,c,d ,a,in [6] + 0x04881d05,23); MD5STEP(F3,a,b,c,d,in [9] + 0xd9d4d039,4); MD5STEP(F3,d,a,b,c,在[12] + 0xe6db99e5,11); MD5STEP(F3,c,d,a,b,在[15] + 0x1fa27c f8,16); MD5STEP(F3,b,c,d,a,in [2] + 0xc4ac5665,23); MD5STEP(F4 ,a,b,c,d,在[0] + 0xf4292244,6); MD5STEP(F4,d,a,b,c,在[7] + 0x432aff97,10); MD5STEP(F4,c,d,a,b,在[14] + 0xab9423a7,15); MD5STEP(F4,b,c,d,a,in [5] + 0xfc93a039,21); MD5STEP(F4,a,b,c,d,在[12] + 0x655b59c3,6); MD5STEP(F4 ,d,a,b,c,in [3] + 0x8f0ccc92,10); MD5STEP(F4,c,d,a,b,in [10] + 0xffeff47d,15); MD5STEP(F4,b,c,d,a,在[1] + 0x85845dd1,21); MD5STEP(F4,a,b,c,d,in [8] + 0x6fa87e4f,6); MD5STEP(F4,d,a,b,c,在[15] + 0xfe2ce6e0,10); MD5STEP(F4 ,c,d,a,b,in [6] + 0xa3014314,15); MD5STEP(F4,b,c,d,a,in [13] + 0x4e0811a1,21); MD5STEP(F4,a,b,c,d,在[4] + 0xf7537e82,6); MD5STEP(F4,d,a,b,c,in [11] + 0xbd3af235,10); MD5STEP(F4,c,d,a,b,在[2] + 0x2ad7d2bb,15); MD5STEP(F4 , b,c,d,a,in [9] + 0xeb86d391,21); buf [0] + = a; buf [1] + = b; buf [2] + = c; buf [3] + = d; } #ifndef MD5_H #define MD5_H / *以下测试优化little-endian 机器的行为,在MD5计算中不需要反转字节顺序 的32位字。默认情况下, HIGHFIRST被定义,这表明我们正在运行 big-endian(最重要的字节优先)机器,其上 必须调用md5.c中的byteReverse函数。但是, byteReverse的编码方式是在小端机器上运行时它是一个身份 函数,所以调用它 在这样的平台上除了浪费时间之外没有任何伤害。 如果知道该平台是小端的,我们通过取消定义HIGHFIRST来加速 定义 byteReverse为空宏。以这种方式做事 确保我们在新平台上工作,无论他们的字节是什么订单。 * / #define HIGHFIRST #ifdef __i386__ #undef HIGHFIRST #endif / *在长的机器上是64位,我们需要声明 uint32作为保证为32位的东西。 * / #ifdef __alpha typedef unsigned int uint32; #else typedef unsigned long uint32; #endif struct MD5Context { uint32 buf [4]; uint32位[2]; [64]中的unsigned char; }; extern void MD5Init(); extern void MD5Update(); extern void MD5Final(); extern void MD5Transform(); / * *这需要在一些MS-DOS编译器上使RSAREF满意。 * / typedef struct MD5Context MD5_CTX ; / *定义CHECK_HARDWARE_PROPERTIES以获得main,c验证 字节顺序和uint32设置。 * / #define CHECK_HARDWARE_PROPERTIES #endif / *!MD5_H * / - Dave K http:// www。 southminster-branch-line.org.uk/ 请注意我的电子邮件地址会定期更改,以避免垃圾邮件。 它始终是form:month-year @ domain。点击回复只会工作几个月才能获得。稍后手动设置。月份是 总是用3个字母书写(例如Jan,而不是1月等)I wanted md5 myself yesterday and found it on the web. Can''t recallwhere, but here is the code below. There are 3 files - I leave it as anexcercise for you to find out where main.c ends and md5.c starts andwhere md5.c ends and md5.h starts!!sparrow /export/home/drkirkby % cat main.c md5.c md5.h/*Calculate or Check MD5 Signature of File or Command Line Argumentby John Walker http://www.fourmilab.ch/This program is in the public domain.*/#define VERSION "2.1 (2003-09-23)"#include <stdio.h>#include <ctype.h>#include <string.h>#ifdef _WIN32#include <fcntl.h>#include <io.h>#endif#include "md5.h"#define FALSE 0#define TRUE 1#define EOS ''\0''/* Main program */int main(argc, argv)int argc; char *argv[];{int i, j, opt, cdata = FALSE, docheck = FALSE, showfile = TRUE, f = 0;unsigned int bp;char *cp, *clabel, *ifname, *hexfmt = "%02X";FILE *in = stdin, *out = stdout;unsigned char buffer[16384], signature[16], csig[16];struct MD5Context md5c;/* Build parameter quality control. Verify machineproperties were properly set in md5.h and refuseto run if they''re not correct. */#ifdef CHECK_HARDWARE_PROPERTIES/* Verify unit32 is, in fact, a 32 bit data type. */if (sizeof(uint32) != 4) {fprintf(stderr, "** Configuration error. Setting for uint32 infile md5.h\n");fprintf(stderr, " is incorrect. This must be a 32 bit datatype, but it\n");fprintf(stderr, " is configured as a %d bit data type.\n",sizeof(uint32) * 8);return 2;}/* If HIGHFIRST is not defined, verify that this machine is,in fact, a little-endian architecture. */#ifndef HIGHFIRST{ uint32 t = 0x12345678;if (*((char *) &t) != 0x78) {fprintf(stderr, "** Configuration error. Setting forHIGHFIRST in file md5.h\n");fprintf(stderr, " is incorrect. This symbol has not beendefined, yet this\n");fprintf(stderr, " machine is a big-endian (mostsignificant byte first in\n");fprintf(stderr, " memory) architecture. Please modifymd5.h so HIGHFIRST is\n");fprintf(stderr, " defined when building for thismachine.\n");return 2;}}#endif#endif/* Process command line options. */for (i = 1; i < argc; i++) {cp = argv[i];if (*cp == ''-'') {if (strlen(cp) == 1) {i++;break; /* - -- Mark end of options;balance are files */}opt = *(++cp);if (islower(opt)) {opt = toupper(opt);}switch (opt) {case ''C'': /* -Csignature -- Checksignature, set return code */docheck = TRUE;if (strlen(cp + 1) != 32) {docheck = FALSE;}memset(csig, 0, 16);clabel = cp + 1;for (j = 0; j < 16; j++) {if (isxdigit((int) clabel[0]) && isxdigit((int)clabel[1]) &&sscanf((cp + 1 + (j * 2)), hexfmt, &bp) == 1) {csig[j] = (unsigned char) bp;} else {docheck = FALSE;break;}clabel += 2;}if (!docheck) {fprintf(stderr, "Error in signaturespecification. Must be 32 hex digits.\n");return 2;}break;case ''D'': /* -Dtext -- Compute signatureof given text */MD5Init(&md5c);MD5Update(&md5c, (unsigned char *) (cp + 1),strlen(cp + 1));cdata = TRUE;f++; /* Mark no infile argument needed */break;case ''L'': /* -L -- Use lower case lettersas hex digits */hexfmt = "%02x";break;case ''N'': /* -N -- Don''t show file nameafter sum */showfile = FALSE;break;case ''O'': /* -Ofname -- Write output tofname (- = stdout) */cp++;if (strcmp(cp, "-") != 0) {if (out != stdout) {fprintf(stderr, "Redundant output filespecification.\n");return 2;}if ((out = fopen(cp, "w")) == NULL) {fprintf(stderr, "Cannot open output file%s\n", cp); return 2;}}break;case ''?'': /* -U, -? -H -- Print how tocall information. */case ''H'':case ''U'':printf("\nMD5 -- Calculate MD5 signature of file. Call");printf("\n with md5 [ options ] [file ...]");printf("\n");printf("\n Options:");printf("\n -csig Check against sig, set exit status0 = OK"); printf("\n -dtext Compute signature of textargument");printf("\n -l Use lower case letters forhexadecimal digits");printf("\n -n Do not show file name after sum");printf("\n -ofname Write output to fname (- = stdout)");printf("\n -u Print this message");printf("\n -v Print version information");printf("\n");printf("\nby John Walker -- http://www.fourmilab.ch/");printf("\nVersion %s\n", VERSION);printf("\nThis program is in the public domain.\n");printf("\n");#ifdef CHECK_HARDWARE_PROPERTIES#ifdef HIGHFIRST{ uint32 t = 0x12345678;if (*((char *) &t) == 0x78) {fprintf(stderr, "** Note. md5 is not optimally configuredfor use on this\n");fprintf(stderr, " machine. This is a little-endian(least significant byte\n");fprintf(stderr, " first in memory) architecture, yet md5has been built with the\n");fprintf(stderr, " symbol HIGHFIRST defined in md5.h,which includes code which\n");fprintf(stderr, " supports both big- and little-endianmachines. Modifying\n");fprintf(stderr, " md5.h to undefine HIGHFIRST for thisplatform will make md5\n");fprintf(stderr, " run faster on it.\n");}}#endif#endifreturn 0;case ''V'': /* -V -- Print version number */printf("%s\n", VERSION);return 0;}} else {break;}}if (cdata && (i < argc)) {fprintf(stderr, "Cannot specify both -d option and input file.\n");return 2;}if ((i >= argc) && (f == 0)) {f++;}for (; (f > 0) || (i < argc); i++) {if ((!cdata) && (f > 0)) {ifname = "-";} else {ifname = argv[i];}f = 0;if (!cdata) {/* If the data weren''t supplied on the command line withthe "-d" option, read it now from the input file. */if (strcmp(ifname, "-") != 0) {if ((in = fopen(ifname, "rb")) == NULL) {fprintf(stderr, "Cannot open input file %s\n", ifname);return 2;}} else {in = stdin;}#ifdef _WIN32/** Warning! On systems which distinguish text mode andbinary I/O (MS-DOS, Macintosh, etc.) the modes in the openstatement for "in" should have forced the input file intobinary mode. But what if we''re reading from standardinput? Well, then we need to do a system-specific tweakto make sure it''s in binary mode. While we''re at it,let''s set the mode to binary regardless of however fopenset it.The following code, conditional on _WIN32, sets binarymode using the method prescribed by Microsoft Visual C 7.0("Monkey C"); this may require modification if you''reusing a different compiler or release of Monkey C. Ifyou''re porting this code to a different system whichdistinguishes text and binary files, you''ll need to addthe equivalent call for that system. */_setmode(_fileno(in), _O_BINARY);#endifMD5Init(&md5c);while ((j = (int) fread(buffer, 1, sizeof buffer, in)) > 0) {MD5Update(&md5c, buffer, (unsigned) j);}}MD5Final(signature, &md5c);if (docheck) {docheck = 0;for (j = 0; j < sizeof signature; j++) {if (signature[j] != csig[j]) {docheck = 1;break;}}if (i < (argc - 1)) {fprintf(stderr, "Only one file may be tested with the-c option.\n");return 2;}} else {for (j = 0; j < sizeof signature; j++) {fprintf(out, hexfmt, signature[j]);}if ((!cdata) && showfile) {fprintf(out, " %s", (in == stdin) ? "-" : ifname);}fprintf(out, "\n");}}return docheck;}/** This code implements the MD5 message-digest algorithm.* The algorithm is due to Ron Rivest. This code was* written by Colin Plumb in 1993, no copyright is claimed.* This code is in the public domain; do with it what you wish.** Equivalent code is available from RSA Data Security, Inc.* This code has been tested against that, and is equivalent,* except that you don''t need to include two pages of legalese* with every copy.** To compute the message digest of a chunk of bytes, declare an* MD5Context structure, pass it to MD5Init, call MD5Update as* needed on buffers full of bytes, and then call MD5Final, which* will fill a supplied 16-byte array with the digest.*//* Brutally hacked by John Walker back from ANSI C to K&R (noprototypes) to maintain the tradition that Netfone will compilewith Sun''s original "cc". */#include <memory.h> /* for memcpy() */#include "md5.h"#ifndef HIGHFIRST#define byteReverse(buf, len) /* Nothing */#else/** Note: this code is harmless on little-endian machines.*/void byteReverse(buf, longs)unsigned char *buf; unsigned longs;{uint32 t;do {t = (uint32) ((unsigned) buf[3] << 8 | buf[2]) << 16 |((unsigned) buf[1] << 8 | buf[0]);*(uint32 *) buf = t;buf += 4;} while (--longs);}#endif/** Start MD5 accumulation. Set bit count to 0 and buffer to mysterious* initialization constants.*/void MD5Init(ctx)struct MD5Context *ctx;{ctx->buf[0] = 0x67452301;ctx->buf[1] = 0xefcdab89;ctx->buf[2] = 0x98badcfe;ctx->buf[3] = 0x10325476;ctx->bits[0] = 0;ctx->bits[1] = 0;}/** Update context to reflect the concatenation of another buffer full* of bytes.*/void MD5Update(ctx, buf, len)struct MD5Context *ctx; unsigned char *buf; unsigned len;{uint32 t;/* Update bitcount */t = ctx->bits[0];if ((ctx->bits[0] = t + ((uint32) len << 3)) < t)ctx->bits[1]++; /* Carry from low to high */ctx->bits[1] += len >> 29;t = (t >> 3) & 0x3f; /* Bytes already in shsInfo->data *//* Handle any leading odd-sized chunks */if (t) {unsigned char *p = (unsigned char *) ctx->in + t;t = 64 - t;if (len < t) {memcpy(p, buf, len);return;}memcpy(p, buf, t);byteReverse(ctx->in, 16);MD5Transform(ctx->buf, (uint32 *) ctx->in);buf += t;len -= t;}/* Process data in 64-byte chunks */while (len >= 64) {memcpy(ctx->in, buf, 64);byteReverse(ctx->in, 16);MD5Transform(ctx->buf, (uint32 *) ctx->in);buf += 64;len -= 64;}/* Handle any remaining bytes of data. */memcpy(ctx->in, buf, len);}/** Final wrapup - pad to 64-byte boundary with the bit pattern* 1 0* (64-bit count of bits processed, MSB-first)*/void MD5Final(digest, ctx)unsigned char digest[16]; struct MD5Context *ctx;{unsigned count;unsigned char *p;/* Compute number of bytes mod 64 */count = (ctx->bits[0] >> 3) & 0x3F;/* Set the first char of padding to 0x80. This is safe since there isalways at least one byte free */p = ctx->in + count;*p++ = 0x80;/* Bytes of padding needed to make 64 bytes */count = 64 - 1 - count;/* Pad out to 56 mod 64 */if (count < 8) {/* Two lots of padding: Pad the first block to 64 bytes */memset(p, 0, count);byteReverse(ctx->in, 16);MD5Transform(ctx->buf, (uint32 *) ctx->in);/* Now fill the next block with 56 bytes */memset(ctx->in, 0, 56);} else {/* Pad block to 56 bytes */memset(p, 0, count - 8);}byteReverse(ctx->in, 14);/* Append length in bits and transform */((uint32 *) ctx->in)[14] = ctx->bits[0];((uint32 *) ctx->in)[15] = ctx->bits[1];MD5Transform(ctx->buf, (uint32 *) ctx->in);byteReverse((unsigned char *) ctx->buf, 4);memcpy(digest, ctx->buf, 16);memset(ctx, 0, sizeof(ctx)); /* In case it''s sensitive */}/* The four core functions - F1 is optimized somewhat *//* #define F1(x, y, z) (x & y | ~x & z) */#define F1(x, y, z) (z ^ (x & (y ^ z)))#define F2(x, y, z) F1(z, x, y)#define F3(x, y, z) (x ^ y ^ z)#define F4(x, y, z) (y ^ (x | ~z))/* This is the central step in the MD5 algorithm. */#define MD5STEP(f, w, x, y, z, data, s) \( w += f(x, y, z) + data, w = w<<s | w>>(32-s), w += x )/** The core of the MD5 algorithm, this alters an existing MD5 hash to* reflect the addition of 16 longwords of new data. MD5Update blocks* the data and converts bytes into longwords for this routine.*/void MD5Transform(buf, in)uint32 buf[4]; uint32 in[16];{register uint32 a, b, c, d;a = buf[0];b = buf[1];c = buf[2];d = buf[3];MD5STEP(F1, a, b, c, d, in[0] + 0xd76aa478, 7);MD5STEP(F1, d, a, b, c, in[1] + 0xe8c7b756, 12);MD5STEP(F1, c, d, a, b, in[2] + 0x242070db, 17);MD5STEP(F1, b, c, d, a, in[3] + 0xc1bdceee, 22);MD5STEP(F1, a, b, c, d, in[4] + 0xf57c0faf, 7);MD5STEP(F1, d, a, b, c, in[5] + 0x4787c62a, 12);MD5STEP(F1, c, d, a, b, in[6] + 0xa8304613, 17);MD5STEP(F1, b, c, d, a, in[7] + 0xfd469501, 22);MD5STEP(F1, a, b, c, d, in[8] + 0x698098d8, 7);MD5STEP(F1, d, a, b, c, in[9] + 0x8b44f7af, 12);MD5STEP(F1, c, d, a, b, in[10] + 0xffff5bb1, 17);MD5STEP(F1, b, c, d, a, in[11] + 0x895cd7be, 22);MD5STEP(F1, a, b, c, d, in[12] + 0x6b901122, 7);MD5STEP(F1, d, a, b, c, in[13] + 0xfd987193, 12);MD5STEP(F1, c, d, a, b, in[14] + 0xa679438e, 17);MD5STEP(F1, b, c, d, a, in[15] + 0x49b40821, 22);MD5STEP(F2, a, b, c, d, in[1] + 0xf61e2562, 5);MD5STEP(F2, d, a, b, c, in[6] + 0xc040b340, 9);MD5STEP(F2, c, d, a, b, in[11] + 0x265e5a51, 14);MD5STEP(F2, b, c, d, a, in[0] + 0xe9b6c7aa, 20);MD5STEP(F2, a, b, c, d, in[5] + 0xd62f105d, 5);MD5STEP(F2, d, a, b, c, in[10] + 0x02441453, 9);MD5STEP(F2, c, d, a, b, in[15] + 0xd8a1e681, 14);MD5STEP(F2, b, c, d, a, in[4] + 0xe7d3fbc8, 20);MD5STEP(F2, a, b, c, d, in[9] + 0x21e1cde6, 5);MD5STEP(F2, d, a, b, c, in[14] + 0xc33707d6, 9);MD5STEP(F2, c, d, a, b, in[3] + 0xf4d50d87, 14);MD5STEP(F2, b, c, d, a, in[8] + 0x455a14ed, 20);MD5STEP(F2, a, b, c, d, in[13] + 0xa9e3e905, 5);MD5STEP(F2, d, a, b, c, in[2] + 0xfcefa3f8, 9);MD5STEP(F2, c, d, a, b, in[7] + 0x676f02d9, 14);MD5STEP(F2, b, c, d, a, in[12] + 0x8d2a4c8a, 20);MD5STEP(F3, a, b, c, d, in[5] + 0xfffa3942, 4);MD5STEP(F3, d, a, b, c, in[8] + 0x8771f681, 11);MD5STEP(F3, c, d, a, b, in[11] + 0x6d9d6122, 16);MD5STEP(F3, b, c, d, a, in[14] + 0xfde5380c, 23);MD5STEP(F3, a, b, c, d, in[1] + 0xa4beea44, 4);MD5STEP(F3, d, a, b, c, in[4] + 0x4bdecfa9, 11);MD5STEP(F3, c, d, a, b, in[7] + 0xf6bb4b60, 16);MD5STEP(F3, b, c, d, a, in[10] + 0xbebfbc70, 23);MD5STEP(F3, a, b, c, d, in[13] + 0x289b7ec6, 4);MD5STEP(F3, d, a, b, c, in[0] + 0xeaa127fa, 11);MD5STEP(F3, c, d, a, b, in[3] + 0xd4ef3085, 16);MD5STEP(F3, b, c, d, a, in[6] + 0x04881d05, 23);MD5STEP(F3, a, b, c, d, in[9] + 0xd9d4d039, 4);MD5STEP(F3, d, a, b, c, in[12] + 0xe6db99e5, 11);MD5STEP(F3, c, d, a, b, in[15] + 0x1fa27cf8, 16);MD5STEP(F3, b, c, d, a, in[2] + 0xc4ac5665, 23);MD5STEP(F4, a, b, c, d, in[0] + 0xf4292244, 6);MD5STEP(F4, d, a, b, c, in[7] + 0x432aff97, 10);MD5STEP(F4, c, d, a, b, in[14] + 0xab9423a7, 15);MD5STEP(F4, b, c, d, a, in[5] + 0xfc93a039, 21);MD5STEP(F4, a, b, c, d, in[12] + 0x655b59c3, 6);MD5STEP(F4, d, a, b, c, in[3] + 0x8f0ccc92, 10);MD5STEP(F4, c, d, a, b, in[10] + 0xffeff47d, 15);MD5STEP(F4, b, c, d, a, in[1] + 0x85845dd1, 21);MD5STEP(F4, a, b, c, d, in[8] + 0x6fa87e4f, 6);MD5STEP(F4, d, a, b, c, in[15] + 0xfe2ce6e0, 10);MD5STEP(F4, c, d, a, b, in[6] + 0xa3014314, 15);MD5STEP(F4, b, c, d, a, in[13] + 0x4e0811a1, 21);MD5STEP(F4, a, b, c, d, in[4] + 0xf7537e82, 6);MD5STEP(F4, d, a, b, c, in[11] + 0xbd3af235, 10);MD5STEP(F4, c, d, a, b, in[2] + 0x2ad7d2bb, 15);MD5STEP(F4, b, c, d, a, in[9] + 0xeb86d391, 21);buf[0] += a;buf[1] += b;buf[2] += c;buf[3] += d;}#ifndef MD5_H#define MD5_H/* The following tests optimise behaviour on little-endianmachines, where there is no need to reverse the byte orderof 32 bit words in the MD5 computation. By default,HIGHFIRST is defined, which indicates we''re running on abig-endian (most significant byte first) machine, on whichthe byteReverse function in md5.c must be invoked. However,byteReverse is coded in such a way that it is an identityfunction when run on a little-endian machine, so calling iton such a platform causes no harm apart from wasting time.If the platform is known to be little-endian, we speedthings up by undefining HIGHFIRST, which definesbyteReverse as a null macro. Doing things in this mannerinsures we work on new platforms regardless of their byteorder. */#define HIGHFIRST#ifdef __i386__#undef HIGHFIRST#endif/* On machines where "long" is 64 bits, we need to declareuint32 as something guaranteed to be 32 bits. */#ifdef __alphatypedef unsigned int uint32;#elsetypedef unsigned long uint32;#endifstruct MD5Context {uint32 buf[4];uint32 bits[2];unsigned char in[64];};extern void MD5Init();extern void MD5Update();extern void MD5Final();extern void MD5Transform();/** This is needed to make RSAREF happy on some MS-DOS compilers.*/typedef struct MD5Context MD5_CTX;/* Define CHECK_HARDWARE_PROPERTIES to have main,c verifybyte order and uint32 settings. */#define CHECK_HARDWARE_PROPERTIES#endif /* !MD5_H */--Dave K http://www.southminster-branch-line.org.uk/Please note my email address changes periodically to avoid spam.It is always of the form: month-year@domain. Hitting reply will workfor a couple of months only. Later set it manually. The month isalways written in 3 letters (e.g. Jan, not January etc) 昨天我自己想要md5并在网上找到它。不记得在哪里,但这里是下面的代码。有3个文件 - 我把它留作一个练习,让你找出main.c结束和md5.c开始的地方以及md5.c结束和md5.h开始的地方!! I wanted md5 myself yesterday and found it on the web. Can''t recall where, but here is the code below. There are 3 files - I leave it as an excercise for you to find out where main.c ends and md5.c starts and where md5.c ends and md5.h starts!! [已删除607行] 如果您在网上找到它,发布指针会更多 比发布实际代码更合适,特别是因为这不是真的是一个想要消息来源的新闻组。 - Keith Thompson(The_Other_Keith) ks***@mib.org < http://www.ghoti.net/ ~kst> 圣地亚哥超级计算机中心< *> < http://users.sdsc.edu/~kst> 我们必须做点什么。这是事情。因此,我们必须这样做。[607 lines deleted]If you found it on the web, posting a pointer would have been moreappropriate than posting the actual code, especially since this isn''treally a sources-wanted newsgroup.--Keith Thompson (The_Other_Keith) ks***@mib.org <http://www.ghoti.net/~kst>San Diego Supercomputer Center <*> <http://users.sdsc.edu/~kst>We must do something. This is something. Therefore, we must do this. 这篇关于用于计算校验和的Opensource软件?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持! 上岸,阿里云! 07-08 08:49