📄 radius_message_digest.c
字号:
ULONG a = state[0], b = state[1], c = state[2], d = state[3], x[16]; MD_decode (x, block, 64); /* Round 1 */ MD4_FF (a, b, c, d, x[ 0], MD4_S11); /* 1 */ MD4_FF (d, a, b, c, x[ 1], MD4_S12); /* 2 */ MD4_FF (c, d, a, b, x[ 2], MD4_S13); /* 3 */ MD4_FF (b, c, d, a, x[ 3], MD4_S14); /* 4 */ MD4_FF (a, b, c, d, x[ 4], MD4_S11); /* 5 */ MD4_FF (d, a, b, c, x[ 5], MD4_S12); /* 6 */ MD4_FF (c, d, a, b, x[ 6], MD4_S13); /* 7 */ MD4_FF (b, c, d, a, x[ 7], MD4_S14); /* 8 */ MD4_FF (a, b, c, d, x[ 8], MD4_S11); /* 9 */ MD4_FF (d, a, b, c, x[ 9], MD4_S12); /* 10 */ MD4_FF (c, d, a, b, x[10], MD4_S13); /* 11 */ MD4_FF (b, c, d, a, x[11], MD4_S14); /* 12 */ MD4_FF (a, b, c, d, x[12], MD4_S11); /* 13 */ MD4_FF (d, a, b, c, x[13], MD4_S12); /* 14 */ MD4_FF (c, d, a, b, x[14], MD4_S13); /* 15 */ MD4_FF (b, c, d, a, x[15], MD4_S14); /* 16 */ /* Round 2 */ MD4_GG (a, b, c, d, x[ 0], MD4_S21); /* 17 */ MD4_GG (d, a, b, c, x[ 4], MD4_S22); /* 18 */ MD4_GG (c, d, a, b, x[ 8], MD4_S23); /* 19 */ MD4_GG (b, c, d, a, x[12], MD4_S24); /* 20 */ MD4_GG (a, b, c, d, x[ 1], MD4_S21); /* 21 */ MD4_GG (d, a, b, c, x[ 5], MD4_S22); /* 22 */ MD4_GG (c, d, a, b, x[ 9], MD4_S23); /* 23 */ MD4_GG (b, c, d, a, x[13], MD4_S24); /* 24 */ MD4_GG (a, b, c, d, x[ 2], MD4_S21); /* 25 */ MD4_GG (d, a, b, c, x[ 6], MD4_S22); /* 26 */ MD4_GG (c, d, a, b, x[10], MD4_S23); /* 27 */ MD4_GG (b, c, d, a, x[14], MD4_S24); /* 28 */ MD4_GG (a, b, c, d, x[ 3], MD4_S21); /* 29 */ MD4_GG (d, a, b, c, x[ 7], MD4_S22); /* 30 */ MD4_GG (c, d, a, b, x[11], MD4_S23); /* 31 */ MD4_GG (b, c, d, a, x[15], MD4_S24); /* 32 */ /* Round 3 */ MD4_HH (a, b, c, d, x[ 0], MD4_S31); /* 33 */ MD4_HH (d, a, b, c, x[ 8], MD4_S32); /* 34 */ MD4_HH (c, d, a, b, x[ 4], MD4_S33); /* 35 */ MD4_HH (b, c, d, a, x[12], MD4_S34); /* 36 */ MD4_HH (a, b, c, d, x[ 2], MD4_S31); /* 37 */ MD4_HH (d, a, b, c, x[10], MD4_S32); /* 38 */ MD4_HH (c, d, a, b, x[ 6], MD4_S33); /* 39 */ MD4_HH (b, c, d, a, x[14], MD4_S34); /* 40 */ MD4_HH (a, b, c, d, x[ 1], MD4_S31); /* 41 */ MD4_HH (d, a, b, c, x[ 9], MD4_S32); /* 42 */ MD4_HH (c, d, a, b, x[ 5], MD4_S33); /* 43 */ MD4_HH (b, c, d, a, x[13], MD4_S34); /* 44 */ MD4_HH (a, b, c, d, x[ 3], MD4_S31); /* 45 */ MD4_HH (d, a, b, c, x[11], MD4_S32); /* 46 */ MD4_HH (c, d, a, b, x[ 7], MD4_S33); /* 47 */ MD4_HH (b, c, d, a, x[15], MD4_S34); /* 48 */ state[0] += a; state[1] += b; state[2] += c; state[3] += d; /* Zeroize sensitive information.*/ MD_memset ((BYTE *) x, 0, sizeof (x));}/*****************************************************************************//* MD5 basic transformation. Transforms state based on block. *//*****************************************************************************/static void MD5_transform (ULONG state[4],BYTE block[64]){ ULONG a = state[0], b = state[1], c = state[2], d = state[3], x[16]; MD_decode (x, block, 64); /* Round 1 */ MD5_FF (a, b, c, d, x[ 0], MD5_S11, 0xd76aa478); /* 1 */ MD5_FF (d, a, b, c, x[ 1], MD5_S12, 0xe8c7b756); /* 2 */ MD5_FF (c, d, a, b, x[ 2], MD5_S13, 0x242070db); /* 3 */ MD5_FF (b, c, d, a, x[ 3], MD5_S14, 0xc1bdceee); /* 4 */ MD5_FF (a, b, c, d, x[ 4], MD5_S11, 0xf57c0faf); /* 5 */ MD5_FF (d, a, b, c, x[ 5], MD5_S12, 0x4787c62a); /* 6 */ MD5_FF (c, d, a, b, x[ 6], MD5_S13, 0xa8304613); /* 7 */ MD5_FF (b, c, d, a, x[ 7], MD5_S14, 0xfd469501); /* 8 */ MD5_FF (a, b, c, d, x[ 8], MD5_S11, 0x698098d8); /* 9 */ MD5_FF (d, a, b, c, x[ 9], MD5_S12, 0x8b44f7af); /* 10 */ MD5_FF (c, d, a, b, x[10], MD5_S13, 0xffff5bb1); /* 11 */ MD5_FF (b, c, d, a, x[11], MD5_S14, 0x895cd7be); /* 12 */ MD5_FF (a, b, c, d, x[12], MD5_S11, 0x6b901122); /* 13 */ MD5_FF (d, a, b, c, x[13], MD5_S12, 0xfd987193); /* 14 */ MD5_FF (c, d, a, b, x[14], MD5_S13, 0xa679438e); /* 15 */ MD5_FF (b, c, d, a, x[15], MD5_S14, 0x49b40821); /* 16 */ /* Round 2 */ MD5_GG (a, b, c, d, x[ 1], MD5_S21, 0xf61e2562); /* 17 */ MD5_GG (d, a, b, c, x[ 6], MD5_S22, 0xc040b340); /* 18 */ MD5_GG (c, d, a, b, x[11], MD5_S23, 0x265e5a51); /* 19 */ MD5_GG (b, c, d, a, x[ 0], MD5_S24, 0xe9b6c7aa); /* 20 */ MD5_GG (a, b, c, d, x[ 5], MD5_S21, 0xd62f105d); /* 21 */ MD5_GG (d, a, b, c, x[10], MD5_S22, 0x2441453); /* 22 */ MD5_GG (c, d, a, b, x[15], MD5_S23, 0xd8a1e681); /* 23 */ MD5_GG (b, c, d, a, x[ 4], MD5_S24, 0xe7d3fbc8); /* 24 */ MD5_GG (a, b, c, d, x[ 9], MD5_S21, 0x21e1cde6); /* 25 */ MD5_GG (d, a, b, c, x[14], MD5_S22, 0xc33707d6); /* 26 */ MD5_GG (c, d, a, b, x[ 3], MD5_S23, 0xf4d50d87); /* 27 */ MD5_GG (b, c, d, a, x[ 8], MD5_S24, 0x455a14ed); /* 28 */ MD5_GG (a, b, c, d, x[13], MD5_S21, 0xa9e3e905); /* 29 */ MD5_GG (d, a, b, c, x[ 2], MD5_S22, 0xfcefa3f8); /* 30 */ MD5_GG (c, d, a, b, x[ 7], MD5_S23, 0x676f02d9); /* 31 */ MD5_GG (b, c, d, a, x[12], MD5_S24, 0x8d2a4c8a); /* 32 */ /* Round 3 */ MD5_HH (a, b, c, d, x[ 5], MD5_S31, 0xfffa3942); /* 33 */ MD5_HH (d, a, b, c, x[ 8], MD5_S32, 0x8771f681); /* 34 */ MD5_HH (c, d, a, b, x[11], MD5_S33, 0x6d9d6122); /* 35 */ MD5_HH (b, c, d, a, x[14], MD5_S34, 0xfde5380c); /* 36 */ MD5_HH (a, b, c, d, x[ 1], MD5_S31, 0xa4beea44); /* 37 */ MD5_HH (d, a, b, c, x[ 4], MD5_S32, 0x4bdecfa9); /* 38 */ MD5_HH (c, d, a, b, x[ 7], MD5_S33, 0xf6bb4b60); /* 39 */ MD5_HH (b, c, d, a, x[10], MD5_S34, 0xbebfbc70); /* 40 */ MD5_HH (a, b, c, d, x[13], MD5_S31, 0x289b7ec6); /* 41 */ MD5_HH (d, a, b, c, x[ 0], MD5_S32, 0xeaa127fa); /* 42 */ MD5_HH (c, d, a, b, x[ 3], MD5_S33, 0xd4ef3085); /* 43 */ MD5_HH (b, c, d, a, x[ 6], MD5_S34, 0x4881d05); /* 44 */ MD5_HH (a, b, c, d, x[ 9], MD5_S31, 0xd9d4d039); /* 45 */ MD5_HH (d, a, b, c, x[12], MD5_S32, 0xe6db99e5); /* 46 */ MD5_HH (c, d, a, b, x[15], MD5_S33, 0x1fa27cf8); /* 47 */ MD5_HH (b, c, d, a, x[ 2], MD5_S34, 0xc4ac5665); /* 48 */ /* Round 4 */ MD5_II (a, b, c, d, x[ 0], MD5_S41, 0xf4292244); /* 49 */ MD5_II (d, a, b, c, x[ 7], MD5_S42, 0x432aff97); /* 50 */ MD5_II (c, d, a, b, x[14], MD5_S43, 0xab9423a7); /* 51 */ MD5_II (b, c, d, a, x[ 5], MD5_S44, 0xfc93a039); /* 52 */ MD5_II (a, b, c, d, x[12], MD5_S41, 0x655b59c3); /* 53 */ MD5_II (d, a, b, c, x[ 3], MD5_S42, 0x8f0ccc92); /* 54 */ MD5_II (c, d, a, b, x[10], MD5_S43, 0xffeff47d); /* 55 */ MD5_II (b, c, d, a, x[ 1], MD5_S44, 0x85845dd1); /* 56 */ MD5_II (a, b, c, d, x[ 8], MD5_S41, 0x6fa87e4f); /* 57 */ MD5_II (d, a, b, c, x[15], MD5_S42, 0xfe2ce6e0); /* 58 */ MD5_II (c, d, a, b, x[ 6], MD5_S43, 0xa3014314); /* 59 */ MD5_II (b, c, d, a, x[13], MD5_S44, 0x4e0811a1); /* 60 */ MD5_II (a, b, c, d, x[ 4], MD5_S41, 0xf7537e82); /* 61 */ MD5_II (d, a, b, c, x[11], MD5_S42, 0xbd3af235); /* 62 */ MD5_II (c, d, a, b, x[ 2], MD5_S43, 0x2ad7d2bb); /* 63 */ MD5_II (b, c, d, a, x[ 9], MD5_S44, 0xeb86d391); /* 64 */ state[0] += a; state[1] += b; state[2] += c; state[3] += d; /* Zeroize sensitive information.*/ MD_memset ((BYTE *)x, 0, sizeof (x));}/****************************************************************************//* Encodes input (ULONG) into output (BYTE). Assumes length is a multiple of 4. *//****************************************************************************/static void MD_encode (BYTE *bptr_output, ULONG *ulptr_input, ULONG length){ ULONG i; ULONG j; for (i = 0x00000000L, j = 0x00000000L; j < length; ++i, j += 4) { bptr_output[j] = (BYTE)(ulptr_input[i] & 0xff); bptr_output[j+1] = (BYTE)((ulptr_input[i] >> 8) & 0xff); bptr_output[j+2] = (BYTE)((ulptr_input[i] >> 16) & 0xff); bptr_output[j+3] = (BYTE)((ulptr_input[i] >> 24) & 0xff); }}/****************************************************************************//* Decodes input (BYTE) into output (ULONG). Assumes length is a multiple of 4. *//****************************************************************************/static void MD_decode (ULONG *ulptr_output, BYTE *bptr_input, ULONG length){ ULONG i; ULONG j; for (i = 0x00000000L, j = 0x00000000L; j < length; ++i, j += 4) { ulptr_output[i] = ((ULONG)bptr_input[j]) | (((ULONG)bptr_input[j+1]) << 8) | (((ULONG)bptr_input[j+2]) << 16) | (((ULONG)bptr_input[j+3]) << 24); }}/****************************************************************************//* Note: Replace "for loop" with standard memcpy if possible. *//****************************************************************************/static void MD_memcpy (BYTE *bptr_output,BYTE *bptr_input,ULONG length){ ULONG i; for (i = 0x00000000L; i < length; ++i) { bptr_output[i] = bptr_input[i]; }}/****************************************************************************//* Note: Replace "for loop" with standard memset if possible. *//****************************************************************************/static void MD_memset (BYTE *bptr_output,int value,ULONG length){ ULONG i; for (i = 0x00000000L; i < length; ++i) { ((char *)bptr_output)[i] = (char)value; }}#endif /* __EAP__ */
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -