Ejemplo n.º 1
0
        private void RunAgainstAs()
        {
            Skein.Skein256Ex  my256 = new Skein.Skein256Ex();
            Skein.Skein512Ex  my512 = new Skein.Skein512Ex();
            Skein.Skein1024Ex my1k  = new Skein.Skein1024Ex();
            int    completedTests   = 0;
            UInt64 runningByteCount = 0;

            //int passedTests = 0;
            //int failedTests = 0;
            byte[] result = null;
            System.Diagnostics.Stopwatch overAllSW = new System.Diagnostics.Stopwatch();
            System.Diagnostics.Stopwatch testSW    = new System.Diagnostics.Stopwatch();

            overAllSW.Start();
            foreach (string Thing in lstTests.SelectedItems)
            {
                string[] pieces      = Thing.Split(new char[] { ',' });
                string   lengthParse = pieces[2].Replace("length=", "");
                int      length      = int.Parse(lengthParse);
                //note:
                //doing this versus "string = new string('a', length)" accomplishes the same thing.
                //the problem with the new string method is it consumes TONS of memory needlessly.
                //this method of just starting with a byte array works just as fast, and uses 1/5th the memory!!!
                byte[] source = new byte[length];
                for (int i = 0; i < length; i++)
                {
                    source[i] = 0x61; // 'a'
                }
                //end note
                runningByteCount += (ulong)source.Length;
                testSW.Start();
                switch (int.Parse(pieces[0]))
                {
                case 256:
                    my256.Initialize(uint.Parse(pieces[1]), null, null, 0, 0, 0);
                    result = my256.ComputeHash(source);
                    break;

                case 512:
                    my512.Initialize(uint.Parse(pieces[1]), null, null, 0, 0, 0);
                    result = my512.ComputeHash(source);
                    break;

                case 1024:
                    my1k.Initialize(uint.Parse(pieces[1]), null, null, 0, 0, 0);
                    result = my1k.ComputeHash(source);
                    break;
                }
                testSW.Stop();
                string testDuration = testSW.Elapsed.Duration().ToString(@"h\:mm\:ss\.fffff");
                txtResults.AppendText(Thing + ", " + testDuration + "     RESULT(base64):\r\n");
                txtResults.AppendText(Convert.ToBase64String(result, Base64FormattingOptions.InsertLineBreaks) + "\r\n\r\n");
                result = null;
                source = null;
                //if (completedTests % 15 == 0 || testSW.Elapsed.TotalSeconds > 5)
                //    System.GC.Collect();
                completedTests++;
                if (completedTests % 10 == 0 || testSW.Elapsed.TotalSeconds > 2)
                {
                    tslblStatus.Text = completedTests.ToString() + " tests complete... Still Running...";
                }
                Application.DoEvents();
                testSW.Reset();
            }
            overAllSW.Stop();
            Double bytesPerSec = runningByteCount / overAllSW.Elapsed.TotalSeconds;

            ssMain.Items["tslblStatus"].Text = "Done in " + overAllSW.Elapsed.Duration().ToString(@"h\:mm\:ss\.ffff") + ". " +
                                               completedTests.ToString() + " Tests Complete " +
                                               (runningByteCount / 1024).ToString() + " KBytes processed (" + bytesPerSec.ToString("0.0") + " bytes/sec or " +
                                               (bytesPerSec / 1048576).ToString("0.0") + " MB/sec) "; //: " +
            //passedTests.ToString() + " PASSED, " + failedTests.ToString() + " FAILED";
        }
