Example #1
0
 /// <summary>
 /// Initializes a new instance of the <see cref="Vector8ui"/> using the specified vector and values.
 /// </summary>
 /// <param name="value">A vector containing the values with which to initialize the first 4 components</param>
 /// <param name="v4">Value for the V4 component of the vector.</param>
 /// <param name="v5">Value for the V5 component of the vector.</param>
 /// <param name="v6">Value for the V6 component of the vector.</param>
 /// <param name="v7">Value for the V7 component of the vector.</param>
 public Vector8ui(Vector4ui value, uint v4, uint v5, uint v6, uint v7, uint v8, uint v9, uint v10, uint v11)
 {
     V0 = value.X;
     V1 = value.Y;
     V2 = value.Z;
     V3 = value.W;
     V4 = v4;
     V5 = v5;
     V6 = v6;
     V7 = v7;
 }
Example #2
0
 /* Decodes input (unsigned char) into output (UINT4). Assumes len is
  * a multiple of 4. */
 private static void Decode(Vector4ui[] output,
                            byte[] input,
                            uint inputIndex,
                            uint len)
 {
     for (uint i = 0, j = 0; j < len; i++, j += 4)
     {
         output[i] = new Vector4ui(((uint)input[inputIndex + j]) |
                                   (((uint)input[inputIndex + j + 1]) << 8) |
                                   (((uint)input[inputIndex + j + 2]) << 16) |
                                   (((uint)input[inputIndex + j + 3]) << 24));
     }
 }
