diff options
author | Peter Dettman <peter.dettman@bouncycastle.org> | 2015-03-23 13:56:59 +0700 |
---|---|---|
committer | Peter Dettman <peter.dettman@bouncycastle.org> | 2015-03-23 13:56:59 +0700 |
commit | add1f6be39cfdebffc7e3220b99c11c25624ea6a (patch) | |
tree | f10a8ea66ff849e87f262fb5b7ab766ea892b1c6 /crypto/src | |
parent | Add ANSSI curve FRP256v1 and refactor curve registries (diff) | |
download | BouncyCastle.NET-ed25519-add1f6be39cfdebffc7e3220b99c11c25624ea6a.tar.xz |
Add SquarePow method to ECFieldElement
Diffstat (limited to 'crypto/src')
-rw-r--r-- | crypto/src/math/ec/ECFieldElement.cs | 24 |
1 files changed, 16 insertions, 8 deletions
diff --git a/crypto/src/math/ec/ECFieldElement.cs b/crypto/src/math/ec/ECFieldElement.cs index e589fc737..27c4ba2d0 100644 --- a/crypto/src/math/ec/ECFieldElement.cs +++ b/crypto/src/math/ec/ECFieldElement.cs @@ -55,6 +55,16 @@ namespace Org.BouncyCastle.Math.EC return Square().Add(x.Multiply(y)); } + public virtual ECFieldElement SquarePow(int pow) + { + ECFieldElement r = this; + for (int i = 0; i < pow; ++i) + { + r = r.Square(); + } + return r; + } + public virtual bool TestBitZero() { return ToBigInteger().TestBit(0); @@ -812,6 +822,11 @@ namespace Org.BouncyCastle.Math.EC return new F2mFieldElement(m, ks, aa); } + public override ECFieldElement SquarePow(int pow) + { + return pow < 1 ? this : new F2mFieldElement(m, ks, x.ModSquareN(pow, m, ks)); + } + public override ECFieldElement Invert() { return new F2mFieldElement(this.m, this.ks, this.x.ModInverse(m, ks)); @@ -819,14 +834,7 @@ namespace Org.BouncyCastle.Math.EC public override ECFieldElement Sqrt() { - LongArray x1 = this.x; - if (x1.IsOne() || x1.IsZero()) - { - return this; - } - - LongArray x2 = x1.ModSquareN(m - 1, m, ks); - return new F2mFieldElement(m, ks, x2); + return (x.IsZero() || x.IsOne()) ? this : SquarePow(m - 1); } /** |