Ejemplo n.º 2
0
        private int RunAgainstKats()
        {
            const string SrcFile = BASEWORKINGDIR + @"ParsedKats\MASTER.txt";

            string[]          SrcLines = System.IO.File.ReadAllLines(SrcFile);
            Skein.Skein256Ex  my256    = new Skein.Skein256Ex();
            Skein.Skein512Ex  my512    = new Skein.Skein512Ex();
            Skein.Skein1024Ex my1k     = new Skein.Skein1024Ex();
            int completedTests         = 0;

            foreach (string Thing in SrcLines)
            {
                try
                {
                    txtOutput1.AppendText(Thing + "\r\n");
                    string[] ThingParts = Thing.Split('^');
                    byte[]   DataToUse  = null;
                    UInt16   HashBitLen;
                    int      MACInputLen;
                    byte[]   MACToUse = null;
                    //'Dim TempByteCount As Integer
                    byte treeNode;
                    byte treeLeaf;
                    byte treeMaxLevels;

                    if (!ThingParts[0].ToLower().Contains("tree"))
                    {
                        txtOutput2.AppendText("Skip KNOWN PASS test:" + Thing.Substring(0, 60) + "\r\n");
                        continue;
                    }

                    int InputLen = int.Parse(ThingParts[3].Replace("L", String.Empty));

                    if (ThingParts.Length == 8)
                    {
                        treeLeaf      = byte.Parse(ThingParts[4].Replace("LF", string.Empty), System.Globalization.NumberStyles.HexNumber);
                        treeNode      = byte.Parse(ThingParts[5].Replace("ND", string.Empty), System.Globalization.NumberStyles.HexNumber);
                        treeMaxLevels = byte.Parse(ThingParts[6].Replace("ML", string.Empty), System.Globalization.NumberStyles.HexNumber);
                    }
                    else
                    {
                        treeLeaf      = 0;
                        treeNode      = 0;
                        treeMaxLevels = 0;
                    }

                    //create sub-arrays of data, otherwise Skein functions will use ENTIRE array
                    if (ThingParts.Length == 6)
                    {
                        MACInputLen = int.Parse(ThingParts[4].Replace("MAC", String.Empty));
                        MACToUse    = new byte[MACInputLen];
                        Buffer.BlockCopy(MACKey, 0, MACToUse, 0, MACInputLen);
                    }
                    else
                    {
                        MACToUse = null;
                    }

                    if (InputLen == 0)
                    {
                        DataToUse = null;
                    }
                    else
                    {
                        int numBytes;
                        int numExtraBits;
                        numBytes = Math.DivRem(InputLen, 8, out numExtraBits);
                        if (numExtraBits > 0)
                        {
                            DataToUse = new byte[numBytes + 1];
                        }
                        else
                        {
                            DataToUse = new byte[numBytes];
                        }
                        System.Diagnostics.Debug.Print("INPUTLEN: " + InputLen.ToString() + " DATATOUSE.LENGTH: " + DataToUse.Length.ToString());
                        switch (ThingParts[0].ToLower())
                        {
                        case "incrementing":
                            Buffer.BlockCopy(IncrementingDataSrc, 0, DataToUse, 0, DataToUse.Length);
                            break;

                        case "random":
                            Buffer.BlockCopy(RandomDataSrc, 0, DataToUse, 0, DataToUse.Length);
                            break;

                        case "zero":
                            Buffer.BlockCopy(ZeroDataSrc, 0, DataToUse, 0, DataToUse.Length);
                            break;

                        case "random_mac":
                            Buffer.BlockCopy(RandomMACDataSrc, 0, DataToUse, 0, DataToUse.Length);
                            break;

                        case "tree":
                            switch (ThingParts[1].ToLower())
                            {
                            case "s256": Buffer.BlockCopy(TreeDataSrc256, 0, DataToUse, 0, DataToUse.Length); break;

                            case "s512": Buffer.BlockCopy(TreeDataSrc512, 0, DataToUse, 0, DataToUse.Length); break;

                            case "s1024": Buffer.BlockCopy(TreeDataSrc1k, 0, DataToUse, 0, DataToUse.Length); break;
                            }
                            break;

                        default:
                            txtOutput2.AppendText("Skip UNKNOWN test:" + Thing.Substring(0, 60) + "\r\n");
                            continue;
                        }
                    }
                    HashBitLen = UInt16.Parse(ThingParts[2].Replace("H", String.Empty));
                    byte[] Result = null;

                    try
                    {
                        switch (ThingParts[1].ToLower())
                        {
                        case "s256":
                            if (Thing.ToLower().Contains("mac") && MACToUse != null)
                            {
                                my256.Initialize(HashBitLen, MACToUse, null, 0, 0, 0);
                                Result = my256.ComputeHash(DataToUse, (byte)(InputLen % 8));
                            }
                            else
                            {
                                my256.Initialize(HashBitLen, null, null, treeLeaf, treeNode, treeMaxLevels);
                                Result = my256.ComputeHash(DataToUse, (byte)(InputLen % 8));
                            }
                            break;

                        case "s512":
                            if (Thing.ToLower().Contains("mac") && MACToUse != null)
                            {
                                my512.Initialize(HashBitLen, MACToUse, null, 0, 0, 0);
                                Result = my512.ComputeHash(DataToUse, (byte)(InputLen % 8));
                            }
                            else
                            {
                                my512.Initialize(HashBitLen, null, null, treeLeaf, treeNode, treeMaxLevels);
                                Result = my512.ComputeHash(DataToUse, (byte)(InputLen % 8));
                            }
                            break;

                        case "s1024":
                            if (Thing.ToLower().Contains("mac") && MACToUse != null)
                            {
                                my1k.Initialize(HashBitLen, MACToUse, null, 0, 0, 0);
                                Result = my1k.ComputeHash(DataToUse, (byte)(InputLen % 8));
                            }
                            else
                            {
                                my1k.Initialize(HashBitLen, null, null, treeLeaf, treeNode, treeMaxLevels);
                                Result = my1k.ComputeHash(DataToUse, (byte)(InputLen % 8));
                            }
                            break;
                        }
                    }
                    catch (Exception ex)
                    {
                        txtOutput2.AppendText("*EXCEPTION!!!!! " + Thing + "\r\n");
                        MessageBox.Show("EXCEPTION: " + ex.Message + "\r\n" + ex.StackTrace);
                    }

                    string ResultString = Bytes2HexString(Result);

                    if (ThingParts.Length == 6)
                    {
                        if (ResultString.CompareTo(ThingParts[5]) == 0)
                        {
                            txtOutput3.AppendText("-PASS:"******"\r\n");
                        }
                        else
                        {
                            txtOutput3.AppendText("*FAIL:" + Thing + "\r\n");
                        }
                    }
                    else if (ThingParts.Length == 8)
                    {
                        if (ResultString.CompareTo(ThingParts[7]) == 0)
                        {
                            txtOutput3.AppendText("-PASS:"******"\r\n");
                        }
                        else
                        {
                            txtOutput3.AppendText("*FAIL:" + Thing + "\r\n");
                        }
                    }
                    else
                    {
                        if (ResultString.CompareTo(ThingParts[4]) == 0)
                        {
                            txtOutput3.AppendText("-PASS:"******"\r\n");
                        }
                        else
                        {
                            txtOutput3.AppendText("*FAIL:" + Thing + "\r\n");
                        }
                    }
                }
                catch (Exception ex)
                {
                    MessageBox.Show("FOR EACH EXCEPTION: " + ex.Message + "\r\n" + ex.StackTrace);
                }
                completedTests++;
            } //end foreach Thing
            return(completedTests);
        }     //end RunAgainstKats