Example #3
0
        /* MD5 basic transformation. Transforms state based on block. */
        private static void MD5Transform(Vector4ui[] state,
                                         byte[] block,
                                         uint blockIndex)
        {
            Vector4ui a = state[0], b = state[1], c = state[2], d = state[3];

            Vector4ui[] x = new Vector4ui[16];

            Decode(x, block, blockIndex, 64);

            /* Round 1 */
            FF(ref a, b, c, d, x[0], S11, 0xd76aa478);             /* 1 */
            FF(ref d, a, b, c, x[1], S12, 0xe8c7b756);             /* 2 */
            FF(ref c, d, a, b, x[2], S13, 0x242070db);             /* 3 */
            FF(ref b, c, d, a, x[3], S14, 0xc1bdceee);             /* 4 */
            FF(ref a, b, c, d, x[4], S11, 0xf57c0faf);             /* 5 */
            FF(ref d, a, b, c, x[5], S12, 0x4787c62a);             /* 6 */
            FF(ref c, d, a, b, x[6], S13, 0xa8304613);             /* 7 */
            FF(ref b, c, d, a, x[7], S14, 0xfd469501);             /* 8 */
            FF(ref a, b, c, d, x[8], S11, 0x698098d8);             /* 9 */
            FF(ref d, a, b, c, x[9], S12, 0x8b44f7af);             /* 10 */
            FF(ref c, d, a, b, x[10], S13, 0xffff5bb1);            /* 11 */
            FF(ref b, c, d, a, x[11], S14, 0x895cd7be);            /* 12 */
            FF(ref a, b, c, d, x[12], S11, 0x6b901122);            /* 13 */
            FF(ref d, a, b, c, x[13], S12, 0xfd987193);            /* 14 */
            FF(ref c, d, a, b, x[14], S13, 0xa679438e);            /* 15 */
            FF(ref b, c, d, a, x[15], S14, 0x49b40821);            /* 16 */

            /* Round 2 */
            GG(ref a, b, c, d, x[1], S21, 0xf61e2562);             /* 17 */
            GG(ref d, a, b, c, x[6], S22, 0xc040b340);             /* 18 */
            GG(ref c, d, a, b, x[11], S23, 0x265e5a51);            /* 19 */
            GG(ref b, c, d, a, x[0], S24, 0xe9b6c7aa);             /* 20 */
            GG(ref a, b, c, d, x[5], S21, 0xd62f105d);             /* 21 */
            GG(ref d, a, b, c, x[10], S22, 0x02441453);            /* 22 */
            GG(ref c, d, a, b, x[15], S23, 0xd8a1e681);            /* 23 */
            GG(ref b, c, d, a, x[4], S24, 0xe7d3fbc8);             /* 24 */
            GG(ref a, b, c, d, x[9], S21, 0x21e1cde6);             /* 25 */
            GG(ref d, a, b, c, x[14], S22, 0xc33707d6);            /* 26 */
            GG(ref c, d, a, b, x[3], S23, 0xf4d50d87);             /* 27 */
            GG(ref b, c, d, a, x[8], S24, 0x455a14ed);             /* 28 */
            GG(ref a, b, c, d, x[13], S21, 0xa9e3e905);            /* 29 */
            GG(ref d, a, b, c, x[2], S22, 0xfcefa3f8);             /* 30 */
            GG(ref c, d, a, b, x[7], S23, 0x676f02d9);             /* 31 */
            GG(ref b, c, d, a, x[12], S24, 0x8d2a4c8a);            /* 32 */

            /* Round 3 */
            HH(ref a, b, c, d, x[5], S31, 0xfffa3942);             /* 33 */
            HH(ref d, a, b, c, x[8], S32, 0x8771f681);             /* 34 */
            HH(ref c, d, a, b, x[11], S33, 0x6d9d6122);            /* 35 */
            HH(ref b, c, d, a, x[14], S34, 0xfde5380c);            /* 36 */
            HH(ref a, b, c, d, x[1], S31, 0xa4beea44);             /* 37 */
            HH(ref d, a, b, c, x[4], S32, 0x4bdecfa9);             /* 38 */
            HH(ref c, d, a, b, x[7], S33, 0xf6bb4b60);             /* 39 */
            HH(ref b, c, d, a, x[10], S34, 0xbebfbc70);            /* 40 */
            HH(ref a, b, c, d, x[13], S31, 0x289b7ec6);            /* 41 */
            HH(ref d, a, b, c, x[0], S32, 0xeaa127fa);             /* 42 */
            HH(ref c, d, a, b, x[3], S33, 0xd4ef3085);             /* 43 */
            HH(ref b, c, d, a, x[6], S34, 0x04881d05);             /* 44 */
            HH(ref a, b, c, d, x[9], S31, 0xd9d4d039);             /* 45 */
            HH(ref d, a, b, c, x[12], S32, 0xe6db99e5);            /* 46 */
            HH(ref c, d, a, b, x[15], S33, 0x1fa27cf8);            /* 47 */
            HH(ref b, c, d, a, x[2], S34, 0xc4ac5665);             /* 48 */

            /* Round 4 */
            II(ref a, b, c, d, x[0], S41, 0xf4292244);             /* 49 */
            II(ref d, a, b, c, x[7], S42, 0x432aff97);             /* 50 */
            II(ref c, d, a, b, x[14], S43, 0xab9423a7);            /* 51 */
            II(ref b, c, d, a, x[5], S44, 0xfc93a039);             /* 52 */
            II(ref a, b, c, d, x[12], S41, 0x655b59c3);            /* 53 */
            II(ref d, a, b, c, x[3], S42, 0x8f0ccc92);             /* 54 */
            II(ref c, d, a, b, x[10], S43, 0xffeff47d);            /* 55 */
            II(ref b, c, d, a, x[1], S44, 0x85845dd1);             /* 56 */
            II(ref a, b, c, d, x[8], S41, 0x6fa87e4f);             /* 57 */
            II(ref d, a, b, c, x[15], S42, 0xfe2ce6e0);            /* 58 */
            II(ref c, d, a, b, x[6], S43, 0xa3014314);             /* 59 */
            II(ref b, c, d, a, x[13], S44, 0x4e0811a1);            /* 60 */
            II(ref a, b, c, d, x[4], S41, 0xf7537e82);             /* 61 */
            II(ref d, a, b, c, x[11], S42, 0xbd3af235);            /* 62 */
            II(ref c, d, a, b, x[2], S43, 0x2ad7d2bb);             /* 63 */
            II(ref b, c, d, a, x[9], S44, 0xeb86d391);             /* 64 */

            state[0] += a;
            state[1] += b;
            state[2] += c;
            state[3] += d;

            /* Zeroize sensitive information. */
            Array.Clear(x, 0, x.Length);
        }
