diff options
Diffstat (limited to 'crypto/src/math/ec/custom')
18 files changed, 27 insertions, 351 deletions
diff --git a/crypto/src/math/ec/custom/djb/Curve25519.cs b/crypto/src/math/ec/custom/djb/Curve25519.cs index 3dbdac051..712b68f29 100644 --- a/crypto/src/math/ec/custom/djb/Curve25519.cs +++ b/crypto/src/math/ec/custom/djb/Curve25519.cs @@ -1,13 +1,12 @@ using System; using Org.BouncyCastle.Math.EC.Custom.Sec; -using Org.BouncyCastle.Math.Field; using Org.BouncyCastle.Utilities.Encoders; namespace Org.BouncyCastle.Math.EC.Custom.Djb { internal class Curve25519 - : ECCurve + : AbstractFpCurve { public static readonly BigInteger q = Nat256.ToBigInteger(Curve25519Field.P); @@ -16,7 +15,7 @@ namespace Org.BouncyCastle.Math.EC.Custom.Djb protected readonly Curve25519Point m_infinity; public Curve25519() - : base(FiniteFields.GetPrimeField(q)) + : base(q) { this.m_infinity = new Curve25519Point(this, null, null); @@ -74,27 +73,5 @@ namespace Org.BouncyCastle.Math.EC.Custom.Djb { return new Curve25519Point(this, x, y, zs, withCompression); } - - protected override ECPoint DecompressPoint(int yTilde, BigInteger X1) - { - ECFieldElement x = FromBigInteger(X1); - ECFieldElement alpha = x.Square().Add(A).Multiply(x).Add(B); - ECFieldElement beta = alpha.Sqrt(); - - // - // if we can't find a sqrt we haven't got a point on the - // curve - run! - // - if (beta == null) - throw new ArithmeticException("Invalid point compression"); - - if (beta.TestBitZero() != (yTilde == 1)) - { - // Use the other root - beta = beta.Negate(); - } - - return new Curve25519Point(this, x, beta, true); - } } } diff --git a/crypto/src/math/ec/custom/djb/Curve25519Point.cs b/crypto/src/math/ec/custom/djb/Curve25519Point.cs index f3da59d16..bfec1d11d 100644 --- a/crypto/src/math/ec/custom/djb/Curve25519Point.cs +++ b/crypto/src/math/ec/custom/djb/Curve25519Point.cs @@ -5,7 +5,7 @@ using Org.BouncyCastle.Math.EC.Custom.Sec; namespace Org.BouncyCastle.Math.EC.Custom.Djb { internal class Curve25519Point - : ECPointBase + : AbstractFpPoint { /** * Create a point which encodes with point compression. @@ -48,11 +48,6 @@ namespace Org.BouncyCastle.Math.EC.Custom.Djb return new Curve25519Point(null, AffineXCoord, AffineYCoord); } - protected internal override bool CompressionYTilde - { - get { return this.AffineYCoord.TestBitZero(); } - } - public override ECFieldElement GetZCoord(int index) { if (index == 1) @@ -224,14 +219,6 @@ namespace Org.BouncyCastle.Math.EC.Custom.Djb return TwiceJacobianModified(false).Add(this); } - public override ECPoint Subtract(ECPoint b) - { - if (b.IsInfinity) - return this; - - return Add(b.Negate()); - } - public override ECPoint Negate() { if (IsInfinity) diff --git a/crypto/src/math/ec/custom/sec/SecP192K1Curve.cs b/crypto/src/math/ec/custom/sec/SecP192K1Curve.cs index 54b87588b..81f77197e 100644 --- a/crypto/src/math/ec/custom/sec/SecP192K1Curve.cs +++ b/crypto/src/math/ec/custom/sec/SecP192K1Curve.cs @@ -1,12 +1,11 @@ using System; -using Org.BouncyCastle.Math.Field; using Org.BouncyCastle.Utilities.Encoders; namespace Org.BouncyCastle.Math.EC.Custom.Sec { internal class SecP192K1Curve - : ECCurve + : AbstractFpCurve { public static readonly BigInteger q = new BigInteger(1, Hex.Decode("FFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFEFFFFEE37")); @@ -16,7 +15,7 @@ namespace Org.BouncyCastle.Math.EC.Custom.Sec protected readonly SecP192K1Point m_infinity; public SecP192K1Curve() - : base(FiniteFields.GetPrimeField(q)) + : base(q) { this.m_infinity = new SecP192K1Point(this, null, null); @@ -72,27 +71,5 @@ namespace Org.BouncyCastle.Math.EC.Custom.Sec { return new SecP192K1Point(this, x, y, zs, withCompression); } - - protected override ECPoint DecompressPoint(int yTilde, BigInteger X1) - { - ECFieldElement x = FromBigInteger(X1); - ECFieldElement alpha = x.Square().Multiply(x).Add(B); - ECFieldElement beta = alpha.Sqrt(); - - // - // if we can't find a sqrt we haven't got a point on the - // curve - run! - // - if (beta == null) - throw new ArithmeticException("Invalid point compression"); - - if (beta.TestBitZero() != (yTilde == 1)) - { - // Use the other root - beta = beta.Negate(); - } - - return new SecP192K1Point(this, x, beta, true); - } } } diff --git a/crypto/src/math/ec/custom/sec/SecP192K1Point.cs b/crypto/src/math/ec/custom/sec/SecP192K1Point.cs index 561324f8e..648aca502 100644 --- a/crypto/src/math/ec/custom/sec/SecP192K1Point.cs +++ b/crypto/src/math/ec/custom/sec/SecP192K1Point.cs @@ -3,7 +3,7 @@ namespace Org.BouncyCastle.Math.EC.Custom.Sec { internal class SecP192K1Point - : ECPointBase + : AbstractFpPoint { /** * Create a point which encodes with point compression. @@ -55,11 +55,6 @@ namespace Org.BouncyCastle.Math.EC.Custom.Sec return new SecP192K1Point(null, AffineXCoord, AffineYCoord); } - protected internal override bool CompressionYTilde - { - get { return this.AffineYCoord.TestBitZero(); } - } - public override ECPoint Add(ECPoint b) { if (this.IsInfinity) @@ -259,14 +254,6 @@ namespace Org.BouncyCastle.Math.EC.Custom.Sec return Twice().Add(this); } - public override ECPoint Subtract(ECPoint b) - { - if (b.IsInfinity) - return this; - - return Add(b.Negate()); - } - public override ECPoint Negate() { if (IsInfinity) diff --git a/crypto/src/math/ec/custom/sec/SecP192R1Curve.cs b/crypto/src/math/ec/custom/sec/SecP192R1Curve.cs index 57b20d31e..cb3a981c8 100644 --- a/crypto/src/math/ec/custom/sec/SecP192R1Curve.cs +++ b/crypto/src/math/ec/custom/sec/SecP192R1Curve.cs @@ -1,12 +1,11 @@ using System; -using Org.BouncyCastle.Math.Field; using Org.BouncyCastle.Utilities.Encoders; namespace Org.BouncyCastle.Math.EC.Custom.Sec { internal class SecP192R1Curve - : ECCurve + : AbstractFpCurve { public static readonly BigInteger q = new BigInteger(1, Hex.Decode("FFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFEFFFFFFFFFFFFFFFF")); @@ -16,7 +15,7 @@ namespace Org.BouncyCastle.Math.EC.Custom.Sec protected readonly SecP192R1Point m_infinity; public SecP192R1Curve() - : base(FiniteFields.GetPrimeField(q)) + : base(q) { this.m_infinity = new SecP192R1Point(this, null, null); @@ -75,27 +74,5 @@ namespace Org.BouncyCastle.Math.EC.Custom.Sec { return new SecP192R1Point(this, x, y, zs, withCompression); } - - protected override ECPoint DecompressPoint(int yTilde, BigInteger X1) - { - ECFieldElement x = FromBigInteger(X1); - ECFieldElement alpha = x.Square().Add(A).Multiply(x).Add(B); - ECFieldElement beta = alpha.Sqrt(); - - // - // if we can't find a sqrt we haven't got a point on the - // curve - run! - // - if (beta == null) - throw new ArithmeticException("Invalid point compression"); - - if (beta.TestBitZero() != (yTilde == 1)) - { - // Use the other root - beta = beta.Negate(); - } - - return new SecP192R1Point(this, x, beta, true); - } } } diff --git a/crypto/src/math/ec/custom/sec/SecP192R1Point.cs b/crypto/src/math/ec/custom/sec/SecP192R1Point.cs index c249c1269..797a8de35 100644 --- a/crypto/src/math/ec/custom/sec/SecP192R1Point.cs +++ b/crypto/src/math/ec/custom/sec/SecP192R1Point.cs @@ -3,7 +3,7 @@ namespace Org.BouncyCastle.Math.EC.Custom.Sec { internal class SecP192R1Point - : ECPointBase + : AbstractFpPoint { /** * Create a point which encodes with point compression. @@ -54,11 +54,6 @@ namespace Org.BouncyCastle.Math.EC.Custom.Sec return new SecP192R1Point(null, AffineXCoord, AffineYCoord); } - protected internal override bool CompressionYTilde - { - get { return this.AffineYCoord.TestBitZero(); } - } - public override ECPoint Add(ECPoint b) { if (this.IsInfinity) @@ -271,14 +266,6 @@ namespace Org.BouncyCastle.Math.EC.Custom.Sec return Twice().Add(this); } - public override ECPoint Subtract(ECPoint b) - { - if (b.IsInfinity) - return this; - - return Add(b.Negate()); - } - public override ECPoint Negate() { if (IsInfinity) diff --git a/crypto/src/math/ec/custom/sec/SecP224K1Curve.cs b/crypto/src/math/ec/custom/sec/SecP224K1Curve.cs index 70de308bb..d4be7d8de 100644 --- a/crypto/src/math/ec/custom/sec/SecP224K1Curve.cs +++ b/crypto/src/math/ec/custom/sec/SecP224K1Curve.cs @@ -1,12 +1,11 @@ using System; -using Org.BouncyCastle.Math.Field; using Org.BouncyCastle.Utilities.Encoders; namespace Org.BouncyCastle.Math.EC.Custom.Sec { internal class SecP224K1Curve - : ECCurve + : AbstractFpCurve { public static readonly BigInteger q = new BigInteger(1, Hex.Decode("FFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFEFFFFE56D")); @@ -16,7 +15,7 @@ namespace Org.BouncyCastle.Math.EC.Custom.Sec protected readonly SecP224K1Point m_infinity; public SecP224K1Curve() - : base(FiniteFields.GetPrimeField(q)) + : base(q) { this.m_infinity = new SecP224K1Point(this, null, null); @@ -72,27 +71,5 @@ namespace Org.BouncyCastle.Math.EC.Custom.Sec { return new SecP224K1Point(this, x, y, zs, withCompression); } - - protected override ECPoint DecompressPoint(int yTilde, BigInteger X1) - { - ECFieldElement x = FromBigInteger(X1); - ECFieldElement alpha = x.Square().Multiply(x).Add(B); - ECFieldElement beta = alpha.Sqrt(); - - // - // if we can't find a sqrt we haven't got a point on the - // curve - run! - // - if (beta == null) - throw new ArithmeticException("Invalid point compression"); - - if (beta.TestBitZero() != (yTilde == 1)) - { - // Use the other root - beta = beta.Negate(); - } - - return new SecP224K1Point(this, x, beta, true); - } } } diff --git a/crypto/src/math/ec/custom/sec/SecP224K1Point.cs b/crypto/src/math/ec/custom/sec/SecP224K1Point.cs index dd6faa829..8cbd29699 100644 --- a/crypto/src/math/ec/custom/sec/SecP224K1Point.cs +++ b/crypto/src/math/ec/custom/sec/SecP224K1Point.cs @@ -3,7 +3,7 @@ namespace Org.BouncyCastle.Math.EC.Custom.Sec { internal class SecP224K1Point - : ECPointBase + : AbstractFpPoint { /** * Create a point which encodes with point compression. @@ -55,11 +55,6 @@ namespace Org.BouncyCastle.Math.EC.Custom.Sec return new SecP224K1Point(null, AffineXCoord, AffineYCoord); } - protected internal override bool CompressionYTilde - { - get { return this.AffineYCoord.TestBitZero(); } - } - public override ECPoint Add(ECPoint b) { if (this.IsInfinity) @@ -259,14 +254,6 @@ namespace Org.BouncyCastle.Math.EC.Custom.Sec return Twice().Add(this); } - public override ECPoint Subtract(ECPoint b) - { - if (b.IsInfinity) - return this; - - return Add(b.Negate()); - } - public override ECPoint Negate() { if (IsInfinity) diff --git a/crypto/src/math/ec/custom/sec/SecP224R1Curve.cs b/crypto/src/math/ec/custom/sec/SecP224R1Curve.cs index 33b66be82..cda8781ff 100644 --- a/crypto/src/math/ec/custom/sec/SecP224R1Curve.cs +++ b/crypto/src/math/ec/custom/sec/SecP224R1Curve.cs @@ -1,12 +1,11 @@ using System; -using Org.BouncyCastle.Math.Field; using Org.BouncyCastle.Utilities.Encoders; namespace Org.BouncyCastle.Math.EC.Custom.Sec { internal class SecP224R1Curve - : ECCurve + : AbstractFpCurve { public static readonly BigInteger q = new BigInteger(1, Hex.Decode("FFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFF000000000000000000000001")); @@ -16,7 +15,7 @@ namespace Org.BouncyCastle.Math.EC.Custom.Sec protected readonly SecP224R1Point m_infinity; public SecP224R1Curve() - : base(FiniteFields.GetPrimeField(q)) + : base(q) { this.m_infinity = new SecP224R1Point(this, null, null); @@ -75,27 +74,5 @@ namespace Org.BouncyCastle.Math.EC.Custom.Sec { return new SecP224R1Point(this, x, y, zs, withCompression); } - - protected override ECPoint DecompressPoint(int yTilde, BigInteger X1) - { - ECFieldElement x = FromBigInteger(X1); - ECFieldElement alpha = x.Square().Add(A).Multiply(x).Add(B); - ECFieldElement beta = alpha.Sqrt(); - - // - // if we can't find a sqrt we haven't got a point on the - // curve - run! - // - if (beta == null) - throw new ArithmeticException("Invalid point compression"); - - if (beta.TestBitZero() != (yTilde == 1)) - { - // Use the other root - beta = beta.Negate(); - } - - return new SecP224R1Point(this, x, beta, true); - } } } diff --git a/crypto/src/math/ec/custom/sec/SecP224R1Point.cs b/crypto/src/math/ec/custom/sec/SecP224R1Point.cs index 3b339720d..c3f4efb59 100644 --- a/crypto/src/math/ec/custom/sec/SecP224R1Point.cs +++ b/crypto/src/math/ec/custom/sec/SecP224R1Point.cs @@ -3,7 +3,7 @@ namespace Org.BouncyCastle.Math.EC.Custom.Sec { internal class SecP224R1Point - : ECPointBase + : AbstractFpPoint { /** * Create a point which encodes with point compression. @@ -54,11 +54,6 @@ namespace Org.BouncyCastle.Math.EC.Custom.Sec return new SecP224R1Point(null, AffineXCoord, AffineYCoord); } - protected internal override bool CompressionYTilde - { - get { return this.AffineYCoord.TestBitZero(); } - } - public override ECPoint Add(ECPoint b) { if (this.IsInfinity) @@ -271,14 +266,6 @@ namespace Org.BouncyCastle.Math.EC.Custom.Sec return Twice().Add(this); } - public override ECPoint Subtract(ECPoint b) - { - if (b.IsInfinity) - return this; - - return Add(b.Negate()); - } - public override ECPoint Negate() { if (IsInfinity) diff --git a/crypto/src/math/ec/custom/sec/SecP256K1Curve.cs b/crypto/src/math/ec/custom/sec/SecP256K1Curve.cs index 89de61706..59e2cefb2 100644 --- a/crypto/src/math/ec/custom/sec/SecP256K1Curve.cs +++ b/crypto/src/math/ec/custom/sec/SecP256K1Curve.cs @@ -1,12 +1,11 @@ using System; -using Org.BouncyCastle.Math.Field; using Org.BouncyCastle.Utilities.Encoders; namespace Org.BouncyCastle.Math.EC.Custom.Sec { internal class SecP256K1Curve - : ECCurve + : AbstractFpCurve { public static readonly BigInteger q = new BigInteger(1, Hex.Decode("FFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFEFFFFFC2F")); @@ -16,7 +15,7 @@ namespace Org.BouncyCastle.Math.EC.Custom.Sec protected readonly SecP256K1Point m_infinity; public SecP256K1Curve() - : base(FiniteFields.GetPrimeField(q)) + : base(q) { this.m_infinity = new SecP256K1Point(this, null, null); @@ -72,27 +71,5 @@ namespace Org.BouncyCastle.Math.EC.Custom.Sec { return new SecP256K1Point(this, x, y, zs, withCompression); } - - protected override ECPoint DecompressPoint(int yTilde, BigInteger X1) - { - ECFieldElement x = FromBigInteger(X1); - ECFieldElement alpha = x.Square().Multiply(x).Add(B); - ECFieldElement beta = alpha.Sqrt(); - - // - // if we can't find a sqrt we haven't got a point on the - // curve - run! - // - if (beta == null) - throw new ArithmeticException("Invalid point compression"); - - if (beta.TestBitZero() != (yTilde == 1)) - { - // Use the other root - beta = beta.Negate(); - } - - return new SecP256K1Point(this, x, beta, true); - } } } diff --git a/crypto/src/math/ec/custom/sec/SecP256K1Point.cs b/crypto/src/math/ec/custom/sec/SecP256K1Point.cs index b12eadb72..3165682fa 100644 --- a/crypto/src/math/ec/custom/sec/SecP256K1Point.cs +++ b/crypto/src/math/ec/custom/sec/SecP256K1Point.cs @@ -3,7 +3,7 @@ namespace Org.BouncyCastle.Math.EC.Custom.Sec { internal class SecP256K1Point - : ECPointBase + : AbstractFpPoint { /** * Create a point which encodes with point compression. @@ -55,11 +55,6 @@ namespace Org.BouncyCastle.Math.EC.Custom.Sec return new SecP256K1Point(null, AffineXCoord, AffineYCoord); } - protected internal override bool CompressionYTilde - { - get { return this.AffineYCoord.TestBitZero(); } - } - public override ECPoint Add(ECPoint b) { if (this.IsInfinity) @@ -259,14 +254,6 @@ namespace Org.BouncyCastle.Math.EC.Custom.Sec return Twice().Add(this); } - public override ECPoint Subtract(ECPoint b) - { - if (b.IsInfinity) - return this; - - return Add(b.Negate()); - } - public override ECPoint Negate() { if (IsInfinity) diff --git a/crypto/src/math/ec/custom/sec/SecP256R1Curve.cs b/crypto/src/math/ec/custom/sec/SecP256R1Curve.cs index 9a94eb8d1..6b3448f06 100644 --- a/crypto/src/math/ec/custom/sec/SecP256R1Curve.cs +++ b/crypto/src/math/ec/custom/sec/SecP256R1Curve.cs @@ -1,12 +1,11 @@ using System; -using Org.BouncyCastle.Math.Field; using Org.BouncyCastle.Utilities.Encoders; namespace Org.BouncyCastle.Math.EC.Custom.Sec { internal class SecP256R1Curve - : ECCurve + : AbstractFpCurve { public static readonly BigInteger q = new BigInteger(1, Hex.Decode("FFFFFFFF00000001000000000000000000000000FFFFFFFFFFFFFFFFFFFFFFFF")); @@ -16,7 +15,7 @@ namespace Org.BouncyCastle.Math.EC.Custom.Sec protected readonly SecP256R1Point m_infinity; public SecP256R1Curve() - : base(FiniteFields.GetPrimeField(q)) + : base(q) { this.m_infinity = new SecP256R1Point(this, null, null); @@ -74,27 +73,5 @@ namespace Org.BouncyCastle.Math.EC.Custom.Sec { return new SecP256R1Point(this, x, y, zs, withCompression); } - - protected override ECPoint DecompressPoint(int yTilde, BigInteger X1) - { - ECFieldElement x = FromBigInteger(X1); - ECFieldElement alpha = x.Square().Add(A).Multiply(x).Add(B); - ECFieldElement beta = alpha.Sqrt(); - - // - // if we can't find a sqrt we haven't got a point on the - // curve - run! - // - if (beta == null) - throw new ArithmeticException("Invalid point compression"); - - if (beta.TestBitZero() != (yTilde == 1)) - { - // Use the other root - beta = beta.Negate(); - } - - return new SecP256R1Point(this, x, beta, true); - } } } diff --git a/crypto/src/math/ec/custom/sec/SecP256R1Point.cs b/crypto/src/math/ec/custom/sec/SecP256R1Point.cs index 0e4b95a10..1de4a0b4a 100644 --- a/crypto/src/math/ec/custom/sec/SecP256R1Point.cs +++ b/crypto/src/math/ec/custom/sec/SecP256R1Point.cs @@ -3,7 +3,7 @@ namespace Org.BouncyCastle.Math.EC.Custom.Sec { internal class SecP256R1Point - : ECPointBase + : AbstractFpPoint { /** * Create a point which encodes with point compression. @@ -54,11 +54,6 @@ namespace Org.BouncyCastle.Math.EC.Custom.Sec return new SecP256R1Point(null, AffineXCoord, AffineYCoord); } - protected internal override bool CompressionYTilde - { - get { return this.AffineYCoord.TestBitZero(); } - } - public override ECPoint Add(ECPoint b) { if (this.IsInfinity) @@ -271,14 +266,6 @@ namespace Org.BouncyCastle.Math.EC.Custom.Sec return Twice().Add(this); } - public override ECPoint Subtract(ECPoint b) - { - if (b.IsInfinity) - return this; - - return Add(b.Negate()); - } - public override ECPoint Negate() { if (IsInfinity) diff --git a/crypto/src/math/ec/custom/sec/SecP384R1Curve.cs b/crypto/src/math/ec/custom/sec/SecP384R1Curve.cs index f3dec05c9..7fd58276a 100644 --- a/crypto/src/math/ec/custom/sec/SecP384R1Curve.cs +++ b/crypto/src/math/ec/custom/sec/SecP384R1Curve.cs @@ -1,12 +1,11 @@ using System; -using Org.BouncyCastle.Math.Field; using Org.BouncyCastle.Utilities.Encoders; namespace Org.BouncyCastle.Math.EC.Custom.Sec { internal class SecP384R1Curve - : ECCurve + : AbstractFpCurve { public static readonly BigInteger q = new BigInteger(1, Hex.Decode("FFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFEFFFFFFFF0000000000000000FFFFFFFF")); @@ -16,7 +15,7 @@ namespace Org.BouncyCastle.Math.EC.Custom.Sec protected readonly SecP384R1Point m_infinity; public SecP384R1Curve() - : base(FiniteFields.GetPrimeField(q)) + : base(q) { this.m_infinity = new SecP384R1Point(this, null, null); @@ -74,27 +73,5 @@ namespace Org.BouncyCastle.Math.EC.Custom.Sec { return new SecP384R1Point(this, x, y, zs, withCompression); } - - protected override ECPoint DecompressPoint(int yTilde, BigInteger X1) - { - ECFieldElement x = FromBigInteger(X1); - ECFieldElement alpha = x.Square().Add(A).Multiply(x).Add(B); - ECFieldElement beta = alpha.Sqrt(); - - // - // if we can't find a sqrt we haven't got a point on the - // curve - run! - // - if (beta == null) - throw new ArithmeticException("Invalid point compression"); - - if (beta.TestBitZero() != (yTilde == 1)) - { - // Use the other root - beta = beta.Negate(); - } - - return new SecP384R1Point(this, x, beta, true); - } } } diff --git a/crypto/src/math/ec/custom/sec/SecP384R1Point.cs b/crypto/src/math/ec/custom/sec/SecP384R1Point.cs index 1ca8489dc..68c601611 100644 --- a/crypto/src/math/ec/custom/sec/SecP384R1Point.cs +++ b/crypto/src/math/ec/custom/sec/SecP384R1Point.cs @@ -3,7 +3,7 @@ namespace Org.BouncyCastle.Math.EC.Custom.Sec { internal class SecP384R1Point - : ECPointBase + : AbstractFpPoint { /** * Create a point which encodes with point compression. @@ -54,11 +54,6 @@ namespace Org.BouncyCastle.Math.EC.Custom.Sec return new SecP384R1Point(null, AffineXCoord, AffineYCoord); } - protected internal override bool CompressionYTilde - { - get { return this.AffineYCoord.TestBitZero(); } - } - public override ECPoint Add(ECPoint b) { if (this.IsInfinity) @@ -272,14 +267,6 @@ namespace Org.BouncyCastle.Math.EC.Custom.Sec return Twice().Add(this); } - public override ECPoint Subtract(ECPoint b) - { - if (b.IsInfinity) - return this; - - return Add(b.Negate()); - } - public override ECPoint Negate() { if (IsInfinity) diff --git a/crypto/src/math/ec/custom/sec/SecP521R1Curve.cs b/crypto/src/math/ec/custom/sec/SecP521R1Curve.cs index cb42304ef..e5083c7f0 100644 --- a/crypto/src/math/ec/custom/sec/SecP521R1Curve.cs +++ b/crypto/src/math/ec/custom/sec/SecP521R1Curve.cs @@ -1,12 +1,11 @@ using System; -using Org.BouncyCastle.Math.Field; using Org.BouncyCastle.Utilities.Encoders; namespace Org.BouncyCastle.Math.EC.Custom.Sec { internal class SecP521R1Curve - : ECCurve + : AbstractFpCurve { public static readonly BigInteger q = new BigInteger(1, Hex.Decode("01FFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFF")); @@ -16,7 +15,7 @@ namespace Org.BouncyCastle.Math.EC.Custom.Sec protected readonly SecP521R1Point m_infinity; public SecP521R1Curve() - : base(FiniteFields.GetPrimeField(q)) + : base(q) { this.m_infinity = new SecP521R1Point(this, null, null); @@ -74,27 +73,5 @@ namespace Org.BouncyCastle.Math.EC.Custom.Sec { return new SecP521R1Point(this, x, y, zs, withCompression); } - - protected override ECPoint DecompressPoint(int yTilde, BigInteger X1) - { - ECFieldElement x = FromBigInteger(X1); - ECFieldElement alpha = x.Square().Add(A).Multiply(x).Add(B); - ECFieldElement beta = alpha.Sqrt(); - - // - // if we can't find a sqrt we haven't got a point on the - // curve - run! - // - if (beta == null) - throw new ArithmeticException("Invalid point compression"); - - if (beta.TestBitZero() != (yTilde == 1)) - { - // Use the other root - beta = beta.Negate(); - } - - return new SecP521R1Point(this, x, beta, true); - } } } diff --git a/crypto/src/math/ec/custom/sec/SecP521R1Point.cs b/crypto/src/math/ec/custom/sec/SecP521R1Point.cs index 44d590f08..fb1996cfd 100644 --- a/crypto/src/math/ec/custom/sec/SecP521R1Point.cs +++ b/crypto/src/math/ec/custom/sec/SecP521R1Point.cs @@ -3,7 +3,7 @@ namespace Org.BouncyCastle.Math.EC.Custom.Sec { internal class SecP521R1Point - : ECPointBase + : AbstractFpPoint { /** * Create a point which encodes with point compression. @@ -54,11 +54,6 @@ namespace Org.BouncyCastle.Math.EC.Custom.Sec return new SecP521R1Point(null, AffineXCoord, AffineYCoord); } - protected internal override bool CompressionYTilde - { - get { return this.AffineYCoord.TestBitZero(); } - } - public override ECPoint Add(ECPoint b) { if (this.IsInfinity) @@ -267,14 +262,6 @@ namespace Org.BouncyCastle.Math.EC.Custom.Sec return Twice().Add(this); } - public override ECPoint Subtract(ECPoint b) - { - if (b.IsInfinity) - return this; - - return Add(b.Negate()); - } - public override ECPoint Negate() { if (IsInfinity) |