Ejemplo n.º 3
0
        private void RunAgainstKats()
        {
            Skein.SkeinEx my256          = new Skein.Skein256Ex();
            Skein.SkeinEx my512          = new Skein.Skein512Ex();
            Skein.SkeinEx my1k           = new Skein.Skein1024Ex();
            int           completedTests = 0;
            int           passedTests    = 0;
            int           failedTests    = 0;

            System.Diagnostics.Stopwatch overAllSW = new System.Diagnostics.Stopwatch();
            System.Diagnostics.Stopwatch testSW    = new System.Diagnostics.Stopwatch();

            overAllSW.Start();
            foreach (string Thing in lstTests.SelectedItems)
            {
                //try
                //{
                string[] ThingParts = Thing.Split('^');
                byte[]   DataToUse  = null;
                UInt16   HashBitLen;
                int      MACInputLen;
                byte[]   MACToUse = null;
                byte     treeNode;
                byte     treeLeaf;
                byte     treeMaxLevels;

                int InputLen = int.Parse(ThingParts[3].Replace("L", String.Empty));

                if (ThingParts.Length == 8)
                {
                    treeLeaf      = byte.Parse(ThingParts[4].Replace("LF", string.Empty), System.Globalization.NumberStyles.HexNumber);
                    treeNode      = byte.Parse(ThingParts[5].Replace("ND", string.Empty), System.Globalization.NumberStyles.HexNumber);
                    treeMaxLevels = byte.Parse(ThingParts[6].Replace("ML", string.Empty), System.Globalization.NumberStyles.HexNumber);
                }
                else
                {
                    treeLeaf      = 0;
                    treeNode      = 0;
                    treeMaxLevels = 0;
                }

                //create sub-arrays of data, otherwise Skein functions will use ENTIRE array
                if (ThingParts.Length == 6)
                {
                    MACInputLen = int.Parse(ThingParts[4].Replace("MAC", String.Empty));
                    MACToUse    = new byte[MACInputLen];
                    Buffer.BlockCopy(MACKey, 0, MACToUse, 0, MACInputLen);
                }
                else
                {
                    MACToUse = null;
                }

                if (InputLen == 0)
                {
                    DataToUse = null;
                }
                else
                {
                    int numBytes;
                    int numExtraBits;
                    numBytes = Math.DivRem(InputLen, 8, out numExtraBits);
                    if (numExtraBits > 0)
                    {
                        DataToUse = new byte[numBytes + 1];
                    }
                    else
                    {
                        DataToUse = new byte[numBytes];
                    }
                    System.Diagnostics.Debug.Print("INPUTLEN: " + InputLen.ToString() + " DATATOUSE.LENGTH: " + DataToUse.Length.ToString());
                    switch (ThingParts[0].ToLower())
                    {
                    case "incrementing":
                        Buffer.BlockCopy(IncrementingDataSrc, 0, DataToUse, 0, DataToUse.Length);
                        break;

                    case "random":
                        Buffer.BlockCopy(RandomDataSrc, 0, DataToUse, 0, DataToUse.Length);
                        break;

                    case "zero":
                        Buffer.BlockCopy(ZeroDataSrc, 0, DataToUse, 0, DataToUse.Length);
                        break;

                    case "random_mac":
                        Buffer.BlockCopy(RandomMACDataSrc, 0, DataToUse, 0, DataToUse.Length);
                        break;

                    case "tree":
                        switch (ThingParts[1].ToLower())
                        {
                        case "s256": Buffer.BlockCopy(TreeDataSrc256, 0, DataToUse, 0, DataToUse.Length); break;

                        case "s512": Buffer.BlockCopy(TreeDataSrc512, 0, DataToUse, 0, DataToUse.Length); break;

                        case "s1024": Buffer.BlockCopy(TreeDataSrc1k, 0, DataToUse, 0, DataToUse.Length); break;
                        }
                        break;

                    default:
                        //this.txtOutput2.AppendText("Skip UNKNOWN test:" + Thing.Substring(0, 60) + "\r\n");
                        continue;
                    }
                }
                HashBitLen = UInt16.Parse(ThingParts[2].Replace("H", String.Empty));
                byte[] Result = null;

                //try
                //{
                testSW.Start();
                switch (ThingParts[1].ToLower())
                {
                case "s256":
                    if (Thing.ToLower().Contains("mac") && MACToUse != null)
                    {
                        my256.Initialize(HashBitLen, MACToUse, null, 0, 0, 0);
                    }
                    else
                    {
                        my256.Initialize(HashBitLen, null, null, treeLeaf, treeNode, treeMaxLevels);
                    }
                    Result = my256.ComputeHash(DataToUse, (byte)(InputLen % 8));
                    break;

                case "s512":
                    if (Thing.ToLower().Contains("mac") && MACToUse != null)
                    {
                        my512.Initialize(HashBitLen, MACToUse, null, 0, 0, 0);
                    }
                    else
                    {
                        my512.Initialize(HashBitLen, null, null, treeLeaf, treeNode, treeMaxLevels);
                    }
                    Result = my512.ComputeHash(DataToUse, (byte)(InputLen % 8));
                    break;

                case "s1024":
                    if (Thing.ToLower().Contains("mac") && MACToUse != null)
                    {
                        my1k.Initialize(HashBitLen, MACToUse, null, 0, 0, 0);
                    }
                    else
                    {
                        my1k.Initialize(HashBitLen, null, null, treeLeaf, treeNode, treeMaxLevels);
                    }
                    Result = my1k.ComputeHash(DataToUse, (byte)(InputLen % 8));
                    break;
                }
                //}
                //catch (Exception ex)
                //{
                //this.txtOutput2.AppendText("*EXCEPTION!!!!! " + Thing + "\r\n");
                //    MessageBox.Show("EXCEPTION: " + ex.Message + "\r\n" + ex.StackTrace);
                //}
                testSW.Stop();
                string ResultString = Bytes2HexString(Result);
                string testAbrvName = Thing.Replace(ThingParts[ThingParts.GetUpperBound(0)], string.Empty).Replace('^', '\t');
                string testDuration = testSW.Elapsed.ToString(@"h\:mm\:ss\.fffff");

                if (ThingParts.Length == 6)
                {
                    if (ResultString.CompareTo(ThingParts[5]) == 0)
                    {
                        passedTests++;
                        txtResults.AppendText("-PASS in " + testDuration + " " + testAbrvName + "\r\n");
                    }
                    else
                    {
                        failedTests++;
                        txtResults.AppendText("*FAIL in " + testDuration + " " + Thing + "\r\n");
                        //this.txtResults.AppendText(" EXPECTED: " + ThingParts[5] + "\r\n");
                        //this.txtResults.AppendText(" RESULT  : " + ResultString + "\r\n");
                    }
                }
                else if (ThingParts.Length == 8)
                {
                    if (ResultString.CompareTo(ThingParts[7]) == 0)
                    {
                        passedTests++;
                        txtResults.AppendText("-PASS in " + testDuration + " " + testAbrvName + "\r\n");
                    }
                    else
                    {
                        failedTests++;
                        txtResults.AppendText("*FAIL in " + testDuration + " " + Thing + "\r\n");
                        //this.txtResults.AppendText(" EXPECTED: " + ThingParts[7] + "\r\n");
                        //this.txtResults.AppendText(" RESULT  : " + ResultString + "\r\n");
                    }
                }
                else
                {
                    if (ResultString.CompareTo(ThingParts[4]) == 0)
                    {
                        passedTests++;
                        txtResults.AppendText("-PASS in " + testDuration + " " + testAbrvName + "\r\n");
                    }
                    else
                    {
                        failedTests++;
                        txtResults.AppendText("*FAIL in " + testDuration + " " + Thing + "\r\n");
                        //this.txtResults.AppendText(" EXPECTED: " + ThingParts[4] + "\r\n");
                        //this.txtResults.AppendText(" RESULT  : " + ResultString + "\r\n");
                    }
                }

                //}
                //catch (Exception ex)
                //{
                //    MessageBox.Show("'FOR-EACH' EXCEPTION: " + ex.Message + "\r\n" + ex.StackTrace);
                //}
                testSW.Reset();
                completedTests++;
                Application.DoEvents();
            } //end foreach Thing
            overAllSW.Stop();
            ssMain.Items["tslblStatus"].Text = "Done in " + overAllSW.Elapsed.Duration().ToString(@"h\:mm\:ss\.ffff")
                                               + "  " + completedTests.ToString() + " Tests Complete: " +
                                               passedTests.ToString() + " PASSED, " + failedTests.ToString() + " FAILED";

            return;
        }//end RunAgainstKats