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

📄 rfc1115.txt

📁 <VC++网络游戏建摸与实现>源代码
💻 TXT
📖 第 1 页 / 共 2 页
字号:
RFC 1115                Mail Privacy: Algorithms             August 1989   may be supplanted by later recommendations for MIC algorithm   selections.   The RSA-MD2 message digest algorithm accepts as input a message of any   length and produces as output a 16-byte quantity.  The attached   reference implementation serves to define the algorithm; implementors   may choose to develop optimizations suited to their operating   environments.4.2.2.  Reference Implementation/* RSA-MD2 Message Digest algorithm in C  *//*  by Ronald L. Rivest 10/1/88  */#include <stdio.h>/**********************************************************************//* Message digest routines:                                           *//* To form the message digest for a message M                         *//*    (1) Initialize a context buffer md using MDINIT                 *//*    (2) Call MDUPDATE on md and each character of M in turn         *//*    (3) Call MDFINAL on md                                          *//* The message digest is now in md->D[0...15]                         *//**********************************************************************//* An MDCTX structure is a context buffer for a message digest        *//*  computation; it holds the current "state" of a message digest     *//*  computation                                                       */struct MDCTX{   unsigned char  D[48];   /* buffer for forming digest in */                           /* At the end, D[0...15] form the message */                           /*  digest */   unsigned char  C[16];   /* checksum register */   unsigned char  i;       /* number of bytes handled, modulo 16 */   unsigned char  L;       /* last checksum char saved */};/* The table S given below is a permutation of 0...255 constructed    *//*  from the digits of pi.  It is a ``random'' nonlinear byte         *//*  substitution operation.                                           */int S[256] = {        41, 46, 67,201,162,216,124,  1, 61, 54, 84,161,236,240,  6, 19,        98,167,  5,243,192,199,115,140,152,147, 43,217,188, 76,130,202,        30,155, 87, 60,253,212,224, 22,103, 66,111, 24,138, 23,229, 18,       190, 78,196,214,218,158,222, 73,160,251,245,142,187, 47,238,122,       169,104,121,145, 21,178,  7, 63,148,194, 16,137, 11, 34, 95, 33,       128,127, 93,154, 90,144, 50, 39, 53, 62,204,231,191,247,151,  3,       255, 25, 48,179, 72,165,181,209,215, 94,146, 42,172, 86,170,198,        79,184, 56,210,150,164,125,182,118,252,107,226,156,116,  4,241,Linn                                                            [Page 5]RFC 1115                Mail Privacy: Algorithms             August 1989        69,157,112, 89,100,113,135, 32,134, 91,207,101,230, 45,168,  2,        27, 96, 37,173,174,176,185,246, 28, 70, 97,105, 52, 64,126, 15,        85, 71,163, 35,221, 81,175, 58,195, 92,249,206,186,197,234, 38,        44, 83, 13,110,133, 40,132,  9,211,223,205,244, 65,129, 77, 82,       106,220, 55,200,108,193,171,250, 36,225,123,  8, 12,189,177, 74,       120,136,149,139,227, 99,232,109,233,203,213,254, 59,  0, 29, 57,       242,239,183, 14,102, 88,208,228,166,119,114,248,235,117, 75, 10,        49, 68, 80,180,143,237, 31, 26,219,153,141, 51,159, 17,131, 20,};/*The routine MDINIT initializes the message digest context buffer md.*//* All fields are set to zero.                                        */void MDINIT(md)  struct MDCTX *md;  { int i;    for (i=0;i<16;i++) md->D[i] = md->C[i] = 0;    md->i = 0;    md->L = 0;  }/* The routine MDUPDATE updates the message digest context buffer to  *//*  account for the presence of the character c in the message whose  *//*  digest is being computed.  This routine will be called for each   *//*   message byte in turn.                                            */void MDUPDATE(md,c)  struct MDCTX *md;  unsigned char c;  { register unsigned char i,j,t,*p;    /**** Put i in a local register for efficiency ****/       i = md->i;    /**** Add new character to buffer ****/       md->D[16+i] = c;       md->D[32+i] = c ^ md->D[i];    /**** Update checksum register C and value L ****/       md->L = (md->C[i] ^= S[0xFF & (c ^ md->L)]);    /**** Increment md->i by one modulo 16 ****/       i = md->i = (i + 1) & 15;    /**** Transform D if i=0 ****/       if (i == 0)         { t = 0;           for (j=0;j<18;j++)             {/*The following is a more efficient version of the loop:*/               /*  for (i=0;i<48;i++) t = md->D[i] = md->D[i] ^ S[t]; */               p = md->D;               for (i=0;i<8;i++)                 { t = (*p++ ^= S[t]);                   t = (*p++ ^= S[t]);                   t = (*p++ ^= S[t]);                   t = (*p++ ^= S[t]);                   t = (*p++ ^= S[t]);Linn                                                            [Page 6]RFC 1115                Mail Privacy: Algorithms             August 1989                   t = (*p++ ^= S[t]);                 }               /* End of more efficient loop implementation */               t = t + j;             }         }  }/* The routine MDFINAL terminates the message digest computation and  *//* ends with the desired message digest being in md->D[0...15].       */void MDFINAL(md)  struct MDCTX *md;  { int i,padlen;    /* pad out to multiple of 16 */       padlen  = 16 - (md->i);       for (i=0;i<padlen;i++) MDUPDATE(md,(unsigned char)padlen);    /* extend with checksum */    /* Note that although md->C is modified by MDUPDATE, character    */    /* md->C[i] is modified after it has been passed to MDUPDATE, so  */    /* the net effect is the same as if md->C were not being modified.*/    for (i=0;i<16;i++) MDUPDATE(md,md->C[i]);  }/**********************************************************************//* End of message digest implementation                               *//**********************************************************************/NOTES:  [1]  Federal Information Processing Standards Publication 113,       Computer Data Authentication, May 1985.  [2]  ANSI X9.17-1985, American National Standard, Financial       Institution Key Management (Wholesale), American Bankers       Association, April 4, 1985, Section 7.2.  [3]  American National Standard Data Encryption Algorithm (ANSI       X3.92-1981), American National Standards Institute, Approved 30       December 1980.  [4]  Federal Information Processing Standards Publication 46,  Data       Encryption Standard, 15 January 1977.  [5]  Information Processing Systems: Data Encipherment: Modes of       Operation of a 64-bit Block Cipher.  [6]  Federal Information Processing Standards Publication 81,       DES Modes of Operation, 2 December 1980.Linn                                                            [Page 7]RFC 1115                Mail Privacy: Algorithms             August 1989  [7]  American National Standard for Information Systems - Data       Encryption  Algorithm - Modes of Operation (ANSI X3.106-1983),       American National Standards Institute - Approved 16 May 1983.  [8]  CCITT, Recommendation X.509, "The Directory: Authentication       Framework", Annex C.  [9]  Moore, J., "Protocol Failures in Cryptosystems",       Proceedings of the IEEE, Vol. 76, No. 5, Pg. 597, May 1988.Author's Address       John Linn       Secure Systems       Digital Equipment Corporation       85 Swanson Road, BXB1-2/D04       Boxborough, MA  01719-1326       Phone: 508-264-5491       EMail: Linn@ultra.enet.dec.comLinn                                                            [Page 8]

⌨️ 快捷键说明

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