From 91e9cac367d2f5bbcbd6023e971ca9e06629845c Mon Sep 17 00:00:00 2001 From: Peter Dettman Date: Sat, 25 Jan 2014 17:39:12 +0700 Subject: Port of AddOne method(s) from Java --- crypto/src/math/ec/ECFieldElement.cs | 16 ++++++++++++++++ 1 file changed, 16 insertions(+) (limited to 'crypto') 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) { -- cgit 1.4.1