Esempio n. 1
0
        public void writeMasterKey(ref int parr_seed)
        {
            var randomNumbers = new int[8];

            //Generate random numbers
            var tGNUR = new GnuRand((UInt32)parr_seed);

            for (int idx = 0; idx < 8; idx++)
            {
                randomNumbers[idx] = tGNUR.Next();
            }

            //Convert them to bytes
            byte[] masterBytes = new byte[randomNumbers.Length * sizeof(int)];
            Buffer.BlockCopy(randomNumbers, 0, masterBytes, 0, masterBytes.Length);

            //Compute SHA256 1024 times
            var hasher = System.Security.Cryptography.SHA256Managed.Create();

            for (int idx = 0; idx < 1024; idx++)
            {
                masterBytes = hasher.ComputeHash(masterBytes);
            }

            //Write to file
            ByteArrayToFile(deviceSerialNumber, masterBytes);

            Console.WriteLine();
            Console.WriteLine("Master File written");
            currentDate = "Master file written. Password cracked: " + parr_seed;
        }
Esempio n. 2
0
        private static bool ValidateSecretKey(int currentSeed)
        {
            var randomNumbers = new int[8];

            //Make 8 random integers, Unix style
            var tGNUR = new GnuRand((UInt32)currentSeed);

            for (int idx = 0; idx < 8; idx++)
            {
                randomNumbers[idx] = tGNUR.Next();
            }

            //Then, use that to generate a random set of 32 bytes
            byte[] initialByteSeed = new byte[randomNumbers.Length * sizeof(int)];
            Buffer.BlockCopy(randomNumbers, 0, initialByteSeed, 0, initialByteSeed.Length);

            //1024 SHA256 operations on the same set of bytes
            var hasher = System.Security.Cryptography.SHA256Managed.Create();

            for (int idx = 0; idx < 1024; idx++)
            {
                initialByteSeed = hasher.ComputeHash(initialByteSeed);
            }
            hasher.Dispose();

            //Prepare HMAC hash
            HMACSHA256 hmc = new HMACSHA256(initialByteSeed);

            byte[] HMAC_Hash = hmc.ComputeHash(deviceSerial);
            hmc.Dispose();

            //Reverse Dword sections of the HMAC hash (because they're integers?)
            //for (int idx = 0; idx < 32; idx += 4)
            //    Array.Reverse(HMAC_Hash, idx, 4);
            //This isn't needed.

            //SecretKeyBuilder
            int a2 = 32;

            byte[] result = new byte[8 * a2 / 5 + 8];

            int  v3  = 0;
            byte v12 = 0;
            byte v11 = 0;
            byte v5;
            byte v7;

            int  v4 = 0;
            char v9;

            byte[] a1 = HMAC_Hash;
            byte   v6;
            byte   v8;
            int    v10;

            do
            {
                v9          = (char)a1[v3];
                result[v12] = (byte)byte_4FF020[(byte)((a1[v3]) >> 3)];
                if (v4 + 1 == a2)
                {
                    result[v12 + 2] = 0;
                    result[v12 + 1] = (byte)byte_4FF020[4 * (v9 & 7)];
                }
                else
                {
                    v5 = (a1[v3 + 1]);;
                    result[v12 + 1] = (byte)byte_4FF020[(byte)(a1[v3 + 1] >> 6) | 4 * (v9 & 7)];
                    result[v12 + 2] = (byte)byte_4FF020[(v5 >> 1) & 0x1F];
                    if (v4 + 2 == a2)
                    {
                        result[v12 + 4] = 0;
                        result[v12 + 3] = (byte)byte_4FF020[16 * (v5 & 1)];
                    }
                    else
                    {
                        v6 = (a1 [v3 + 2]);
                        result[v12 + 3] = (byte)byte_4FF020[(byte)(a1[v3 + 2] >> 4) | 16 * (v5 & 1)];
                        if (v4 + 3 == a2)
                        {
                            result[v12 + 5] = 0;
                            result[v12 + 4] = (byte)byte_4FF020[2 * (v6 & 0xF)];
                        }
                        else
                        {
                            v7 = (a1[v3 + 3]);
                            result[v12 + 4] = (byte)byte_4FF020[(byte)(a1[v3 + 3] >> 7) | 2 * (v6 & 0xF)];
                            result[v12 + 5] = (byte)byte_4FF020[(v7 >> 2) & 0x1F];
                            if (v4 + 4 == a2)
                            {
                                result[v12 + 7] = 0;
                                result[v12 + 6] = (byte)byte_4FF020[8 * (v7 & 3)];
                            }
                            else
                            {
                                v8 = (byte)byte_4FF020[(byte)(a1[v3 + 4] >> 5) | 8 * (v7 & 3)];
                                result[v12 + 7] = (byte)byte_4FF020[(a1[v3 + 4] & 0x1F)];
                                result[v12 + 6] = v8;
                            }
                        }
                    }
                }
                v11 += 5;
                v12 += 8;
                v4   = v11;
                v3   = v11;
            }while (a2 > v11);
            v10         = v12;
            result[v10] = 0;
            //SecretKeyBuilder Ends here

            for (int idx = 0; idx < 52; idx++)
            {
                if (TargetSecretKey[idx] == result[idx])
                {
                    continue;
                }
                else
                {
                    return(false);
                }
            }
            return(true);
        }