public override byte[] Hash(byte[] data) { byte[] paddedInput = LengthPadding.PadToBlockSize(data, 64, 8, true); // Convert bytes to uint array for processing uint[] arr = paddedInput.UInt8ArrToUInt32ArrLE(); // Initial Hash values uint[] hash = { 0x67_45_23_01, 0xef_cd_ab_89, 0x98_ba_dc_fe, 0x10_32_54_76 };
public override byte[] Hash(byte[] data) { byte[] paddedInput = LengthPadding.PadToBlockSize(data, 64, 8, true); // Convert bytes to uint array for processing uint[] arr = paddedInput.UInt8ArrToUInt32ArrLE(); // Initial Hash values uint[] hash = { 0x67452301, 0xEFCDAB89, 0x98BADCFE, 0x10325476, 0xC3D2E1F0 }; // amount of blocks int amountOfBlocks = arr.Length / 16; uint[] block = new uint[16]; // Message Block for (int n = 0; n < amountOfBlocks; n++) { // Copy data into current message block Array.Copy(arr, 16 * n, block, 0, block.Length); // 1. Initialize the working variables: uint a = hash[0]; uint b = hash[1]; uint c = hash[2]; uint d = hash[3]; uint e = hash[4]; uint _a = hash[0]; uint _b = hash[1]; uint _c = hash[2]; uint _d = hash[3]; uint _e = hash[4]; // 2. Perform the main hash computation: foreach (int j in Enumerable.Range(0, 80)) { int s = _s160[j]; int sdash = _sDash160[j]; uint t = (a + F(j, b, c, d) + block[_r160[j]] + K_160(j)).RotL(s) + e; a = e; e = d; d = c.RotL(10); c = b; b = t; t = (_a + F(79 - j, _b, _c, _d) + block[_rDash160[j]] + KDash_160(j)).RotL(sdash) + _e; _a = _e; _e = _d; _d = _c.RotL(10); _c = _b; _b = t; } // 3. Compute the intermediate hash value H(i) uint temp = hash[1] + c + _d; hash[1] = hash[2] + d + _e; hash[2] = hash[3] + e + _a; hash[3] = hash[4] + a + _b; hash[4] = hash[0] + b + _c; hash[0] = temp; } return(hash.UInt32ArrToUInt8ArrLE()); }
public override byte[] Hash(byte[] data) { byte[] paddedInput = LengthPadding.PadToBlockSize(data, 64, 8); // Convert input byte array to uint array for processing uint[] arr = paddedInput.UInt8ArrToUInt32Arr(); // Initial Values uint[] hash = { 0xc1059ed8, 0x367cd507, 0x3070dd17, 0xf70e5939, 0xffc00b31, 0x68581511, 0x64f98fa7, 0xbefa4fa4 }; // amount of blocks int n = arr.Length / 16; uint[] m = new uint[16]; // M_0 -> M_15, Current Block uint[] w = new uint[64]; // W_0 -> W_63, Message Schedule // Process each block for (int i = 0; i < n; i++) { // Copy data into current message block Array.Copy(arr, i * m.Length, m, 0, m.Length); // 1. Prepare the message schedule W: Array.Copy(m, 0, w, 0, m.Length); // Copy first block into start of message schedule w foreach (int t in Enumerable.Range(16, 48)) { w[t] = SmallSigma1(w[t - 2]) + w[t - 7] + SmallSigma0(w[t - 15]) + w[t - 16]; } // 2. Initialize the working variables: uint a = hash[0]; uint b = hash[1]; uint c = hash[2]; uint d = hash[3]; uint e = hash[4]; uint f = hash[5]; uint g = hash[6]; uint h = hash[7]; // 3. Perform the main hash computation: foreach (int t in Enumerable.Range(0, 64)) { uint t1 = h + BigSigma1(e) + Ch(e, f, g) + _k256[t] + w[t]; uint t2 = BigSigma0(a) + Maj(a, b, c); h = g; g = f; f = e; e = d + t1; d = c; c = b; b = a; a = t1 + t2; } // 4. Compute the intermediate hash value H(i) hash[0] += a; hash[1] += b; hash[2] += c; hash[3] += d; hash[4] += e; hash[5] += f; hash[6] += g; hash[7] += h; } uint[] output = { hash[0], hash[1], hash[2], hash[3], hash[4], hash[5], hash[6] }; return(output.UInt32ArrToUInt8Arr()); }
public override byte[] Hash(byte[] data) { byte[] paddedInput = LengthPadding.PadToBlockSize(data, 128, 16); // Convert input bytes to ulong array ulong[] arr = paddedInput.UInt8ArrToUInt64Arr(); // Initial values ulong[] hash = { 0xcbbb9d5dc1059ed8, 0x629a292a367cd507, 0x9159015a3070dd17, 0x152fecd8f70e5939, 0x67332667ffc00b31, 0x8eb44a8768581511, 0xdb0c2e0d64f98fa7, 0x47b5481dbefa4fa4 }; // amount of blocks int n = arr.Length / 16; ulong[] m = new ulong[16]; // M_0 -> M_15, Message Block ulong[] w = new ulong[80]; // W_0 -> W_79, Message Schedule // Process each block for (int i = 0; i < n; i++) { // message block Array.Copy(arr, i * m.Length, m, 0, m.Length); // 1. Prepare the message schedule W: Array.Copy(m, 0, w, 0, m.Length); // Copy first block into start of message schedule w foreach (int t in Enumerable.Range(start: 16, count: 64)) { w[t] = SmallSigma1(w[t - 2]) + w[t - 7] + SmallSigma0(w[t - 15]) + w[t - 16]; } // 2. Initialize the working variables: ulong a = hash[0]; ulong b = hash[1]; ulong c = hash[2]; ulong d = hash[3]; ulong e = hash[4]; ulong f = hash[5]; ulong g = hash[6]; ulong h = hash[7]; // 3. Perform the main hash computation: foreach (int t in Enumerable.Range(0, 80)) { ulong t1 = h + BigSigma1(e) + Ch(e, f, g) + _k512[t] + w[t]; ulong t2 = BigSigma0(a) + Maj(a, b, c); h = g; g = f; f = e; e = d + t1; d = c; c = b; b = a; a = t1 + t2; } // 4. Compute the intermediate hash value H(i) hash[0] += a; hash[1] += b; hash[2] += c; hash[3] += d; hash[4] += e; hash[5] += f; hash[6] += g; hash[7] += h; } ulong[] output = { hash[0], hash[1], hash[2], hash[3], hash[4], hash[5] }; return(output.UInt64ArrToUInt8Arr()); }
public override byte[] Hash(byte[] data) { byte[] paddedInput = LengthPadding.PadToBlockSize(data, 64, 8); // Convert input byte array to uint array for processing uint[] arr = paddedInput.UInt8ArrToUInt32Arr(); // Initial values uint[] hash = { 0x67452301, 0xEFCDAB89, 0x98BADCFE, 0x10325476, 0xC3D2E1F0 }; // amount of blocks int amountOfBlocks = arr.Length / 16; uint[] m = new uint[16]; // M_0 -> M_15, Message Block uint[] w = new uint[80]; // W_0 -> W_79, Message Schedule // Process each block for (int n = 0; n < amountOfBlocks; n++) { // Copy data into current message block Array.Copy(arr, n * m.Length, m, 0, m.Length); // 1. Prepare the message schedule W: Array.Copy(m, 0, w, 0, m.Length); // Copy first block into start of message schedule w foreach (int t in Enumerable.Range(16, 64)) { w[t] = (w[t - 3] ^ w[t - 8] ^ w[t - 14] ^ w[t - 16]).RotL(1); } // 2. Initialize the working variables: uint a = hash[0]; uint b = hash[1]; uint c = hash[2]; uint d = hash[3]; uint e = hash[4]; // 3. Perform the main hash computation: foreach (int t in Enumerable.Range(0, 80)) { uint temp = a.RotL(5) + F(t, b, c, d) + e + w[t] + K(t); e = d; d = c; c = b.RotL(30); b = a; a = temp; } // 4. Compute the intermediate hash value H(i) hash[0] += a; hash[1] += b; hash[2] += c; hash[3] += d; hash[4] += e; } return(hash.UInt32ArrToUInt8Arr()); }
public override byte[] Hash(byte[] data) { byte[] paddedInput = LengthPadding.PadToBlockSize(data, 64, 8); // Convert input byte array to uint array for processing uint[] arr = paddedInput.UInt8ArrToUInt32Arr(); // Initial Values uint[] hash = { 0x6a09e667, 0xbb67ae85, 0x3c6ef372, 0xa54ff53a, 0x510e527f, 0x9b05688c, 0x1f83d9ab, 0x5be0cd19 }; // amount of blocks int n = arr.Length / 16; uint[] m = new uint[16]; // M_0 -> M_15, Message Block uint[] w = new uint[64]; // W_0 -> W_63, Message Schedule // Process each block for (int i = 0; i < n; i++) { // Copy data into current message block Array.Copy(arr, i * m.Length, m, 0, m.Length); // 1. Prepare the message schedule W: Array.Copy(m, 0, w, 0, m.Length); // Copy first block into start of message schedule w foreach (int t in Enumerable.Range(16, 48)) { w[t] = SmallSigma1(w[t - 2]) + w[t - 7] + SmallSigma0(w[t - 15]) + w[t - 16]; } // 2. Initialize the working variables: uint a = hash[0]; uint b = hash[1]; uint c = hash[2]; uint d = hash[3]; uint e = hash[4]; uint f = hash[5]; uint g = hash[6]; uint h = hash[7]; // 3. Perform the main hash computation: foreach (int t in Enumerable.Range(0, 64)) { uint t1 = h + BigSigma1(e) + Ch(e, f, g) + _k256[t] + w[t]; uint t2 = BigSigma0(a) + Maj(a, b, c); h = g; g = f; f = e; e = d + t1; d = c; c = b; b = a; a = t1 + t2; } // 4. Compute the intermediate hash value H(i) hash[0] += a; hash[1] += b; hash[2] += c; hash[3] += d; hash[4] += e; hash[5] += f; hash[6] += g; hash[7] += h; } return(hash.UInt32ArrToUInt8Arr()); }
public override byte[] Hash(byte[] data) { byte[] paddedInput = LengthPadding.PadToBlockSize(data, 128, 16); // Convert input bytes to ulong array ulong[] arr = paddedInput.UInt8ArrToUInt64Arr(); // Initial values ulong[] hash = { 0x6a09e667f3bcc908, 0xbb67ae8584caa73b, 0x3c6ef372fe94f82b, 0xa54ff53a5f1d36f1, 0x510e527fade682d1, 0x9b05688c2b3e6c1f, 0x1f83d9abfb41bd6b, 0x5be0cd19137e2179 }; // amount of blocks int n = arr.Length / 16; ulong[] m = new ulong[16]; // M_0 -> M_15, Message Block ulong[] w = new ulong[80]; // W_0 -> W_79, Message Schedule // Process each block for (int i = 0; i < n; i++) { // message block Array.Copy(arr, i * m.Length, m, 0, m.Length); // 1. Prepare the message schedule W: Array.Copy(m, 0, w, 0, m.Length); // Copy first block into start of message schedule w foreach (int t in Enumerable.Range(start: 16, count: 64)) { w[t] = SmallSigma1(w[t - 2]) + w[t - 7] + SmallSigma0(w[t - 15]) + w[t - 16]; } // 2. Initialize the working variables: ulong a = hash[0]; ulong b = hash[1]; ulong c = hash[2]; ulong d = hash[3]; ulong e = hash[4]; ulong f = hash[5]; ulong g = hash[6]; ulong h = hash[7]; // 3. Perform the main hash computation: foreach (int t in Enumerable.Range(0, 80)) { ulong t1 = h + BigSigma1(e) + Ch(e, f, g) + _k512[t] + w[t]; ulong t2 = BigSigma0(a) + Maj(a, b, c); h = g; g = f; f = e; e = d + t1; d = c; c = b; b = a; a = t1 + t2; } // 4. Compute the intermediate hash value H(i) hash[0] += a; hash[1] += b; hash[2] += c; hash[3] += d; hash[4] += e; hash[5] += f; hash[6] += g; hash[7] += h; } return(hash.UInt64ArrToUInt8Arr()); }