Exemple #1
0
        protected override void Compress(IQmhHukState hashState, byte[] buffer)
        {
            // Init Message Schedule array (W)
            UInt32[] W = new UInt32[56];
            for (int t = 0, j = 0; t < 16; ++t, j += 4)
            {
                W[t] = (UInt32)((buffer[j] << 24) | (buffer[j + 1] << 16) | (buffer[j + 2] << 8) | (buffer[j + 3]));
            }
            for (int t = 16; t < 56; ++t)
            {
                W[t] = Wsigma1(W[t - 2]) + W[t - 7] + Wsigma0(W[t - 15]) + W[t - 16];
            }

            QmhHuk256State state = (QmhHuk256State)hashState;
            // Init working variables
            UInt32 a = state.H[0];
            UInt32 b = state.H[1];
            UInt32 c = state.H[2];
            UInt32 d = state.H[3];
            UInt32 e = state.H[4];
            UInt32 f = state.H[5];
            UInt32 g = state.H[6];
            UInt32 h = state.H[7];

            // 56 rounds
            for (int r = 0; r < 56; ++r)
            {
                UInt32 T1 = h + Sigma1(e) + Choice(e, f, g) + K[r] + W[r];
                UInt32 T2 = Sigma0(a) + Majority(a, b, c);
                UInt32 T3 = a + Sigma1(d) + Choice(c, b, a) + K[r] + W[r];
                UInt32 T4 = Sigma0(h) + Majority(h, g, f);
                h = g;
                g = f ^ T1;
                f = e;
                e = T3 + T4;
                d = c;
                c = b ^ T3;
                b = a;
                a = T1 + T2;
            }

            // Update hash state
            state.H[0] ^= a;
            state.H[1] ^= b;
            state.H[2] ^= c;
            state.H[3] ^= d;
            state.H[4] ^= e;
            state.H[5] ^= f;
            state.H[6] ^= g;
            state.H[7] ^= h;
        }
Exemple #2
0
        protected override byte[] FinalHash(IQmhHukState hashState)
        {
            var size = 8;

            if (this._bitLen == 224)
            {
                size = 7;
            }
            byte[] result = new byte[size * 4];

            QmhHuk256State state = (QmhHuk256State)hashState;

            for (int h = 0, p = 0; h < size; h++, p += 4)
            {
                var hState = state.H[h];
                result[p + 0] = (byte)(hState >> 24);
                result[p + 1] = (byte)(hState >> 16);
                result[p + 2] = (byte)(hState >> 8);
                result[p + 3] = (byte)(hState);
            }

            return(result);
        }
Exemple #3
0
 /// <summary>
 /// Init hsha state
 /// </summary>
 /// <param name="hashState"></param>
 protected override void InitState(out IQmhHukState hashState)
 {
     if (this._bitLen == 256)
     {
         hashState = new QmhHuk256State()
         {
             H = new UInt32[] { // 419..457
                 0x78307697, 0x84AE4B7C, 0xC2B2B755, 0xCF03D20E,
                 0xF3CBB117, 0x79C450F6, 0x308AF161, 0x60A7A998
             }
         }
     }
     ;
     else
     {
         hashState = new QmhHuk256State()
         {
             H = new UInt32[] { // 461..503
                 0x788D9812, 0x84769B42, 0x9C34F062, 0xE2D564C4,
                 0xAE469BE4, 0x2894C107, 0x569B58C6, 0x6D7B3939
             }
         }
     };
 }