summary refs log tree commit diff
path: root/crypto/src/math/ec
diff options
context:
space:
mode:
Diffstat (limited to 'crypto/src/math/ec')
-rw-r--r--crypto/src/math/ec/ECFieldElement.cs55
-rw-r--r--crypto/src/math/ec/LongArray.cs15
2 files changed, 23 insertions, 47 deletions
diff --git a/crypto/src/math/ec/ECFieldElement.cs b/crypto/src/math/ec/ECFieldElement.cs
index 3afc843cd..e2306a7a9 100644
--- a/crypto/src/math/ec/ECFieldElement.cs
+++ b/crypto/src/math/ec/ECFieldElement.cs
@@ -516,29 +516,24 @@ namespace Org.BouncyCastle.Math.EC
             return x3;
         }
 
-        public override bool Equals(
-            object obj)
+        public override bool Equals(object obj) => obj is FpFieldElement that && Equals(that);
+
+        public virtual bool Equals(FpFieldElement other)
         {
-            if (obj == this)
+            if (this == other)
                 return true;
 
-            FpFieldElement other = obj as FpFieldElement;
-
-            if (other == null)
-                return false;
-
-            return Equals(other);
-        }
-
-        public virtual bool Equals(
-            FpFieldElement other)
-        {
-            return q.Equals(other.q) && base.Equals(other);
+            return q.Equals(other.q)
+                && x.Equals(other.x);
         }
 
         public override int GetHashCode()
         {
-            return q.GetHashCode() ^ base.GetHashCode();
+#if NETCOREAPP2_1_OR_GREATER || NETSTANDARD2_1_OR_GREATER
+            return HashCode.Combine(q, x);
+#else
+            return q.GetHashCode() ^ x.GetHashCode();
+#endif
         }
     }
 
@@ -910,32 +905,26 @@ namespace Org.BouncyCastle.Math.EC
             get { return this.ks.Length >= 3 ? this.ks[2] : 0; }
         }
 
-        public override bool Equals(
-            object obj)
+        public override bool Equals(object obj) => obj is F2mFieldElement that && Equals(that);
+
+        public virtual bool Equals(F2mFieldElement other)
         {
-            if (obj == this)
+            if (this == other)
                 return true;
 
-            F2mFieldElement other = obj as F2mFieldElement;
-
-            if (other == null)
-                return false;
-
-            return Equals(other);
-        }
-
-        public virtual bool Equals(
-            F2mFieldElement other)
-        {
-            return ((this.m == other.m)
-                && (this.representation == other.representation)
+            return this.m == other.m
+                && this.representation == other.representation
                 && Arrays.AreEqual(this.ks, other.ks)
-                && (this.x.Equals(other.x)));
+                && this.x.Equals(other.x);
         }
 
         public override int GetHashCode()
         {
+#if NETCOREAPP2_1_OR_GREATER || NETSTANDARD2_1_OR_GREATER
+            return HashCode.Combine(x, m, Arrays.GetHashCode(ks));
+#else
             return x.GetHashCode() ^ m ^ Arrays.GetHashCode(ks);
+#endif
         }
     }
 }
diff --git a/crypto/src/math/ec/LongArray.cs b/crypto/src/math/ec/LongArray.cs
index 3475e9ecc..e492f2913 100644
--- a/crypto/src/math/ec/LongArray.cs
+++ b/crypto/src/math/ec/LongArray.cs
@@ -1245,20 +1245,7 @@ namespace Org.BouncyCastle.Math.EC
             return true;
         }
 
-        public override int GetHashCode()
-        {
-            int usedLen = GetUsedLength();
-            int hash = 1;
-            for (int i = 0; i < usedLen; i++)
-            {
-                ulong mi = m_data[i];
-                hash *= 31;
-                hash ^= (int)mi;
-                hash *= 31;
-                hash ^= (int)(mi >> 32);
-            }
-            return hash;
-        }
+        public override int GetHashCode() => Arrays.GetHashCode(m_data, 0, GetUsedLength());
 
         public LongArray Copy()
         {