summary refs log tree commit diff
path: root/crypto/test
diff options
context:
space:
mode:
authorPeter Dettman <peter.dettman@bouncycastle.org>2022-12-05 15:20:20 +0700
committerPeter Dettman <peter.dettman@bouncycastle.org>2022-12-05 15:20:20 +0700
commit3dacc4fc708eeed68f9d714d76e1cbc02a6341a9 (patch)
tree6c67917ad3b88f3f2170b1a143432231e44032ea /crypto/test
parentRefactoring in SP80038G (diff)
downloadBouncyCastle.NET-ed25519-3dacc4fc708eeed68f9d714d76e1cbc02a6341a9.tar.xz
Fix rounding issue with FF1
Diffstat (limited to 'crypto/test')
-rw-r--r--crypto/test/src/crypto/test/SP80038GTest.cs23
1 files changed, 23 insertions, 0 deletions
diff --git a/crypto/test/src/crypto/test/SP80038GTest.cs b/crypto/test/src/crypto/test/SP80038GTest.cs
index 7d2a76474..c1eac2a24 100644
--- a/crypto/test/src/crypto/test/SP80038GTest.cs
+++ b/crypto/test/src/crypto/test/SP80038GTest.cs
@@ -413,6 +413,28 @@ namespace Org.BouncyCastle.Crypto.Tests
             }
         }
 
+        private void ImplTestFF1Rounding()
+        {
+            int radix = 256;
+            byte[] key = Hex.DecodeStrict("000102030405060708090a0b0c0d0e0f");
+            byte[] tweak = Hex.DecodeStrict("0001020304050607");
+            byte[] asciiPT = Hex.DecodeStrict("000102030405060708090a0b0c0d0e0f101112131415161718191a1b1c1d1e1f202122232425262728292a2b2c2d2e2f303132333435363738");
+            byte[] asciiCT = Hex.DecodeStrict("dc18bef8b7d23aa77d1daf7a50c2253c4bacb772129f70805ecd413775bc3bdf7927ce70f455dacf4fdf61b61ac73a5c90fd3d1759dca0bf27");
+            byte[] result = new byte[asciiPT.Length];
+
+            FpeEngine fpeEngine = new FpeFf1Engine();
+            FpeParameters fpeParameters = new FpeParameters(new KeyParameter(key), radix, tweak);
+
+            fpeEngine.Init(true, fpeParameters);
+            fpeEngine.ProcessBlock(asciiPT, 0, asciiPT.Length, result, 0);
+            IsTrue("Failed FF1 rounding test (encryption)", AreEqual(asciiCT, result));
+
+            fpeEngine.Init(false, fpeParameters);
+            fpeEngine.ProcessBlock(asciiCT, 0, asciiCT.Length, result, 0);
+
+            IsTrue("Failed FF1 rounding test (decryption)", AreEqual(asciiPT, result));
+        }
+
         private void ImplTestFF3_1Bounds()
         {
             string bigAlpha = "+-ABCDEFGHIJKLMNOPQRSTUVWXYZ0123456789abcdefghijklmnopqrstuvwxyz";
@@ -505,6 +527,7 @@ namespace Org.BouncyCastle.Crypto.Tests
             ImplTestFF1();
             ImplTestFF1w();
             ImplTestFF1Bounds();
+            ImplTestFF1Rounding();
             ImplTestFF3_1();
             ImplTestFF3_1w();
             ImplTestFF3_1_255();