summary refs log tree commit diff
path: root/crypto/src/math/ec
diff options
context:
space:
mode:
authorPeter Dettman <peter.dettman@bouncycastle.org>2014-01-25 17:39:12 +0700
committerPeter Dettman <peter.dettman@bouncycastle.org>2014-01-25 17:39:12 +0700
commit91e9cac367d2f5bbcbd6023e971ca9e06629845c (patch)
tree2c24a4458d754748f98a5af3ca46e7e0e2d70a94 /crypto/src/math/ec
parentUse AesEngine by default (diff)
downloadBouncyCastle.NET-ed25519-91e9cac367d2f5bbcbd6023e971ca9e06629845c.tar.xz
Port of AddOne method(s) from Java
Diffstat (limited to 'crypto/src/math/ec')
-rw-r--r--crypto/src/math/ec/ECFieldElement.cs16
1 files changed, 16 insertions, 0 deletions
diff --git a/crypto/src/math/ec/ECFieldElement.cs b/crypto/src/math/ec/ECFieldElement.cs
index c2754ada8..22cd1e0e8 100644
--- a/crypto/src/math/ec/ECFieldElement.cs
+++ b/crypto/src/math/ec/ECFieldElement.cs
@@ -11,6 +11,7 @@ namespace Org.BouncyCastle.Math.EC
         public abstract string FieldName { get; }
         public abstract int FieldSize { get; }
         public abstract ECFieldElement Add(ECFieldElement b);
+        public abstract ECFieldElement AddOne();
         public abstract ECFieldElement Subtract(ECFieldElement b);
         public abstract ECFieldElement Multiply(ECFieldElement b);
         public abstract ECFieldElement Divide(ECFieldElement b);
@@ -146,6 +147,16 @@ namespace Org.BouncyCastle.Math.EC
             return new FpFieldElement(q, r, ModAdd(x, b.ToBigInteger()));
         }
 
+        public override ECFieldElement AddOne()
+        {
+            BigInteger x2 = x.Add(BigInteger.One);
+            if (x2.CompareTo(q) == 0)
+            {
+                x2 = BigInteger.Zero;
+            }
+            return new FpFieldElement(q, r, x2);
+        }
+
         public override ECFieldElement Subtract(
             ECFieldElement b)
         {
@@ -1104,6 +1115,11 @@ namespace Org.BouncyCastle.Math.EC
             return new F2mFieldElement(m, ks, iarrClone);
         }
 
+        public override ECFieldElement AddOne()
+        {
+            return new F2mFieldElement(m, ks, x.AddOne());
+        }
+
         public override ECFieldElement Subtract(
             ECFieldElement b)
         {