summary refs log tree commit diff
path: root/crypto
diff options
context:
space:
mode:
authorPeter Dettman <peter.dettman@bouncycastle.org>2014-01-26 20:39:15 +0700
committerPeter Dettman <peter.dettman@bouncycastle.org>2014-01-26 20:39:15 +0700
commit649d131ada52a4921ee820503f91405afd17b6ac (patch)
treed6a1924cf9de94b324d9ba8d38c35b1ef449e404 /crypto
parentWhen OCB is used with incrementing nonces, the cipher processing during initi... (diff)
downloadBouncyCastle.NET-ed25519-649d131ada52a4921ee820503f91405afd17b6ac.tar.xz
Add new test case for 96 bit tag from CFRG
Diffstat (limited to 'crypto')
-rw-r--r--crypto/test/src/crypto/test/OCBTest.cs62
1 files changed, 31 insertions, 31 deletions
diff --git a/crypto/test/src/crypto/test/OCBTest.cs b/crypto/test/src/crypto/test/OCBTest.cs
index 284ae7fb3..f4c9f3e48 100644
--- a/crypto/test/src/crypto/test/OCBTest.cs
+++ b/crypto/test/src/crypto/test/OCBTest.cs
@@ -23,12 +23,20 @@ namespace Org.BouncyCastle.Crypto.Tests
         private const string K = "000102030405060708090A0B0C0D0E0F";
         private const string N = "000102030405060708090A0B";
 
