|
|
@ -1,8 +1,6 @@ |
|
|
|
namespace WhiteRabbit |
|
|
|
namespace WhiteRabbit |
|
|
|
{ |
|
|
|
{ |
|
|
|
using System; |
|
|
|
using System.Numerics; |
|
|
|
using System.Linq; |
|
|
|
|
|
|
|
using System.Reflection; |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
/** |
|
|
|
/** |
|
|
|
* Code taken from BouncyCastle and optimized for specific constraints (e.g. input is always larger than 4 bytes and smaller than 52 bytes). |
|
|
|
* Code taken from BouncyCastle and optimized for specific constraints (e.g. input is always larger than 4 bytes and smaller than 52 bytes). |
|
|
@ -13,89 +11,240 @@ |
|
|
|
*/ |
|
|
|
*/ |
|
|
|
internal static class MD5Digest |
|
|
|
internal static class MD5Digest |
|
|
|
{ |
|
|
|
{ |
|
|
|
public static unsafe uint[] Compute(Phrase input) |
|
|
|
private static readonly Vector<uint> K1 = new Vector<uint>(0xd76aa478); |
|
|
|
|
|
|
|
private static readonly Vector<uint> K2 = new Vector<uint>(0xe8c7b756); |
|
|
|
|
|
|
|
private static readonly Vector<uint> K3 = new Vector<uint>(0x242070db); |
|
|
|
|
|
|
|
private static readonly Vector<uint> K4 = new Vector<uint>(0xc1bdceee); |
|
|
|
|
|
|
|
private static readonly Vector<uint> K5 = new Vector<uint>(0xf57c0faf); |
|
|
|
|
|
|
|
private static readonly Vector<uint> K6 = new Vector<uint>(0x4787c62a); |
|
|
|
|
|
|
|
private static readonly Vector<uint> K7 = new Vector<uint>(0xa8304613); |
|
|
|
|
|
|
|
private static readonly Vector<uint> K8 = new Vector<uint>(0xfd469501); |
|
|
|
|
|
|
|
private static readonly Vector<uint> K9 = new Vector<uint>(0x698098d8); |
|
|
|
|
|
|
|
private static readonly Vector<uint> K10 = new Vector<uint>(0x8b44f7af); |
|
|
|
|
|
|
|
private static readonly Vector<uint> K11 = new Vector<uint>(0xffff5bb1); |
|
|
|
|
|
|
|
private static readonly Vector<uint> K12 = new Vector<uint>(0x895cd7be); |
|
|
|
|
|
|
|
private static readonly Vector<uint> K13 = new Vector<uint>(0x6b901122); |
|
|
|
|
|
|
|
private static readonly Vector<uint> K14 = new Vector<uint>(0xfd987193); |
|
|
|
|
|
|
|
private static readonly Vector<uint> K15 = new Vector<uint>(0xa679438e); |
|
|
|
|
|
|
|
private static readonly Vector<uint> K16 = new Vector<uint>(0x49b40821); |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
private static readonly Vector<uint> K17 = new Vector<uint>(0xf61e2562); |
|
|
|
|
|
|
|
private static readonly Vector<uint> K18 = new Vector<uint>(0xc040b340); |
|
|
|
|
|
|
|
private static readonly Vector<uint> K19 = new Vector<uint>(0x265e5a51); |
|
|
|
|
|
|
|
private static readonly Vector<uint> K20 = new Vector<uint>(0xe9b6c7aa); |
|
|
|
|
|
|
|
private static readonly Vector<uint> K21 = new Vector<uint>(0xd62f105d); |
|
|
|
|
|
|
|
private static readonly Vector<uint> K22 = new Vector<uint>(0x2441453); |
|
|
|
|
|
|
|
private static readonly Vector<uint> K23 = new Vector<uint>(0xd8a1e681); |
|
|
|
|
|
|
|
private static readonly Vector<uint> K24 = new Vector<uint>(0xe7d3fbc8); |
|
|
|
|
|
|
|
private static readonly Vector<uint> K25 = new Vector<uint>(0x21e1cde6); |
|
|
|
|
|
|
|
private static readonly Vector<uint> K26 = new Vector<uint>(0xc33707d6); |
|
|
|
|
|
|
|
private static readonly Vector<uint> K27 = new Vector<uint>(0xf4d50d87); |
|
|
|
|
|
|
|
private static readonly Vector<uint> K28 = new Vector<uint>(0x455a14ed); |
|
|
|
|
|
|
|
private static readonly Vector<uint> K29 = new Vector<uint>(0xa9e3e905); |
|
|
|
|
|
|
|
private static readonly Vector<uint> K30 = new Vector<uint>(0xfcefa3f8); |
|
|
|
|
|
|
|
private static readonly Vector<uint> K31 = new Vector<uint>(0x676f02d9); |
|
|
|
|
|
|
|
private static readonly Vector<uint> K32 = new Vector<uint>(0x8d2a4c8a); |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
private static readonly Vector<uint> K33 = new Vector<uint>(0xfffa3942); |
|
|
|
|
|
|
|
private static readonly Vector<uint> K34 = new Vector<uint>(0x8771f681); |
|
|
|
|
|
|
|
private static readonly Vector<uint> K35 = new Vector<uint>(0x6d9d6122); |
|
|
|
|
|
|
|
private static readonly Vector<uint> K36 = new Vector<uint>(0xfde5380c); |
|
|
|
|
|
|
|
private static readonly Vector<uint> K37 = new Vector<uint>(0xa4beea44); |
|
|
|
|
|
|
|
private static readonly Vector<uint> K38 = new Vector<uint>(0x4bdecfa9); |
|
|
|
|
|
|
|
private static readonly Vector<uint> K39 = new Vector<uint>(0xf6bb4b60); |
|
|
|
|
|
|
|
private static readonly Vector<uint> K40 = new Vector<uint>(0xbebfbc70); |
|
|
|
|
|
|
|
private static readonly Vector<uint> K41 = new Vector<uint>(0x289b7ec6); |
|
|
|
|
|
|
|
private static readonly Vector<uint> K42 = new Vector<uint>(0xeaa127fa); |
|
|
|
|
|
|
|
private static readonly Vector<uint> K43 = new Vector<uint>(0xd4ef3085); |
|
|
|
|
|
|
|
private static readonly Vector<uint> K44 = new Vector<uint>(0x4881d05); |
|
|
|
|
|
|
|
private static readonly Vector<uint> K45 = new Vector<uint>(0xd9d4d039); |
|
|
|
|
|
|
|
private static readonly Vector<uint> K46 = new Vector<uint>(0xe6db99e5); |
|
|
|
|
|
|
|
private static readonly Vector<uint> K47 = new Vector<uint>(0x1fa27cf8); |
|
|
|
|
|
|
|
private static readonly Vector<uint> K48 = new Vector<uint>(0xc4ac5665); |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
private static readonly Vector<uint> K49 = new Vector<uint>(0xf4292244); |
|
|
|
|
|
|
|
private static readonly Vector<uint> K50 = new Vector<uint>(0x432aff97); |
|
|
|
|
|
|
|
private static readonly Vector<uint> K51 = new Vector<uint>(0xab9423a7); |
|
|
|
|
|
|
|
private static readonly Vector<uint> K52 = new Vector<uint>(0xfc93a039); |
|
|
|
|
|
|
|
private static readonly Vector<uint> K53 = new Vector<uint>(0x655b59c3); |
|
|
|
|
|
|
|
private static readonly Vector<uint> K54 = new Vector<uint>(0x8f0ccc92); |
|
|
|
|
|
|
|
private static readonly Vector<uint> K55 = new Vector<uint>(0xffeff47d); |
|
|
|
|
|
|
|
private static readonly Vector<uint> K56 = new Vector<uint>(0x85845dd1); |
|
|
|
|
|
|
|
private static readonly Vector<uint> K57 = new Vector<uint>(0x6fa87e4f); |
|
|
|
|
|
|
|
private static readonly Vector<uint> K58 = new Vector<uint>(0xfe2ce6e0); |
|
|
|
|
|
|
|
private static readonly Vector<uint> K59 = new Vector<uint>(0xa3014314); |
|
|
|
|
|
|
|
private static readonly Vector<uint> K60 = new Vector<uint>(0x4e0811a1); |
|
|
|
|
|
|
|
private static readonly Vector<uint> K61 = new Vector<uint>(0xf7537e82); |
|
|
|
|
|
|
|
private static readonly Vector<uint> K62 = new Vector<uint>(0xbd3af235); |
|
|
|
|
|
|
|
private static readonly Vector<uint> K63 = new Vector<uint>(0x2ad7d2bb); |
|
|
|
|
|
|
|
private static readonly Vector<uint> K64 = new Vector<uint>(0xeb86d391); |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
private static readonly Vector<uint> A0 = new Vector<uint>(0x67452301); |
|
|
|
|
|
|
|
private static readonly Vector<uint> B0 = new Vector<uint>(0xefcdab89); |
|
|
|
|
|
|
|
private static readonly Vector<uint> C0 = new Vector<uint>(0x98badcfe); |
|
|
|
|
|
|
|
private static readonly Vector<uint> D0 = new Vector<uint>(0x10325476); |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
public static unsafe PhrasesHashesChunk Compute(PhrasesChunk input) |
|
|
|
{ |
|
|
|
{ |
|
|
|
var xUints = stackalloc uint[8]; // it seems that alignment helps |
|
|
|
var initialUints = stackalloc uint[32]; |
|
|
|
*(long*)xUints = *(long*)input.Buffer; |
|
|
|
*(long*)(initialUints + 0 * 2) = *(long*)(input.Buffers + 0 * 8); |
|
|
|
*(long*)(xUints + 2) = *(long*)(input.Buffer + 8); |
|
|
|
*(long*)(initialUints + 1 * 2) = *(long*)(input.Buffers + 1 * 8); |
|
|
|
*(long*)(xUints + 4) = *(long*)(input.Buffer + 16); |
|
|
|
*(long*)(initialUints + 2 * 2) = *(long*)(input.Buffers + 2 * 8); |
|
|
|
*(long*)(xUints + 6) = *(long*)(input.Buffer + 24); |
|
|
|
*(long*)(initialUints + 3 * 2) = *(long*)(input.Buffers + 3 * 8); |
|
|
|
((byte*)xUints)[31] = 0; |
|
|
|
*(long*)(initialUints + 4 * 2) = *(long*)(input.Buffers + 4 * 8); |
|
|
|
((byte*)xUints)[input.Buffer[31]] = 128; |
|
|
|
*(long*)(initialUints + 5 * 2) = *(long*)(input.Buffers + 5 * 8); |
|
|
|
xUints[7] = (uint)(input.Buffer[31] << 3); |
|
|
|
*(long*)(initialUints + 6 * 2) = *(long*)(input.Buffers + 6 * 8); |
|
|
|
|
|
|
|
*(long*)(initialUints + 7 * 2) = *(long*)(input.Buffers + 7 * 8); |
|
|
|
uint a = 0x67452301; |
|
|
|
*(long*)(initialUints + 8 * 2) = *(long*)(input.Buffers + 8 * 8); |
|
|
|
uint b = 0xefcdab89; |
|
|
|
*(long*)(initialUints + 9 * 2) = *(long*)(input.Buffers + 9 * 8); |
|
|
|
uint c = 0x98badcfe; |
|
|
|
*(long*)(initialUints + 10 * 2) = *(long*)(input.Buffers + 10 * 8); |
|
|
|
uint d = 0x10325476; |
|
|
|
*(long*)(initialUints + 11 * 2) = *(long*)(input.Buffers + 11 * 8); |
|
|
|
|
|
|
|
*(long*)(initialUints + 12 * 2) = *(long*)(input.Buffers + 12 * 8); |
|
|
|
a = LeftRotate(xUints[0] + 0xd76aa478 + a + ((b & c) | (~b & d)), 7, 32 - 7) + b; |
|
|
|
*(long*)(initialUints + 13 * 2) = *(long*)(input.Buffers + 13 * 8); |
|
|
|
d = LeftRotate(xUints[1] + 0xe8c7b756 + d + ((a & b) | (~a & c)), 12, 32 - 12) + a; |
|
|
|
*(long*)(initialUints + 14 * 2) = *(long*)(input.Buffers + 14 * 8); |
|
|
|
c = LeftRotate(xUints[2] + 0x242070db + c + ((d & a) | (~d & b)), 17, 32 - 17) + d; |
|
|
|
*(long*)(initialUints + 15 * 2) = *(long*)(input.Buffers + 15 * 8); |
|
|
|
b = LeftRotate(xUints[3] + 0xc1bdceee + b + ((c & d) | (~c & a)), 22, 32 - 22) + c; |
|
|
|
|
|
|
|
a = LeftRotate(xUints[4] + 0xf57c0faf + a + ((b & c) | (~b & d)), 7, 32 - 7) + b; |
|
|
|
((byte*)initialUints)[31 + 0 * 32] = 0; |
|
|
|
d = LeftRotate(xUints[5] + 0x4787c62a + d + ((a & b) | (~a & c)), 12, 32 - 12) + a; |
|
|
|
((byte*)initialUints)[31 + 1 * 32] = 0; |
|
|
|
c = LeftRotate(xUints[6] + 0xa8304613 + c + ((d & a) | (~d & b)), 17, 32 - 17) + d; |
|
|
|
((byte*)initialUints)[31 + 2 * 32] = 0; |
|
|
|
b = LeftRotate(0xfd469501 + b + ((c & d) | (~c & a)), 22, 32 - 22) + c; |
|
|
|
((byte*)initialUints)[31 + 3 * 32] = 0; |
|
|
|
a = LeftRotate(0x698098d8 + a + ((b & c) | (~b & d)), 7, 32 - 7) + b; |
|
|
|
((byte*)initialUints)[0 * 32 + input.Buffers[31 + 0 * 32]] = 128; |
|
|
|
d = LeftRotate(0x8b44f7af + d + ((a & b) | (~a & c)), 12, 32 - 12) + a; |
|
|
|
((byte*)initialUints)[1 * 32 + input.Buffers[31 + 1 * 32]] = 128; |
|
|
|
c = LeftRotate(0xffff5bb1 + c + ((d & a) | (~d & b)), 17, 32 - 17) + d; |
|
|
|
((byte*)initialUints)[2 * 32 + input.Buffers[31 + 2 * 32]] = 128; |
|
|
|
b = LeftRotate(0x895cd7be + b + ((c & d) | (~c & a)), 22, 32 - 22) + c; |
|
|
|
((byte*)initialUints)[3 * 32 + input.Buffers[31 + 3 * 32]] = 128; |
|
|
|
a = LeftRotate(0x6b901122 + a + ((b & c) | (~b & d)), 7, 32 - 7) + b; |
|
|
|
initialUints[7 + 0 * 8] = (uint)(input.Buffers[31 + 0 * 32] << 3); |
|
|
|
d = LeftRotate(0xfd987193 + d + ((a & b) | (~a & c)), 12, 32 - 12) + a; |
|
|
|
initialUints[7 + 1 * 8] = (uint)(input.Buffers[31 + 1 * 32] << 3); |
|
|
|
c = LeftRotate(xUints[7] + 0xa679438e + c + ((d & a) | (~d & b)), 17, 32 - 17) + d; |
|
|
|
initialUints[7 + 2 * 8] = (uint)(input.Buffers[31 + 2 * 32] << 3); |
|
|
|
b = LeftRotate(0x49b40821 + b + ((c & d) | (~c & a)), 22, 32 - 22) + c; |
|
|
|
initialUints[7 + 3 * 8] = (uint)(input.Buffers[31 + 3 * 32] << 3); |
|
|
|
|
|
|
|
|
|
|
|
a = LeftRotate(xUints[1] + 0xf61e2562 + a + ((b & d) | (c & ~d)), 5, 32 - 5) + b; |
|
|
|
var message0 = new Vector<uint>(new uint[] { |
|
|
|
d = LeftRotate(xUints[6] + 0xc040b340 + d + ((a & c) | (b & ~c)), 9, 32 - 9) + a; |
|
|
|
initialUints[0 + 0 * 8], |
|
|
|
c = LeftRotate(0x265e5a51 + c + ((d & b) | (a & ~b)), 14, 32 - 14) + d; |
|
|
|
initialUints[0 + 1 * 8], |
|
|
|
b = LeftRotate(xUints[0] + 0xe9b6c7aa + b + ((c & a) | (d & ~a)), 20, 32 - 20) + c; |
|
|
|
initialUints[0 + 2 * 8], |
|
|
|
a = LeftRotate(xUints[5] + 0xd62f105d + a + ((b & d) | (c & ~d)), 5, 32 - 5) + b; |
|
|
|
initialUints[0 + 3 * 8], |
|
|
|
d = LeftRotate(0x2441453 + d + ((a & c) | (b & ~c)), 9, 32 - 9) + a; |
|
|
|
}); |
|
|
|
c = LeftRotate(0xd8a1e681 + c + ((d & b) | (a & ~b)), 14, 32 - 14) + d; |
|
|
|
|
|
|
|
b = LeftRotate(xUints[4] + 0xe7d3fbc8 + b + ((c & a) | (d & ~a)), 20, 32 - 20) + c; |
|
|
|
var message1 = new Vector<uint>(new uint[] { |
|
|
|
a = LeftRotate(0x21e1cde6 + a + ((b & d) | (c & ~d)), 5, 32 - 5) + b; |
|
|
|
initialUints[1 + 0 * 8], |
|
|
|
d = LeftRotate(xUints[7] + 0xc33707d6 + d + ((a & c) | (b & ~c)), 9, 32 - 9) + a; |
|
|
|
initialUints[1 + 1 * 8], |
|
|
|
c = LeftRotate(xUints[3] + 0xf4d50d87 + c + ((d & b) | (a & ~b)), 14, 32 - 14) + d; |
|
|
|
initialUints[1 + 2 * 8], |
|
|
|
b = LeftRotate(0x455a14ed + b + ((c & a) | (d & ~a)), 20, 32 - 20) + c; |
|
|
|
initialUints[1 + 3 * 8], |
|
|
|
a = LeftRotate(0xa9e3e905 + a + ((b & d) | (c & ~d)), 5, 32 - 5) + b; |
|
|
|
}); |
|
|
|
d = LeftRotate(xUints[2] + 0xfcefa3f8 + d + ((a & c) | (b & ~c)), 9, 32 - 9) + a; |
|
|
|
|
|
|
|
c = LeftRotate(0x676f02d9 + c + ((d & b) | (a & ~b)), 14, 32 - 14) + d; |
|
|
|
var message2 = new Vector<uint>(new uint[] { |
|
|
|
b = LeftRotate(0x8d2a4c8a + b + ((c & a) | (d & ~a)), 20, 32 - 20) + c; |
|
|
|
initialUints[2 + 0 * 8], |
|
|
|
|
|
|
|
initialUints[2 + 1 * 8], |
|
|
|
a = LeftRotate(xUints[5] + 0xfffa3942 + a + (b ^ c ^ d), 4, 32 - 4) + b; |
|
|
|
initialUints[2 + 2 * 8], |
|
|
|
d = LeftRotate(0x8771f681 + d + (a ^ b ^ c), 11, 32 - 11) + a; |
|
|
|
initialUints[2 + 3 * 8], |
|
|
|
c = LeftRotate(0x6d9d6122 + c + (d ^ a ^ b), 16, 32 - 16) + d; |
|
|
|
}); |
|
|
|
b = LeftRotate(xUints[7] + 0xfde5380c + b + (c ^ d ^ a), 23, 32 - 23) + c; |
|
|
|
|
|
|
|
a = LeftRotate(xUints[1] + 0xa4beea44 + a + (b ^ c ^ d), 4, 32 - 4) + b; |
|
|
|
var message3 = new Vector<uint>(new uint[] { |
|
|
|
d = LeftRotate(xUints[4] + 0x4bdecfa9 + d + (a ^ b ^ c), 11, 32 - 11) + a; |
|
|
|
initialUints[3 + 0 * 8], |
|
|
|
c = LeftRotate(0xf6bb4b60 + c + (d ^ a ^ b), 16, 32 - 16) + d; |
|
|
|
initialUints[3 + 1 * 8], |
|
|
|
b = LeftRotate(0xbebfbc70 + b + (c ^ d ^ a), 23, 32 - 23) + c; |
|
|
|
initialUints[3 + 2 * 8], |
|
|
|
a = LeftRotate(0x289b7ec6 + a + (b ^ c ^ d), 4, 32 - 4) + b; |
|
|
|
initialUints[3 + 3 * 8], |
|
|
|
d = LeftRotate(xUints[0] + 0xeaa127fa + d + (a ^ b ^ c), 11, 32 - 11) + a; |
|
|
|
}); |
|
|
|
c = LeftRotate(xUints[3] + 0xd4ef3085 + c + (d ^ a ^ b), 16, 32 - 16) + d; |
|
|
|
|
|
|
|
b = LeftRotate(xUints[6] + 0x4881d05 + b + (c ^ d ^ a), 23, 32 - 23) + c; |
|
|
|
var message4 = new Vector<uint>(new uint[] { |
|
|
|
a = LeftRotate(0xd9d4d039 + a + (b ^ c ^ d), 4, 32 - 4) + b; |
|
|
|
initialUints[4 + 0 * 8], |
|
|
|
d = LeftRotate(0xe6db99e5 + d + (a ^ b ^ c), 11, 32 - 11) + a; |
|
|
|
initialUints[4 + 1 * 8], |
|
|
|
c = LeftRotate(0x1fa27cf8 + c + (d ^ a ^ b), 16, 32 - 16) + d; |
|
|
|
initialUints[4 + 2 * 8], |
|
|
|
b = LeftRotate(xUints[2] + 0xc4ac5665 + b + (c ^ d ^ a), 23, 32 - 23) + c; |
|
|
|
initialUints[4 + 3 * 8], |
|
|
|
|
|
|
|
}); |
|
|
|
a = LeftRotate(xUints[0] + 0xf4292244 + a + (c ^ (b | ~d)), 6, 32 - 6) + b; |
|
|
|
|
|
|
|
d = LeftRotate(0x432aff97 + d + (b ^ (a | ~c)), 10, 32 - 10) + a; |
|
|
|
var message5 = new Vector<uint>(new uint[] { |
|
|
|
c = LeftRotate(xUints[7] + 0xab9423a7 + c + (a ^ (d | ~b)), 15, 32 - 15) + d; |
|
|
|
initialUints[5 + 0 * 8], |
|
|
|
b = LeftRotate(xUints[5] + 0xfc93a039 + b + (d ^ (c | ~a)), 21, 32 - 21) + c; |
|
|
|
initialUints[5 + 1 * 8], |
|
|
|
a = LeftRotate(0x655b59c3 + a + (c ^ (b | ~d)), 6, 32 - 6) + b; |
|
|
|
initialUints[5 + 2 * 8], |
|
|
|
d = LeftRotate(xUints[3] + 0x8f0ccc92 + d + (b ^ (a | ~c)), 10, 32 - 10) + a; |
|
|
|
initialUints[5 + 3 * 8], |
|
|
|
c = LeftRotate(0xffeff47d + c + (a ^ (d | ~b)), 15, 32 - 15) + d; |
|
|
|
}); |
|
|
|
b = LeftRotate(xUints[1] + 0x85845dd1 + b + (d ^ (c | ~a)), 21, 32 - 21) + c; |
|
|
|
|
|
|
|
a = LeftRotate(0x6fa87e4f + a + (c ^ (b | ~d)), 6, 32 - 6) + b; |
|
|
|
var message6 = new Vector<uint>(new uint[] { |
|
|
|
d = LeftRotate(0xfe2ce6e0 + d + (b ^ (a | ~c)), 10, 32 - 10) + a; |
|
|
|
initialUints[6 + 0 * 8], |
|
|
|
c = LeftRotate(xUints[6] + 0xa3014314 + c + (a ^ (d | ~b)), 15, 32 - 15) + d; |
|
|
|
initialUints[6 + 1 * 8], |
|
|
|
b = LeftRotate(0x4e0811a1 + b + (d ^ (c | ~a)), 21, 32 - 21) + c; |
|
|
|
initialUints[6 + 2 * 8], |
|
|
|
a = LeftRotate(xUints[4] + 0xf7537e82 + a + (c ^ (b | ~d)), 6, 32 - 6) + b; |
|
|
|
initialUints[6 + 3 * 8], |
|
|
|
d = LeftRotate(0xbd3af235 + d + (b ^ (a | ~c)), 10, 32 - 10) + a; |
|
|
|
}); |
|
|
|
c = LeftRotate(xUints[2] + 0x2ad7d2bb + c + (a ^ (d | ~b)), 15, 32 - 15) + d; |
|
|
|
|
|
|
|
b = LeftRotate(0xeb86d391 + b + (d ^ (c | ~a)), 21, 32 - 21) + c; |
|
|
|
var message7 = new Vector<uint>(new uint[] { |
|
|
|
|
|
|
|
initialUints[7 + 0 * 8], |
|
|
|
|
|
|
|
initialUints[7 + 1 * 8], |
|
|
|
|
|
|
|
initialUints[7 + 2 * 8], |
|
|
|
|
|
|
|
initialUints[7 + 3 * 8], |
|
|
|
|
|
|
|
}); |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
var a = A0; |
|
|
|
|
|
|
|
var b = B0; |
|
|
|
|
|
|
|
var c = C0; |
|
|
|
|
|
|
|
var d = D0; |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
a = LeftRotate(message0 + K1 + a + ((b & c) | (~b & d)), 7, 32 - 7) + b; |
|
|
|
|
|
|
|
d = LeftRotate(message1 + K2 + d + ((a & b) | (~a & c)), 12, 32 - 12) + a; |
|
|
|
|
|
|
|
c = LeftRotate(message2 + K3 + c + ((d & a) | (~d & b)), 17, 32 - 17) + d; |
|
|
|
|
|
|
|
b = LeftRotate(message3 + K4 + b + ((c & d) | (~c & a)), 22, 32 - 22) + c; |
|
|
|
|
|
|
|
a = LeftRotate(message4 + K5 + a + ((b & c) | (~b & d)), 7, 32 - 7) + b; |
|
|
|
|
|
|
|
d = LeftRotate(message5 + K6 + d + ((a & b) | (~a & c)), 12, 32 - 12) + a; |
|
|
|
|
|
|
|
c = LeftRotate(message6 + K7 + c + ((d & a) | (~d & b)), 17, 32 - 17) + d; |
|
|
|
|
|
|
|
b = LeftRotate(K8 + b + ((c & d) | (~c & a)), 22, 32 - 22) + c; |
|
|
|
|
|
|
|
a = LeftRotate(K9 + a + ((b & c) | (~b & d)), 7, 32 - 7) + b; |
|
|
|
|
|
|
|
d = LeftRotate(K10 + d + ((a & b) | (~a & c)), 12, 32 - 12) + a; |
|
|
|
|
|
|
|
c = LeftRotate(K11 + c + ((d & a) | (~d & b)), 17, 32 - 17) + d; |
|
|
|
|
|
|
|
b = LeftRotate(K12 + b + ((c & d) | (~c & a)), 22, 32 - 22) + c; |
|
|
|
|
|
|
|
a = LeftRotate(K13 + a + ((b & c) | (~b & d)), 7, 32 - 7) + b; |
|
|
|
|
|
|
|
d = LeftRotate(K14 + d + ((a & b) | (~a & c)), 12, 32 - 12) + a; |
|
|
|
|
|
|
|
c = LeftRotate(message7 + K15 + c + ((d & a) | (~d & b)), 17, 32 - 17) + d; |
|
|
|
|
|
|
|
b = LeftRotate(K16 + b + ((c & d) | (~c & a)), 22, 32 - 22) + c; |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
a = LeftRotate(message1 + K17 + a + ((b & d) | (c & ~d)), 5, 32 - 5) + b; |
|
|
|
|
|
|
|
d = LeftRotate(message6 + K18 + d + ((a & c) | (b & ~c)), 9, 32 - 9) + a; |
|
|
|
|
|
|
|
c = LeftRotate(K19 + c + ((d & b) | (a & ~b)), 14, 32 - 14) + d; |
|
|
|
|
|
|
|
b = LeftRotate(message0 + K20 + b + ((c & a) | (d & ~a)), 20, 32 - 20) + c; |
|
|
|
|
|
|
|
a = LeftRotate(message5 + K21 + a + ((b & d) | (c & ~d)), 5, 32 - 5) + b; |
|
|
|
|
|
|
|
d = LeftRotate(K22 + d + ((a & c) | (b & ~c)), 9, 32 - 9) + a; |
|
|
|
|
|
|
|
c = LeftRotate(K23 + c + ((d & b) | (a & ~b)), 14, 32 - 14) + d; |
|
|
|
|
|
|
|
b = LeftRotate(message4 + K24 + b + ((c & a) | (d & ~a)), 20, 32 - 20) + c; |
|
|
|
|
|
|
|
a = LeftRotate(K25 + a + ((b & d) | (c & ~d)), 5, 32 - 5) + b; |
|
|
|
|
|
|
|
d = LeftRotate(message7 + K26 + d + ((a & c) | (b & ~c)), 9, 32 - 9) + a; |
|
|
|
|
|
|
|
c = LeftRotate(message3 + K27 + c + ((d & b) | (a & ~b)), 14, 32 - 14) + d; |
|
|
|
|
|
|
|
b = LeftRotate(K28 + b + ((c & a) | (d & ~a)), 20, 32 - 20) + c; |
|
|
|
|
|
|
|
a = LeftRotate(K29 + a + ((b & d) | (c & ~d)), 5, 32 - 5) + b; |
|
|
|
|
|
|
|
d = LeftRotate(message2 + K30 + d + ((a & c) | (b & ~c)), 9, 32 - 9) + a; |
|
|
|
|
|
|
|
c = LeftRotate(K31 + c + ((d & b) | (a & ~b)), 14, 32 - 14) + d; |
|
|
|
|
|
|
|
b = LeftRotate(K32 + b + ((c & a) | (d & ~a)), 20, 32 - 20) + c; |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
a = LeftRotate(message5 + K33 + a + (b ^ c ^ d), 4, 32 - 4) + b; |
|
|
|
|
|
|
|
d = LeftRotate(K34 + d + (a ^ b ^ c), 11, 32 - 11) + a; |
|
|
|
|
|
|
|
c = LeftRotate(K35 + c + (d ^ a ^ b), 16, 32 - 16) + d; |
|
|
|
|
|
|
|
b = LeftRotate(message7 + K36 + b + (c ^ d ^ a), 23, 32 - 23) + c; |
|
|
|
|
|
|
|
a = LeftRotate(message1 + K37 + a + (b ^ c ^ d), 4, 32 - 4) + b; |
|
|
|
|
|
|
|
d = LeftRotate(message4 + K38 + d + (a ^ b ^ c), 11, 32 - 11) + a; |
|
|
|
|
|
|
|
c = LeftRotate(K39 + c + (d ^ a ^ b), 16, 32 - 16) + d; |
|
|
|
|
|
|
|
b = LeftRotate(K40 + b + (c ^ d ^ a), 23, 32 - 23) + c; |
|
|
|
|
|
|
|
a = LeftRotate(K41 + a + (b ^ c ^ d), 4, 32 - 4) + b; |
|
|
|
|
|
|
|
d = LeftRotate(message0 + K42 + d + (a ^ b ^ c), 11, 32 - 11) + a; |
|
|
|
|
|
|
|
c = LeftRotate(message3 + K43 + c + (d ^ a ^ b), 16, 32 - 16) + d; |
|
|
|
|
|
|
|
b = LeftRotate(message6 + K44 + b + (c ^ d ^ a), 23, 32 - 23) + c; |
|
|
|
|
|
|
|
a = LeftRotate(K45 + a + (b ^ c ^ d), 4, 32 - 4) + b; |
|
|
|
|
|
|
|
d = LeftRotate(K46 + d + (a ^ b ^ c), 11, 32 - 11) + a; |
|
|
|
|
|
|
|
c = LeftRotate(K47 + c + (d ^ a ^ b), 16, 32 - 16) + d; |
|
|
|
|
|
|
|
b = LeftRotate(message2 + K48 + b + (c ^ d ^ a), 23, 32 - 23) + c; |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
a = LeftRotate(message0 + K49 + a + (c ^ (b | ~d)), 6, 32 - 6) + b; |
|
|
|
|
|
|
|
d = LeftRotate(K50 + d + (b ^ (a | ~c)), 10, 32 - 10) + a; |
|
|
|
|
|
|
|
c = LeftRotate(message7 + K51 + c + (a ^ (d | ~b)), 15, 32 - 15) + d; |
|
|
|
|
|
|
|
b = LeftRotate(message5 + K52 + b + (d ^ (c | ~a)), 21, 32 - 21) + c; |
|
|
|
|
|
|
|
a = LeftRotate(K53 + a + (c ^ (b | ~d)), 6, 32 - 6) + b; |
|
|
|
|
|
|
|
d = LeftRotate(message3 + K54 + d + (b ^ (a | ~c)), 10, 32 - 10) + a; |
|
|
|
|
|
|
|
c = LeftRotate(K55 + c + (a ^ (d | ~b)), 15, 32 - 15) + d; |
|
|
|
|
|
|
|
b = LeftRotate(message1 + K56 + b + (d ^ (c | ~a)), 21, 32 - 21) + c; |
|
|
|
|
|
|
|
a = LeftRotate(K57 + a + (c ^ (b | ~d)), 6, 32 - 6) + b; |
|
|
|
|
|
|
|
d = LeftRotate(K58 + d + (b ^ (a | ~c)), 10, 32 - 10) + a; |
|
|
|
|
|
|
|
c = LeftRotate(message6 + K59 + c + (a ^ (d | ~b)), 15, 32 - 15) + d; |
|
|
|
|
|
|
|
b = LeftRotate(K60 + b + (d ^ (c | ~a)), 21, 32 - 21) + c; |
|
|
|
|
|
|
|
a = LeftRotate(message4 + K61 + a + (c ^ (b | ~d)), 6, 32 - 6) + b; |
|
|
|
|
|
|
|
d = LeftRotate(K62 + d + (b ^ (a | ~c)), 10, 32 - 10) + a; |
|
|
|
|
|
|
|
c = LeftRotate(message2 + K63 + c + (a ^ (d | ~b)), 15, 32 - 15) + d; |
|
|
|
|
|
|
|
b = LeftRotate(K64 + b + (d ^ (c | ~a)), 21, 32 - 21) + c; |
|
|
|
|
|
|
|
|
|
|
|
return new[] |
|
|
|
return new[] |
|
|
|
{ |
|
|
|
{ |
|
|
@ -106,7 +255,7 @@ |
|
|
|
}; |
|
|
|
}; |
|
|
|
} |
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
private static uint LeftRotate(uint x, int left, int right) |
|
|
|
private static uint LeftRotate(Vector<uint> x, int left, int right) |
|
|
|
{ |
|
|
|
{ |
|
|
|
return (x << left) | (x >> right); |
|
|
|
return (x << left) | (x >> right); |
|
|
|
} |
|
|
|
} |
|
|
|