diff options
author | Peter Dettman <peter.dettman@bouncycastle.org> | 2014-01-21 18:22:20 +0700 |
---|---|---|
committer | Peter Dettman <peter.dettman@bouncycastle.org> | 2014-01-21 18:22:20 +0700 |
commit | f9d1a02949b1325b68d0a4d9f9c21cd53de2fb36 (patch) | |
tree | 0183c9fff430b51a18e00f7e9fac10c111d9c00e /crypto/src/math/ec/ECPoint.cs | |
parent | Fix digest test constructors (diff) | |
download | BouncyCastle.NET-ed25519-f9d1a02949b1325b68d0a4d9f9c21cd53de2fb36.tar.xz |
Fix Equals methods
Diffstat (limited to 'crypto/src/math/ec/ECPoint.cs')
-rw-r--r-- | crypto/src/math/ec/ECPoint.cs | 35 |
1 files changed, 21 insertions, 14 deletions
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; } // /** |