-        // Each test vector contains the strings A, P, C in order
-        private static readonly string[][] TestVectors = new string[][]
-        {
+        /*
+         * Test vectors contain the strings A, P, C in order
+         */
+
+        // Sample data for 96 bit tag, taken from a CFRG post
+        private static readonly string[][] TEST_VECTORS_96 = new string[][]{ new string[]{
+            "000102030405060708090A0B0C0D0E0F101112131415161718191A1B1C1D1E1F2021222324252627",
+            "000102030405060708090A0B0C0D0E0F101112131415161718191A1B1C1D1E1F2021222324252627",
+            "09A4FD29DE949D9A9AA9924248422097AD4883B4713E6C214FF6567ADA08A96766FC4E2EE3E3A5A11B6C44F34E3ABB3CBF8976E7" } };
+
+        // Test vectors from Appendix A of the specification
+        private static readonly string[][] TEST_VECTORS_128 = new string[][]{
             new string[]{ "", "", "197B9C3C441D3C83EAFB2BEF633B9182" },
-            new string[]{ "0001020304050607", "0001020304050607",
-                "92B657130A74B85A16DC76A46D47E1EAD537209E8A96D14E" },
+            new string[]{ "0001020304050607", "0001020304050607", "92B657130A74B85A16DC76A46D47E1EAD537209E8A96D14E" },
             new string[]{ "0001020304050607", "", "98B91552C8C009185044E30A6EB2FE21" },
             new string[]{ "", "0001020304050607", "92B657130A74B85A971EFFCAE19AD4716F88E87B871FBEED" },
             new string[]{ "000102030405060708090A0B0C0D0E0F", "000102030405060708090A0B0C0D0E0F",
@@ -36,37 +44,30 @@ namespace Org.BouncyCastle.Crypto.Tests
             new string[]{ "000102030405060708090A0B0C0D0E0F", "", "7DDB8E6CEA6814866212509619B19CC6" },
             new string[]{ "", "000102030405060708090A0B0C0D0E0F",
                 "BEA5E8798DBE7110031C144DA0B2612213CC8B747807121A" + "4CBB3E4BD6B456AF" },
-            new string[]{ "000102030405060708090A0B0C0D0E0F1011121314151617",
-                "000102030405060708090A0B0C0D0E0F1011121314151617",
+            new string[]{ "000102030405060708090A0B0C0D0E0F1011121314151617", "000102030405060708090A0B0C0D0E0F1011121314151617",
                 "BEA5E8798DBE7110031C144DA0B26122FCFCEE7A2A8D4D48" + "5FA94FC3F38820F1DC3F3D1FD4E55E1C" },
-            new string[]{ "000102030405060708090A0B0C0D0E0F1011121314151617", "",
-                "282026DA3068BC9FA118681D559F10F6" },
+            new string[]{ "000102030405060708090A0B0C0D0E0F1011121314151617", "", "282026DA3068BC9FA118681D559F10F6" },
             new string[]{ "", "000102030405060708090A0B0C0D0E0F1011121314151617",
                 "BEA5E8798DBE7110031C144DA0B26122FCFCEE7A2A8D4D48" + "6EF2F52587FDA0ED97DC7EEDE241DF68" },
-            new string[]{
-                "000102030405060708090A0B0C0D0E0F1011121314151617" + "18191A1B1C1D1E1F",
+            new string[]{ "000102030405060708090A0B0C0D0E0F1011121314151617" + "18191A1B1C1D1E1F",
                 "000102030405060708090A0B0C0D0E0F1011121314151617" + "18191A1B1C1D1E1F",
-                "BEA5E8798DBE7110031C144DA0B26122CEAAB9B05DF771A6"
-                    + "57149D53773463CBB2A040DD3BD5164372D76D7BB6824240" },
+                "BEA5E8798DBE7110031C144DA0B26122CEAAB9B05DF771A6" + "57149D53773463CBB2A040DD3BD5164372D76D7BB6824240" },
             new string[]{ "000102030405060708090A0B0C0D0E0F1011121314151617" + "18191A1B1C1D1E1F", "",
                 "E1E072633BADE51A60E85951D9C42A1B" },
-            new string[]{
-                "",
-                "000102030405060708090A0B0C0D0E0F1011121314151617" + "18191A1B1C1D1E1F",
-                "BEA5E8798DBE7110031C144DA0B26122CEAAB9B05DF771A6"
-                    + "57149D53773463CB4A3BAE824465CFDAF8C41FC50C7DF9D9" },
+            new string[]{ "", "000102030405060708090A0B0C0D0E0F1011121314151617" + "18191A1B1C1D1E1F",
+                "BEA5E8798DBE7110031C144DA0B26122CEAAB9B05DF771A6" + "57149D53773463CB4A3BAE824465CFDAF8C41FC50C7DF9D9" },
             new string[]{
                 "000102030405060708090A0B0C0D0E0F1011121314151617" + "18191A1B1C1D1E1F2021222324252627",
                 "000102030405060708090A0B0C0D0E0F1011121314151617" + "18191A1B1C1D1E1F2021222324252627",
-                "BEA5E8798DBE7110031C144DA0B26122CEAAB9B05DF771A6"
-                    + "57149D53773463CB68C65778B058A635659C623211DEEA0D" + "E30D2C381879F4C8" },
-            new string[]{ "000102030405060708090A0B0C0D0E0F1011121314151617" + "18191A1B1C1D1E1F2021222324252627",
-                "", "7AEB7A69A1687DD082CA27B0D9A37096" },
+                "BEA5E8798DBE7110031C144DA0B26122CEAAB9B05DF771A6" + "57149D53773463CB68C65778B058A635659C623211DEEA0D"
+                    + "E30D2C381879F4C8" },
+            new string[]{ "000102030405060708090A0B0C0D0E0F1011121314151617" + "18191A1B1C1D1E1F2021222324252627", "",
+                "7AEB7A69A1687DD082CA27B0D9A37096" },
             new string[]{
                 "",
                 "000102030405060708090A0B0C0D0E0F1011121314151617" + "18191A1B1C1D1E1F2021222324252627",
-                "BEA5E8798DBE7110031C144DA0B26122CEAAB9B05DF771A6"
-                    + "57149D53773463CB68C65778B058A635060C8467F4ABAB5E" + "8B3C2067A2E115DC" },
+                "BEA5E8798DBE7110031C144DA0B26122CEAAB9B05DF771A6" + "57149D53773463CB68C65778B058A635060C8467F4ABAB5E"
+                    + "8B3C2067A2E115DC" },
         };
 
         public override string Name
@@ -76,9 +77,13 @@ namespace Org.BouncyCastle.Crypto.Tests
 
         public override void PerformTest()
         {
-            for (int i = 0; i < TestVectors.Length; ++i)
+            for (int i = 0; i < TEST_VECTORS_96.Length; ++i)
             {
-                RunTestCase("Test Case " + i, TestVectors[i]);
+                RunTestCase("Test Case " + i, TEST_VECTORS_96[i], 96);
+            }
+            for (int i = 0; i < TEST_VECTORS_128.Length; ++i)
+            {
+                RunTestCase("Test Case " + i, TEST_VECTORS_128[i], 128);
             }
 
             RunLongerTestCase(128, 128, Hex.Decode("B2B41CBF9B05037DA7F16C24A35C1C94"));
@@ -123,11 +128,6 @@ namespace Org.BouncyCastle.Crypto.Tests
             //AEADTestUtil.testTampering(this, ocb, new AEADParameters(new KeyParameter(new byte[16]), 128, new byte[15]));
         }
 
-        private void RunTestCase(string testName, string[] testVector)
-        {
-            RunTestCase(testName, testVector, 128);
-        }
-
         private void RunTestCase(string testName, string[] testVector, int macLengthBits)
         {
             byte[] key = Hex.Decode(K);