⭐ 欢迎来到虫虫下载站! | 📦 资源下载 📁 资源专辑 ℹ️ 关于我们
⭐ 虫虫下载站

📄 md5driver.c

📁 改进的MD5文件校验
💻 C
📖 第 1 页 / 共 2 页
字号:
  GG ( c, d, a, b, in[ 3], S23, 0xf4d50d87); /* 27 */  GG ( b, c, d, a, in[ 8], S24, 0x455a14ed); /* 28 */  GG ( a, b, c, d, in[13], S21, 0xa9e3e905); /* 29 */  GG ( d, a, b, c, in[ 2], S22, 0xfcefa3f8); /* 30 */  GG ( c, d, a, b, in[ 7], S23, 0x676f02d9); /* 31 */  GG ( b, c, d, a, in[12], S24, 0x8d2a4c8a); /* 32 */  /* Round 3 */#define S31 4#define S32 11#define S33 16#define S34 23  HH ( a, b, c, d, in[ 5], S31, 0xfffa3942); /* 33 */  HH ( d, a, b, c, in[ 8], S32, 0x8771f681); /* 34 */  HH ( c, d, a, b, in[11], S33, 0x6d9d6122); /* 35 */  HH ( b, c, d, a, in[14], S34, 0xfde5380c); /* 36 */  HH ( a, b, c, d, in[ 1], S31, 0xa4beea44); /* 37 */  HH ( d, a, b, c, in[ 4], S32, 0x4bdecfa9); /* 38 */  HH ( c, d, a, b, in[ 7], S33, 0xf6bb4b60); /* 39 */  HH ( b, c, d, a, in[10], S34, 0xbebfbc70); /* 40 */  HH ( a, b, c, d, in[13], S31,  0x289b7ec6); /* 41 */  HH ( d, a, b, c, in[ 0], S32, 0xeaa127fa); /* 42 */  HH ( c, d, a, b, in[ 3], S33, 0xd4ef3085); /* 43 */  HH ( b, c, d, a, in[ 6], S34,   0x4881d05); /* 44 */  HH ( a, b, c, d, in[ 9], S31, 0xd9d4d039); /* 45 */  HH ( d, a, b, c, in[12], S32, 0xe6db99e5); /* 46 */  HH ( c, d, a, b, in[15], S33,  0x1fa27cf8); /* 47 */  HH ( b, c, d, a, in[ 2], S34, 0xc4ac5665); /* 48 */  /* Round 4 */#define S41 6#define S42 10#define S43 15#define S44 21  II ( a, b, c, d, in[ 0], S41, 0xf4292244); /* 49 */  II ( d, a, b, c, in[ 7], S42, 0x432aff97); /* 50 */  II ( c, d, a, b, in[14], S43, 0xab9423a7); /* 51 */  II ( b, c, d, a, in[ 5], S44, 0xfc93a039); /* 52 */  II ( a, b, c, d, in[12], S41, 0x655b59c3); /* 53 */  II ( d, a, b, c, in[ 3], S42, 0x8f0ccc92); /* 54 */  II ( c, d, a, b, in[10], S43, 0xffeff47d); /* 55 */  II ( b, c, d, a, in[ 1], S44, 0x85845dd1); /* 56 */  II ( a, b, c, d, in[ 8], S41, 0x6fa87e4f); /* 57 */  II ( d, a, b, c, in[15], S42, 0xfe2ce6e0); /* 58 */  II ( c, d, a, b, in[ 6], S43, 0xa3014314); /* 59 */  II ( b, c, d, a, in[13], S44, 0x4e0811a1); /* 60 */  II ( a, b, c, d, in[ 4], S41, 0xf7537e82); /* 61 */  II ( d, a, b, c, in[11], S42, 0xbd3af235); /* 62 */  II ( c, d, a, b, in[ 2], S43,  0x2ad7d2bb); /* 63 */  II ( b, c, d, a, in[ 9], S44, 0xeb86d391); /* 64 */  buf[0] += a;  buf[1] += b;  buf[2] += c;  buf[3] += d;}/* ********************************************************************** ** End of md5.c                                                     ** ******************************* (cut) ******************************** *//* Prints message digest buffer in mdContext as 32 hexadecimal digits.   Order is from low-order byte to high-order byte of digest.   Each byte is printed with high-order hexadecimal digit first. */static void MDPrint (MD5_CTX *mdContext){  int i;	printf ("char is:");  for (i = 0; i < 16; i++)    printf ("%02x", mdContext->digest[i]);}/* size of test block */#define TEST_BLOCK_SIZE 1000/* number of blocks to process */#define TEST_BLOCKS 10000/* number of test bytes = TEST_BLOCK_SIZE * TEST_BLOCKS */static long TEST_BYTES = (long)TEST_BLOCK_SIZE * (long)TEST_BLOCKS;/* A time trial routine, to measure the speed of MD5.   Measures wall time required to digest TEST_BLOCKS * TEST_BLOCK_SIZE   characters. */static void MDTimeTrial (){  MD5_CTX mdContext;  time_t endTime, startTime;  unsigned char data[TEST_BLOCK_SIZE];  unsigned int i;  /* initialize test data */  for (i = 0; i < TEST_BLOCK_SIZE; i++)    data[i] = (unsigned char)(i & 0xFF);  /* start timer */  printf ("MD5 time trial. Processing %ld characters...\n", TEST_BYTES);  time (&startTime);  /* digest data in TEST_BLOCK_SIZE byte blocks */  MD5Init (&mdContext);  for (i = TEST_BLOCKS; i > 0; i--)  MD5Update (&mdContext, data, TEST_BLOCK_SIZE);  MD5Final (&mdContext);  /* stop timer, get time difference */  time (&endTime);  MDPrint (&mdContext);  printf (" is digest of test input.\n");  printf    ("Seconds to process test input: %ld\n", (long)(endTime-startTime));  printf    ("Characters processed per second: %ld\n",     TEST_BYTES/(endTime-startTime));}/* Computes the message digest for string inString.   Prints out message digest, a space, the string (in quotes) and a   carriage return. */static void MDString (char *inString){  MD5_CTX mdContext;  unsigned int len = strlen (inString);  MD5Init (&mdContext);  MD5Update (&mdContext, inString, len);  MD5Final (&mdContext);  MDPrint (&mdContext);  printf (" \"%s\"\n\n", inString);}/* Computes the message digest for a specified file.   Prints out message digest, a space, the file name, and a carriage   return. */static void MDFile (char *filename){  FILE *inFile = fopen (filename, "rb");  MD5_CTX mdContext;  int bytes;  unsigned char data[1024];  if (inFile == NULL) {    printf ("%s can't be opened.\n", filename);    return;  }  MD5Init (&mdContext);  while ((bytes = fread (data, 1, 1024, inFile)) != 0)    MD5Update (&mdContext, data, bytes);  MD5Final (&mdContext);  MDPrint (&mdContext);  printf (" filename :%s\n", filename);  fclose (inFile);}/* Writes the message digest of the data from stdin onto stdout,   followed by a carriage return. */static void MDFilter (){  MD5_CTX mdContext;  int bytes;  unsigned char data[16];  MD5Init (&mdContext);  while ((bytes = fread (data, 1, 16, stdin)) != 0)    MD5Update (&mdContext, data, bytes);  MD5Final (&mdContext);  MDPrint (&mdContext);  printf ("\n");}/* Runs a standard suite of test data. */static void MDTestSuite (){  printf ("MD5 test suite results:\n\n");  MDString ("");  MDString ("a");  MDString ("abc");  MDString ("message digest");  MDString ("abcdefghijklmnopqrstuvwxyz");  MDString    ("ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789");  MDString    ("1234567890123456789012345678901234567890\1234567890123456789012345678901234567890");  /* Contents of file foo are "abc" */  MDFile ("foo");}int main (int argc,char *argv[]){  int i;  /* For each command line argument in turn:  ** filename          -- prints message digest and name of file  ** -sstring          -- prints message digest and contents of string  ** -t                -- prints time trial statistics for 1M characters  ** -x                -- execute a standard suite of test data  ** (no args)         -- writes messages digest of stdin onto stdout  */  if (argc == 1)    MDFilter ();  else    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]);      return 0;}/* ********************************************************************** ** End of md5driver.c                                               ** ******************************* (cut) ******************************** */

⌨️ 快捷键说明

复制代码 Ctrl + C
搜索代码 Ctrl + F
全屏模式 F11
切换主题 Ctrl + Shift + D
显示快捷键 ?
增大字号 Ctrl + =
减小字号 Ctrl + -