|
|
1.1 ! root 1: /* Implementation of NIST's Secure Hash Algorithm (FIPS 180) Lightly bummed ! 2: for execution efficiency. ! 3: ! 4: Jim Gillogly 3 May 1993 ! 5: ! 6: Copyright 1993, Dr. James J. Gillogly This code may be freely used in any ! 7: application. */ ! 8: ! 9: ! 10: #include <memory.h> ! 11: #include "sha.h" ! 12: ! 13: #pragma intrinsic(memcpy) ! 14: ! 15: #define f0(x,y,z) (z ^ (x & (y ^ z))) /* Magic functions */ ! 16: #define f1(x,y,z) (x ^ y ^ z) ! 17: #define f2(x,y,z) ((x & y) | (z & (x | y))) ! 18: #define f3(x,y,z) (x ^ y ^ z) ! 19: ! 20: #define K0 0x5a827999 /* Magic constants */ ! 21: #define K1 0x6ed9eba1 ! 22: #define K2 0x8f1bbcdc ! 23: #define K3 0xca62c1d6 ! 24: ! 25: #define S(n, X) ((X << n) | (X >> (32 - n))) /* Barrel roll */ ! 26: ! 27: #define r0(f, K) \ ! 28: temp = S(5, A) + f(B, C, D) + E + *p0++ + K; \ ! 29: E = D; \ ! 30: D = C; \ ! 31: C = S(30, B); \ ! 32: B = A; \ ! 33: A = temp ! 34: ! 35: #define r1_0(f, K) \ ! 36: temp = S(5, A) + f(B, C, D) + E + \ ! 37: (*p0++ = *p1++ ^ *p2++ ^ *p3++ ^ *p4++) + K; \ ! 38: E = D; \ ! 39: D = C; \ ! 40: C = S(30, B); \ ! 41: B = A; \ ! 42: A = temp ! 43: ! 44: void ! 45: _cdecl ShaTransform0 (unsigned long *hash, unsigned long *data) /* NIST original */ ! 46: { ! 47: unsigned long W[80]; ! 48: ! 49: unsigned long *p0, *p1, *p2, *p3, *p4; ! 50: unsigned long A, B, C, D, E, temp; ! 51: ! 52: unsigned long h0, h1, h2, h3, h4; ! 53: ! 54: h0 = hash[0]; ! 55: h1 = hash[1]; ! 56: h2 = hash[2]; ! 57: h3 = hash[3]; ! 58: h4 = hash[4]; ! 59: ! 60: memcpy (W, data, 64); ! 61: ! 62: p0 = W; ! 63: A = h0; ! 64: B = h1; ! 65: C = h2; ! 66: D = h3; ! 67: E = h4; ! 68: ! 69: r0 (f0, K0); ! 70: r0 (f0, K0); ! 71: r0 (f0, K0); ! 72: r0 (f0, K0); ! 73: r0 (f0, K0); ! 74: r0 (f0, K0); ! 75: r0 (f0, K0); ! 76: r0 (f0, K0); ! 77: r0 (f0, K0); ! 78: r0 (f0, K0); ! 79: r0 (f0, K0); ! 80: r0 (f0, K0); ! 81: r0 (f0, K0); ! 82: r0 (f0, K0); ! 83: r0 (f0, K0); ! 84: r0 (f0, K0); ! 85: ! 86: p1 = &W[13]; ! 87: p2 = &W[8]; ! 88: p3 = &W[2]; ! 89: p4 = &W[0]; ! 90: ! 91: r1_0 (f0, K0); ! 92: r1_0 (f0, K0); ! 93: r1_0 (f0, K0); ! 94: r1_0 (f0, K0); ! 95: r1_0 (f1, K1); ! 96: r1_0 (f1, K1); ! 97: r1_0 (f1, K1); ! 98: r1_0 (f1, K1); ! 99: r1_0 (f1, K1); ! 100: r1_0 (f1, K1); ! 101: r1_0 (f1, K1); ! 102: r1_0 (f1, K1); ! 103: r1_0 (f1, K1); ! 104: r1_0 (f1, K1); ! 105: r1_0 (f1, K1); ! 106: r1_0 (f1, K1); ! 107: r1_0 (f1, K1); ! 108: r1_0 (f1, K1); ! 109: r1_0 (f1, K1); ! 110: r1_0 (f1, K1); ! 111: r1_0 (f1, K1); ! 112: r1_0 (f1, K1); ! 113: r1_0 (f1, K1); ! 114: r1_0 (f1, K1); ! 115: r1_0 (f2, K2); ! 116: r1_0 (f2, K2); ! 117: r1_0 (f2, K2); ! 118: r1_0 (f2, K2); ! 119: r1_0 (f2, K2); ! 120: r1_0 (f2, K2); ! 121: r1_0 (f2, K2); ! 122: r1_0 (f2, K2); ! 123: r1_0 (f2, K2); ! 124: r1_0 (f2, K2); ! 125: r1_0 (f2, K2); ! 126: r1_0 (f2, K2); ! 127: r1_0 (f2, K2); ! 128: r1_0 (f2, K2); ! 129: r1_0 (f2, K2); ! 130: r1_0 (f2, K2); ! 131: r1_0 (f2, K2); ! 132: r1_0 (f2, K2); ! 133: r1_0 (f2, K2); ! 134: r1_0 (f2, K2); ! 135: r1_0 (f3, K3); ! 136: r1_0 (f3, K3); ! 137: r1_0 (f3, K3); ! 138: r1_0 (f3, K3); ! 139: r1_0 (f3, K3); ! 140: r1_0 (f3, K3); ! 141: r1_0 (f3, K3); ! 142: r1_0 (f3, K3); ! 143: r1_0 (f3, K3); ! 144: r1_0 (f3, K3); ! 145: r1_0 (f3, K3); ! 146: r1_0 (f3, K3); ! 147: r1_0 (f3, K3); ! 148: r1_0 (f3, K3); ! 149: r1_0 (f3, K3); ! 150: r1_0 (f3, K3); ! 151: r1_0 (f3, K3); ! 152: r1_0 (f3, K3); ! 153: r1_0 (f3, K3); ! 154: r1_0 (f3, K3); ! 155: ! 156: h0 += A; ! 157: h1 += B; ! 158: h2 += C; ! 159: h3 += D; ! 160: h4 += E; ! 161: ! 162: hash[0] = h0; ! 163: hash[1] = h1; ! 164: hash[2] = h2; ! 165: hash[3] = h3; ! 166: hash[4] = h4; ! 167: } ! 168:
This archive runs on limited infrastructure. Preserving old code on modern bandwidth. Automated agents are requested to crawl responsibly.