Fix Equals methods
2 files changed, 28 insertions, 27 deletions
diff --git a/crypto/src/math/ec/ECFieldElement.cs b/crypto/src/math/ec/ECFieldElement.cs
index cc5050002..fb0e8535b 100644
--- a/crypto/src/math/ec/ECFieldElement.cs
+++ b/crypto/src/math/ec/ECFieldElement.cs
@@ -39,23 +39,17 @@ namespace Org.BouncyCastle.Math.EC
return ToBigInteger().TestBit(0);
}
- public override bool Equals(
- object obj)
+ public override bool Equals(object obj)
{
- if (obj == this)
- return true;
-
- ECFieldElement other = obj as ECFieldElement;
-
- if (other == null)
- return false;
-
- return Equals(other);
+ return Equals(obj as ECFieldElement);
}
- public virtual bool Equals(
- ECFieldElement other)
+ public virtual bool Equals(ECFieldElement other)
{
+ if (this == other)
+ return true;
+ if (null == other)
+ return false;
return ToBigInteger().Equals(other.ToBigInteger());
}
diff --git a/crypto/src/math/ec/ECPoint.cs b/crypto/src/math/ec/ECPoint.cs
index 6a06be4d1..e4ce58d2d 100644
--- a/crypto/src/math/ec/ECPoint.cs
+++ b/crypto/src/math/ec/ECPoint.cs
@@ -59,29 +59,36 @@ namespace Org.BouncyCastle.Math.EC
get { return withCompression; }
}
- public override bool Equals(
- object obj)
+ public override bool Equals(object obj)
{
- if (obj == this)
- return true;
-
- ECPoint o = obj as ECPoint;
+ return Equals(obj as ECPoint);
+ }
- if (o == null)
+ public virtual bool Equals(ECPoint other)
+ {
+ if (this == other)
+ return true;
+ if (null == other)
return false;
- if (this.IsInfinity)
- return o.IsInfinity;
+ bool i1 = IsInfinity, i2 = other.IsInfinity;
+ if (i1 || i2)
+ {
+ return i1 && i2;
+ }
- return x.Equals(o.x) && y.Equals(o.y);
+ return X.Equals(other.X) && Y.Equals(other.Y);
}
public override int GetHashCode()
{
- if (this.IsInfinity)
- return 0;
-
- return x.GetHashCode() ^ y.GetHashCode();
+ int hc = 0;
+ if (!IsInfinity)
+ {
+ hc ^= X.GetHashCode() * 17;
+ hc ^= Y.GetHashCode() * 257;
+ }
+ return hc;
}
// /**
|