Example #4
0
 private static void II(ref Vector4ui a, Vector4ui b, Vector4ui c, Vector4ui d, Vector4ui x, int s, uint ac)
 {
     (a) += I((b), (c), (d)) + (x) + new Vector4ui(ac);
     (a)  = ROTATE_LEFT((a), (s));
     (a) += (b);
 }
Example #5
0
 /* ROTATE_LEFT rotates x left n bits. */
 private static Vector4ui ROTATE_LEFT(Vector4ui x, int n)
 {
     return(new Vector4ui(((x[0]) << (n)) | ((x[0]) >> (32 - (n)))));
 }
Example #6
0
 private static Vector4ui I(Vector4ui x, Vector4ui y, Vector4ui z)
 {
     return((y) ^ ((x) | (new Vector4ui(~z.X))));
 }
Example #7
0
 private static Vector4ui H(Vector4ui x, Vector4ui y, Vector4ui z)
 {
     return((x) ^ (y) ^ (z));
 }
Example #8
0
 private static Vector4ui G(Vector4ui x, Vector4ui y, Vector4ui z)
 {
     return(y ^ (z & (x ^ y)));
 }
Example #9
0
 /* F, G, H and I are basic MD5 functions. */
 private static Vector4ui F(Vector4ui x, Vector4ui y, Vector4ui z)
 {
     return(z ^ (x & (y ^ z)));
 }
Example #10
0
 /// <summary>Read an array of <c>Vector4ui</c> values.</summary>
 public static Vector4ui[] ReadArrayVector4ui(this BinaryReader reader, int count)
 {
     Vector4ui[] array = new Vector4ui[count]; reader.ReadArray(array, 0, count); return array;
 }
Example #11
0
 /// <summary>Read a <see cref="Vector4ui"/>.</summary>
 public static void ReadVector4ui(this BinaryReader reader , out Vector4ui result)
 {
     result.X = reader.ReadUInt32();
                                 result.Y = reader.ReadUInt32();
                                 result.Z = reader.ReadUInt32();
                                 result.W = reader.ReadUInt32();
             return;
 }
 static unsafe void FromUInt32(int first, int count, IList<Vector4ui> data)
 {
     for(int index = 0; index < count; index++)data[first + index] = new Vector4ui((uint)( *((System.UInt32*)list.ToPointer() + (index + 0) * 4 * 4) ), (uint)( *((System.UInt32*)list.ToPointer() + (index + 1) * 4 * 4) ), (uint)( *((System.UInt32*)list.ToPointer() + (index + 2) * 4 * 4) ), (uint)( *((System.UInt32*)list.ToPointer() + (index + 3) * 4 * 4) ));
 }
 static unsafe void FromBoolean(int first, int count, IList<Vector4ui> data)
 {
     for(int index = 0; index < count; index++)data[first + index] = new Vector4ui((uint)( Marshal.ReadInt32(list, (index + 0) * 4 * 4 * 4) != 0 ? 1 : 0 ), (uint)( Marshal.ReadInt32(list, (index + 1) * 4 * 4 * 4) != 0 ? 1 : 0 ), (uint)( Marshal.ReadInt32(list, (index + 2) * 4 * 4 * 4) != 0 ? 1 : 0 ), (uint)( Marshal.ReadInt32(list, (index + 3) * 4 * 4 * 4) != 0 ? 1 : 0 ));
 }
 public void Set(ref Vector4ui value)
 {
     unsafe { fixed(Vector4ui* pointer = &value) Set4(1, (uint*)pointer); }
 }
 public void Set(Vector4ui value)
 {
     unsafe { Set4(1, (uint*)&value); }
 }