summary refs log tree commit diff
path: root/crypto/src
diff options
context:
space:
mode:
authorPeter Dettman <peter.dettman@bouncycastle.org>2014-01-21 18:22:20 +0700
committerPeter Dettman <peter.dettman@bouncycastle.org>2014-01-21 18:22:20 +0700
commitf9d1a02949b1325b68d0a4d9f9c21cd53de2fb36 (patch)
tree0183c9fff430b51a18e00f7e9fac10c111d9c00e /crypto/src
parentFix digest test constructors (diff)
downloadBouncyCastle.NET-ed25519-f9d1a02949b1325b68d0a4d9f9c21cd53de2fb36.tar.xz
Fix Equals methods
Diffstat (limited to 'crypto/src')
-rw-r--r--crypto/src/math/ec/ECFieldElement.cs20
-rw-r--r--crypto/src/math/ec/ECPoint.cs35
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;
         }
 
 //		/**