public unsafe void Compress20Test()
        {
            int dataLen = 20;

            byte[] data     = GetRandomBytes(dataLen);
            byte[] expected = ComputeSingleSha(data);

            using Sha256Fo sha = new Sha256Fo();
            fixed(uint *hPt = &sha.hashState[0], wPt = &sha.w[0])
            {
                int dIndex = 0;

                for (int i = 0; i < 5; i++, dIndex += 4)
                {
                    wPt[i] = (uint)((data[dIndex] << 24) | (data[dIndex + 1] << 16) | (data[dIndex + 2] << 8) | data[dIndex + 3]);
                }
                wPt[5] = 0b10000000_00000000_00000000_00000000U;

                wPt[15] = (uint)dataLen * 8;
                sha.Init(hPt);
                sha.Compress20(hPt, wPt);
                byte[] actual = sha.GetBytes(hPt);

                Assert.Equal(expected, actual);
            }
        }
Beispiel #2
0
        private unsafe bool Loop15()
        {
            using Sha512Fo sha512 = new Sha512Fo();
            ulong[] ipad = new ulong[80];
            ulong[] opad = new ulong[80];

            using Sha256Fo sha256 = new Sha256Fo();
            var cartesian = CartesianProduct.Create(Enumerable.Repeat(Enumerable.Range(0, 2048), missCount));

            fixed(ulong *iPt = ipad, oPt = opad)
            fixed(uint *wPt  = &sha256.w[0], hPt = &sha256.hashState[0], wrd = &wordIndexes[0])
            fixed(int *mi    = &missingIndexes[0])
            fixed(byte *mnPt = &mnBytes[0])
            {
                wPt[5]  = 0b10000000_00000000_00000000_00000000U;
                wPt[15] = 160;

                foreach (var item in cartesian)
                {
                    int j = 0;
                    foreach (var k in item)
                    {
                        wrd[mi[j]] = (uint)k;
                        j++;
                    }

                    wPt[0] = wrd[0] << 21 | wrd[1] << 10 | wrd[2] >> 1;
                    wPt[1] = wrd[2] << 31 | wrd[3] << 20 | wrd[4] << 9 | wrd[5] >> 2;
                    wPt[2] = wrd[5] << 30 | wrd[6] << 19 | wrd[7] << 8 | wrd[8] >> 3;
                    wPt[3] = wrd[8] << 29 | wrd[9] << 18 | wrd[10] << 7 | wrd[11] >> 4;
                    wPt[4] = wrd[11] << 28 | wrd[12] << 17 | wrd[13] << 6 | wrd[14] >> 5;

                    sha256.Init(hPt);
                    sha256.Compress20(hPt, wPt);

                    if ((wrd[14] & 0b1_1111) == hPt[0] >> 27)
                    {
                        int mnLen = 0;
                        for (int i = 0; i < 15; i++)
                        {
                            foreach (byte b in wordBytes[wrd[i]])
                            {
                                mnPt[mnLen++] = b;
                            }
                            mnPt[mnLen++] = SpaceByte;
                        }

                        if (SetBip32(sha512, mnPt, --mnLen, iPt, oPt))
                        {
                            return(SetResult(mnLen));
                        }
                    }
                }
            }

            return(false);
        }