private void btnKATS_Click(object sender, EventArgs e) { //if compilation errors crop up that KeysV3 or RNGV3 does not exist, it's because the DLL was compiled without the DEBUG flag and those // functions and classes were internalized TestParametersV3 tests = new TestParametersV3(); this.Enabled = false; txtOutput.Clear(); foreach (TestParametersV3.Params test in tests.Tests) { txtOutput.AppendText("PROCEEDING WITH TEST #" + test.ID + "\r\n"); Application.DoEvents(); #pragma warning disable 618 // we know in DEBUG mode this will throw an Obsolete warning, this is a legitimate use of this function, so supress it TripleSecManaged.RNGV3 r = new TripleSecManaged.RNGV3(test.RNGBytes); TripleSecManaged.KeysV3 k = new TripleSecManaged.KeysV3(test.Key, r.Salt); #pragma warning restore 618 if (!TestParametersV3.ArrayContentsAreEqual(test.HMACSHA512Key, k.HMACSHA512_KEY)) txtOutput.AppendText("*TEST " + test.ID + " FAILED! HMACSHA512 Key\r\n"); else txtOutput.AppendText("Pass HMACSHA512 Key\r\n"); if (!TestParametersV3.ArrayContentsAreEqual(test.HMACKeccak512Key, k.HMACKeccak512_KEY)) txtOutput.AppendText("*TEST " + test.ID + " FAILED! HMACKeccak512 Key\r\n"); else txtOutput.AppendText("Pass HMACKeccak512 Key\r\n"); if (!TestParametersV3.ArrayContentsAreEqual(test.AESKey, k.AES_KEY)) txtOutput.AppendText("*TEST " + test.ID + " FAILED! AES Key\r\n"); else txtOutput.AppendText("Pass AES Key\r\n"); if (!TestParametersV3.ArrayContentsAreEqual(test.TwofishKey, k.Twofish_KEY)) txtOutput.AppendText("*TEST " + test.ID + " FAILED! Twofish Key\r\n"); else txtOutput.AppendText("Pass Twofish Key\r\n"); if (!TestParametersV3.ArrayContentsAreEqual(test.XSalsa20Key, k.XSalsa20_KEY)) txtOutput.AppendText("*TEST " + test.ID + " FAILED! XSalsa20 Key\r\n"); else txtOutput.AppendText("Pass XSalsa20 Key\r\n"); Application.DoEvents(); #pragma warning disable 618 // we know in DEBUG mode this will throw an Obsolete warning, this is a legitimate use of this function, so supress it byte[] testedstuff = TripleSecManaged.V3.Encrypt(test.PlainText, k, r); #pragma warning restore 618 if (!TestParametersV3.ArrayContentsAreEqual(test.CipherText, testedstuff)) txtOutput.AppendText("*TEST " + test.ID + " FAILED! Encrypt: Ciphertexts don't match\r\n"); else txtOutput.AppendText("Pass Encrypt\r\n"); Application.DoEvents(); //use the test cipher text here to run the tests for Decrypt separately from Encrypt bool success = TripleSecManaged.V3.TryDecrypt(test.CipherText, test.Key, out testedstuff); bool match = success ? // if we succeeded on the last step, test them, else assume false match TestParametersV3.ArrayContentsAreEqual(test.PlainText, testedstuff) : false; if (success && !match) txtOutput.AppendText("*TEST " + test.ID + " FAILED! TryDecrypt = TRUE, Plaintexts don't match\r\n"); else if (success && match) txtOutput.AppendText("Pass TryDecrypt\r\n"); else if (!success) // no need to test match on outright failure txtOutput.AppendText("*TEST " + test.ID + " FAILED! TryDecrypt = FALSE\r\n"); } txtOutput.AppendText("===COMPLETE===\r\n"); txtOutput.AppendText("Any failures? " + txtOutput.Text.Contains("FAILED!").ToString()); this.Enabled = true; }
private void btnKATS_Click(object sender, EventArgs e) { //if compilation errors crop up that KeysV3 or RNGV3 does not exist, it's because the DLL was compiled without the DEBUG flag and those // functions and classes were internalized TestParameters tests = new TestParameters(); this.Enabled = false; txtOutput.Clear(); foreach (TestParameters.ParamsV3 test in tests.TestsV3) { //#if DEBUG // System.Diagnostics.Debug.Print("=========================================================================================="); // System.Diagnostics.Debug.Print("==TEST " + test.ID + "===================================================================="); //#endif txtOutput.AppendText("PROCEEDING WITH V3 TEST #" + test.ID + "\r\n"); Application.DoEvents(); #pragma warning disable 618 // we know in DEBUG mode this will throw an Obsolete warning, this is a legitimate use of this function, so supress it TripleSecManaged.RNGV3 r = new TripleSecManaged.RNGV3(test.RNGBytes); TripleSecManaged.KeysV3 k = new TripleSecManaged.KeysV3(test.Key, r.Salt); #pragma warning restore 618 if (!TestParameters.ArrayContentsAreEqual(test.HMACSHA512Key, k.HMACSHA512_KEY)) { txtOutput.AppendText("*TEST " + test.ID + " FAILED! HMACSHA512 Key\r\n"); } else { txtOutput.AppendText("Pass HMACSHA512 Key\r\n"); } if (!TestParameters.ArrayContentsAreEqual(test.HMACKeccak512Key, k.HMACKeccak512_KEY)) { txtOutput.AppendText("*TEST " + test.ID + " FAILED! HMACKeccak512 Key\r\n"); } else { txtOutput.AppendText("Pass HMACKeccak512 Key\r\n"); } if (!TestParameters.ArrayContentsAreEqual(test.AESKey, k.AES_KEY)) { txtOutput.AppendText("*TEST " + test.ID + " FAILED! AES Key\r\n"); } else { txtOutput.AppendText("Pass AES Key\r\n"); } if (!TestParameters.ArrayContentsAreEqual(test.TwofishKey, k.Twofish_KEY)) { txtOutput.AppendText("*TEST " + test.ID + " FAILED! Twofish Key\r\n"); } else { txtOutput.AppendText("Pass Twofish Key\r\n"); } if (!TestParameters.ArrayContentsAreEqual(test.XSalsa20Key, k.XSalsa20_KEY)) { txtOutput.AppendText("*TEST " + test.ID + " FAILED! XSalsa20 Key\r\n"); } else { txtOutput.AppendText("Pass XSalsa20 Key\r\n"); } Application.DoEvents(); #pragma warning disable 618 // we know in DEBUG mode this will throw an Obsolete warning, this is a legitimate use of this function, so supress it byte[] testedstuff = TripleSecManaged.V3.Encrypt(test.PlainText, k, r); #pragma warning restore 618 if (!TestParameters.ArrayContentsAreEqual(test.CipherText, testedstuff)) { txtOutput.AppendText("*TEST " + test.ID + " FAILED! Encrypt: Ciphertexts don't match\r\n"); } else { txtOutput.AppendText("Pass Encrypt\r\n"); } Application.DoEvents(); //use the test cipher text here to run the tests for Decrypt separately from Encrypt bool success = TripleSecManaged.V3.TryDecrypt(test.CipherText, test.Key, out testedstuff); bool match = success ? // if we succeeded on the last step, test them, else assume false match TestParameters.ArrayContentsAreEqual(test.PlainText, testedstuff) : false; if (success && !match) { txtOutput.AppendText("*TEST " + test.ID + " FAILED! TryDecrypt = TRUE, Plaintexts don't match\r\n"); } else if (success && match) { txtOutput.AppendText("Pass TryDecrypt\r\n"); } else if (!success) // no need to test match on outright failure { txtOutput.AppendText("*TEST " + test.ID + " FAILED! TryDecrypt = FALSE\r\n"); } } foreach (TestParameters.ParamsV4 test in tests.TestsV4) { //#if DEBUG // System.Diagnostics.Debug.Print("=========================================================================================="); // System.Diagnostics.Debug.Print("==TEST " + test.ID + "===================================================================="); //#endif txtOutput.AppendText("PROCEEDING WITH V4 TEST #" + test.ID + "\r\n"); Application.DoEvents(); #pragma warning disable 618 // we know in DEBUG mode this will throw an Obsolete warning, this is a legitimate use of this function, so supress it TripleSecManaged.RNGV4 r = new TripleSecManaged.RNGV4(test.RNGBytes); TripleSecManaged.KeysV4 k = new TripleSecManaged.KeysV4(test.Key, r.Salt); #pragma warning restore 618 if (!TestParameters.ArrayContentsAreEqual(test.HMACSHA512Key, k.HMACSHA512_KEY)) { txtOutput.AppendText("*TEST " + test.ID + " FAILED! HMACSHA512 Key\r\n"); } else { txtOutput.AppendText("Pass HMACSHA512 Key\r\n"); } if (!TestParameters.ArrayContentsAreEqual(test.HMACSHA3_512Key, k.HMACSHA3_512_KEY)) { txtOutput.AppendText("*TEST " + test.ID + " FAILED! HMACKeccak512 Key\r\n"); } else { txtOutput.AppendText("Pass HMACKeccak512 Key\r\n"); } if (!TestParameters.ArrayContentsAreEqual(test.AESKey, k.AES_KEY)) { txtOutput.AppendText("*TEST " + test.ID + " FAILED! AES Key\r\n"); } else { txtOutput.AppendText("Pass AES Key\r\n"); } if (!TestParameters.ArrayContentsAreEqual(test.XSalsa20Key, k.XSalsa20_KEY)) { txtOutput.AppendText("*TEST " + test.ID + " FAILED! XSalsa20 Key\r\n"); } else { txtOutput.AppendText("Pass XSalsa20 Key\r\n"); } Application.DoEvents(); #pragma warning disable 618 // we know in DEBUG mode this will throw an Obsolete warning, this is a legitimate use of this function, so supress it byte[] testedstuff = TripleSecManaged.V4.Encrypt(test.PlainText, k, r); #pragma warning restore 618 if (!TestParameters.ArrayContentsAreEqual(test.CipherText, testedstuff)) { txtOutput.AppendText("*TEST " + test.ID + " FAILED! Encrypt: Ciphertexts don't match\r\n"); } else { txtOutput.AppendText("Pass Encrypt\r\n"); } Application.DoEvents(); //use the test cipher text here to run the tests for Decrypt separately from Encrypt bool success = TripleSecManaged.V4.TryDecrypt(test.CipherText, test.Key, out testedstuff); bool match = success ? // if we succeeded on the last step, test them, else assume false match TestParameters.ArrayContentsAreEqual(test.PlainText, testedstuff) : false; if (success && !match) { txtOutput.AppendText("*TEST " + test.ID + " FAILED! TryDecrypt = TRUE, Plaintexts don't match\r\n"); } else if (success && match) { txtOutput.AppendText("Pass TryDecrypt\r\n"); } else if (!success) // no need to test match on outright failure { txtOutput.AppendText("*TEST " + test.ID + " FAILED! TryDecrypt = FALSE\r\n"); } } txtOutput.AppendText("===COMPLETE===\r\n"); txtOutput.AppendText("Any failures? " + txtOutput.Text.Contains("FAILED!").ToString()); this.Enabled = true; }