public void TestCipherModeSetting() { DummyAlgorithm dummy = new DummyAlgorithm(); dummy.Mode = CipherMode.ECB; Assert.IsTrue(dummy.ModePlus == CipherModePlus.ECB, "#1"); dummy.Mode = CipherMode.CBC; Assert.IsTrue(dummy.ModePlus == CipherModePlus.CBC, "#2"); dummy.Mode = CipherMode.CFB; Assert.IsTrue(dummy.ModePlus == CipherModePlus.CFB, "#3"); dummy.Mode = CipherMode.OFB; Assert.IsTrue(dummy.ModePlus == CipherModePlus.OFB, "#4"); dummy.Mode = CipherMode.CTS; Assert.IsTrue(dummy.ModePlus == CipherModePlus.CTS, "#5"); dummy.ModePlus = CipherModePlus.ECB; Assert.IsTrue(dummy.Mode == CipherMode.ECB, "#6"); dummy.ModePlus = CipherModePlus.CBC; Assert.IsTrue(dummy.Mode == CipherMode.CBC, "#7"); dummy.ModePlus = CipherModePlus.CFB; Assert.IsTrue(dummy.Mode == CipherMode.CFB, "#8"); dummy.ModePlus = CipherModePlus.OFB; Assert.IsTrue(dummy.Mode == CipherMode.OFB, "#9"); dummy.ModePlus = CipherModePlus.CTS; Assert.IsTrue(dummy.Mode == CipherMode.CTS, "#10"); }
public void ECBTest () { DummyAlgorithm algo = new DummyAlgorithm (); algo.Mode = CipherMode.ECB; Test (algo, "ECB #1", RNG.GetBytes (8), RNG.GetBytes (8), new byte[] {1, 2, 3, 4, 5, 6, 7, 8, 255, 254, 253, 252, 251, 250, 249, 248}, new byte[] {1, 2, 3, 4, 5, 6, 7, 8, 255, 254, 253, 252, 251, 250, 249, 248}); }
public void ECBTest() { DummyAlgorithm algo = new DummyAlgorithm(); algo.Mode = CipherMode.ECB; Test(algo, "ECB #1", RNG.GetBytes(8), RNG.GetBytes(8), new byte[] { 1, 2, 3, 4, 5, 6, 7, 8, 255, 254, 253, 252, 251, 250, 249, 248 }, new byte[] { 1, 2, 3, 4, 5, 6, 7, 8, 255, 254, 253, 252, 251, 250, 249, 248 }); }
public void CBCTest () { DummyAlgorithm algo = new DummyAlgorithm (); algo.Mode = CipherMode.CBC; Test (algo, "CBC #1", RNG.GetBytes (8), new byte[] {2, 3, 4, 5, 6, 7, 8, 9}, new byte[] {1, 2, 3, 4, 5, 6, 7, 8, 255, 254, 253, 252, 251, 250, 249, 248}, new byte[] {3, 1, 7, 1, 3, 1, 15, 1, 255 ^ 3, 254 ^ 1, 253 ^ 7, 252 ^ 1, 251 ^ 3, 250 ^ 1, 249 ^ 15, 248 ^ 1}); }
public void CBCTest() { DummyAlgorithm algo = new DummyAlgorithm(); algo.Mode = CipherMode.CBC; Test(algo, "CBC #1", RNG.GetBytes(8), new byte[] { 2, 3, 4, 5, 6, 7, 8, 9 }, new byte[] { 1, 2, 3, 4, 5, 6, 7, 8, 255, 254, 253, 252, 251, 250, 249, 248 }, new byte[] { 3, 1, 7, 1, 3, 1, 15, 1, 255 ^ 3, 254 ^ 1, 253 ^ 7, 252 ^ 1, 251 ^ 3, 250 ^ 1, 249 ^ 15, 248 ^ 1 }); }
public void CTRTest () { DummyAlgorithm algo = new DummyAlgorithm (); algo.ModePlus = CipherModePlus.CTR; Test (algo, "CTR #1", RNG.GetBytes (8), new byte[] {0, 0xFF, 1, 0xFF, 2, 0xFF, 3, 0xFF}, new byte[] {1, 2, 3, 4, 5, 6, 7, 8, 255, 254, 253, 252, 251, 250, 249, 248}, new byte[] {1 ^ 0, 2 ^ 0xFF, 3 ^ 1, 4 ^ 0xFF, 5 ^ 2, 6 ^ 0xFF, 7 ^ 3, 8 ^ 0xFF, 255 ^ 0, 254 ^ 0xFF, 253 ^ 1, 252 ^ 0xFF, 251 ^ 2, 250 ^ 0xFF, 249 ^ 4, 248 ^ 0}); }
public void OFBTest () { DummyAlgorithm algo = new DummyAlgorithm (); algo.Mode = CipherMode.OFB; Test (algo, "OFB #1", RNG.GetBytes (8), new byte[] {2, 3, 4, 5, 6, 7, 8, 9}, new byte[] {1, 2, 3, 4, 5, 6, 7, 8, 255, 254, 253, 252, 251, 250, 249, 248}, new byte[] {2 ^ 1, 3 ^ 2, 4 ^ 3, 5 ^ 4, 6 ^ 5, 7 ^ 6, 8 ^ 7, 9 ^ 8, 255 ^ 2, 254 ^ 3, 253 ^ 4, 252 ^ 5, 251 ^ 6, 250 ^ 7, 249 ^ 8, 248 ^ 9}); }
public void CTRTest() { DummyAlgorithm algo = new DummyAlgorithm(); algo.ModePlus = CipherModePlus.CTR; Test(algo, "CTR #1", RNG.GetBytes(8), new byte[] { 0, 0xFF, 1, 0xFF, 2, 0xFF, 3, 0xFF }, new byte[] { 1, 2, 3, 4, 5, 6, 7, 8, 255, 254, 253, 252, 251, 250, 249, 248 }, new byte[] { 1 ^ 0, 2 ^ 0xFF, 3 ^ 1, 4 ^ 0xFF, 5 ^ 2, 6 ^ 0xFF, 7 ^ 3, 8 ^ 0xFF, 255 ^ 0, 254 ^ 0xFF, 253 ^ 1, 252 ^ 0xFF, 251 ^ 2, 250 ^ 0xFF, 249 ^ 4, 248 ^ 0 }); }
public void OFBTest() { DummyAlgorithm algo = new DummyAlgorithm(); algo.Mode = CipherMode.OFB; Test(algo, "OFB #1", RNG.GetBytes(8), new byte[] { 2, 3, 4, 5, 6, 7, 8, 9 }, new byte[] { 1, 2, 3, 4, 5, 6, 7, 8, 255, 254, 253, 252, 251, 250, 249, 248 }, new byte[] { 2 ^ 1, 3 ^ 2, 4 ^ 3, 5 ^ 4, 6 ^ 5, 7 ^ 6, 8 ^ 7, 9 ^ 8, 255 ^ 2, 254 ^ 3, 253 ^ 4, 252 ^ 5, 251 ^ 6, 250 ^ 7, 249 ^ 8, 248 ^ 9 }); }
public void TestANSIX923() { DummyAlgorithm algo = new DummyAlgorithm(); algo.Mode = CipherMode.ECB; algo.Padding = PaddingMode.ANSIX923; PaddingTest(algo, "ANSIX923 Tests #1", new byte[] { 1, 2, 3, 4, 5, 6, 7, 8 }, new byte[] { 1, 2, 3, 4, 5, 6, 7, 8, 0, 0, 0, 0, 0, 0, 0, 8 }); PaddingTest(algo, "ANSIX923 Tests #2", new byte[] { 1, 2, 3, 4, 5, 6, 7, 8, 9 }, new byte[] { 1, 2, 3, 4, 5, 6, 7, 8, 9, 0, 0, 0, 0, 0, 0, 7 }); PaddingTest(algo, "ANSIX923 Tests #3", new byte[] { 1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11, 12, 13, 14, 15 }, new byte[] { 1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11, 12, 13, 14, 15, 1 }); PaddingTest(algo, "ANSIX923 Tests #4", new byte[] { 1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11, 12, 13, 14, 15, 16 }, new byte[] { 1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11, 12, 13, 14, 15, 16, 0, 0, 0, 0, 0, 0, 0, 8 }); PaddingTest(algo, "ANSIX923 Tests #5", new byte[] { 1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11, 12, 13, 14, 15, 16, 17 }, new byte[] { 1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11, 12, 13, 14, 15, 16, 17, 0, 0, 0, 0, 0, 0, 7 }); }
public void TestZeros() { DummyAlgorithm algo = new DummyAlgorithm(); algo.Mode = CipherMode.ECB; algo.Padding = PaddingMode.Zeros; PaddingTest(algo, "Zeros Tests #1", new byte[] { 1, 2, 3, 4, 5, 6, 7, 8 }, new byte[] { 1, 2, 3, 4, 5, 6, 7, 8 }); PaddingTest(algo, "Zeros Tests #2", new byte[] { 1, 2, 3, 4, 5, 6, 7, 8, 9 }, new byte[] { 1, 2, 3, 4, 5, 6, 7, 8, 9, 0, 0, 0, 0, 0, 0, 0 }); PaddingTest(algo, "Zeros Tests #3", new byte[] { 1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11, 12, 13, 14, 15 }, new byte[] { 1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11, 12, 13, 14, 15, 0 }); PaddingTest(algo, "Zeros Tests #4", new byte[] { 1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11, 12, 13, 14, 15, 16 }, new byte[] { 1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11, 12, 13, 14, 15, 16 }); PaddingTest(algo, "Zeros Tests #5", new byte[] { 1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11, 12, 13, 14, 15, 16, 17 }, new byte[] { 1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11, 12, 13, 14, 15, 16, 17, 0, 0, 0, 0, 0, 0, 0 }); }
public void TestPKCS7() { DummyAlgorithm algo = new DummyAlgorithm(); algo.Mode = CipherMode.ECB; algo.Padding = PaddingMode.PKCS7; PaddingTest(algo, "PKCS7 Tests #1", new byte[] { 1, 2, 3, 4, 5, 6, 7, 8 }, new byte[] { 1, 2, 3, 4, 5, 6, 7, 8, 8, 8, 8, 8, 8, 8, 8, 8 }); PaddingTest(algo, "PKCS7 Tests #2", new byte[] { 1, 2, 3, 4, 5, 6, 7, 8, 9 }, new byte[] { 1, 2, 3, 4, 5, 6, 7, 8, 9, 7, 7, 7, 7, 7, 7, 7 }); PaddingTest(algo, "PKCS7 Tests #3", new byte[] { 1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11, 12, 13, 14, 15 }, new byte[] { 1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11, 12, 13, 14, 15, 1 }); PaddingTest(algo, "PKCS7 Tests #4", new byte[] { 1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11, 12, 13, 14, 15, 16 }, new byte[] { 1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11, 12, 13, 14, 15, 16, 8, 8, 8, 8, 8, 8, 8, 8 }); PaddingTest(algo, "PKCS7 Tests #5", new byte[] { 1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11, 12, 13, 14, 15, 16, 17 }, new byte[] { 1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11, 12, 13, 14, 15, 16, 17, 7, 7, 7, 7, 7, 7, 7 }); }
public void TestNone() { DummyAlgorithm algo = new DummyAlgorithm(); algo.Mode = CipherMode.ECB; algo.Padding = PaddingMode.None; PaddingTest(algo, "None Tests #1", new byte[] { 1, 2, 3, 4, 5, 6, 7, 8 }, new byte[] { 1, 2, 3, 4, 5, 6, 7, 8 }); try { PaddingTest(algo, String.Empty, new byte[] { 1, 2, 3, 4, 5, 6, 7, 8, 9 }, new byte[0]); Assert.Fail("None Tests #2"); } catch (CryptographicException) {} try { PaddingTest(algo, String.Empty, new byte[] { 1, 2, 3, 4, 5, 6, 7, 8, 9 }, new byte[0]); Assert.Fail("None Tests #2"); } catch (CryptographicException) {} try { PaddingTest(algo, String.Empty, new byte[] { 1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11, 12, 13, 14, 15 }, new byte[0]); Assert.Fail("None Tests #3"); } catch (CryptographicException) {} PaddingTest(algo, "None Tests #4", new byte[] { 1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11, 12, 13, 14, 15, 16 }, new byte[] { 1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11, 12, 13, 14, 15, 16 }); try { PaddingTest(algo, String.Empty, new byte[] { 1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11, 12, 13, 14, 15, 16, 17 }, new byte[0]); Assert.Fail("None Tests #4"); } catch (CryptographicException) {} }