Example #1
0
        private void CompressOneBlock(ReadOnlySpan <byte> block)
        {
            _blockCount += 1;
            Span <uint> w = stackalloc uint[68];

            for (var i = 0; i < 16; i++)
            {
                w[i] = ReadU32Be(block.Slice(i * 4, 4));
            }

            for (var j = 16; j < 68; j++)
            {
                w[j] = P1(w[j - 16] ^ w[j - 9] ^ RotL32(w[j - 3], 15)) ^ RotL32(w[j - 13], 7) ^ w[j - 6];
            }

            Span <uint> wp = stackalloc uint[64];

            for (var j = 0; j < 64; j++)
            {
                wp[j] = w[j] ^ w[j + 4];
            }

            var(a, b, c, d, e, f, g, h) = _state;
            for (var j = 0; j < 64; j++)
            {
                var ss1 = RotL32(RotL32(a, 12) + e + RotL32(T(j), (byte)(j % 32)), 7);
                var ss2 = ss1 ^ RotL32(a, 12);
                var tt1 = FF(j, a, b, c) + d + ss2 + wp[j];
                var tt2 = GG(j, e, f, g) + h + ss1 + w[j];
                d = c;
                c = RotL32(b, 9);
                b = a;
                a = tt1;
                h = g;
                g = RotL32(f, 19);
                f = e;
                e = P0(tt2);
            }

            _state = (a, b, c, d, e, f, g, h) ^ _state;
        }
Example #2
0
 public override void Initialize()
 {
     _state       = (0x7380166fu, 0x4914b2b9u, 0x172442d7u, 0xda8a0600u, 0xa96f30bcu, 0x163138aau, 0xe38dee4du, 0xb0fb0e4e);
     _blockCount  = 0;
     _msgBufCount = 0;
 }