Exemplo n.º 1
0
        public unsafe void Compress24Test()
        {
            int dataLen = 24;

            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 < 6; i++, dIndex += 4)
                {
                    wPt[i] = (uint)((data[dIndex] << 24) | (data[dIndex + 1] << 16) | (data[dIndex + 2] << 8) | data[dIndex + 3]);
                }
                wPt[6] = 0b10000000_00000000_00000000_00000000U;

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

                Assert.Equal(expected, actual);
            }
        }
Exemplo n.º 2
0
        private unsafe bool Loop18()
        {
            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[6]  = 0b10000000_00000000_00000000_00000000U;
                wPt[15] = 192;

                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;
                    wPt[5] = wrd[14] << 27 | wrd[15] << 16 | wrd[16] << 5 | wrd[17] >> 6;

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

                    if ((wrd[17] & 0b11_1111) == hPt[0] >> 26)
                    {
                        int mnLen = 0;
                        for (int i = 0; i < 18; 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);
        }