summary refs log tree commit diff
path: root/crypto/src/math/BigInteger.cs
diff options
context:
space:
mode:
Diffstat (limited to 'crypto/src/math/BigInteger.cs')
-rw-r--r--crypto/src/math/BigInteger.cs10
1 files changed, 10 insertions, 0 deletions
diff --git a/crypto/src/math/BigInteger.cs b/crypto/src/math/BigInteger.cs
index e5ab22e92..588adaf77 100644
--- a/crypto/src/math/BigInteger.cs
+++ b/crypto/src/math/BigInteger.cs
@@ -5,6 +5,9 @@ using System.Globalization;
 #if NETCOREAPP3_0_OR_GREATER
 using System.Numerics;
 #endif
+#if NETCOREAPP2_1_OR_GREATER || NETSTANDARD2_1_OR_GREATER
+using System.Runtime.InteropServices;
+#endif
 using System.Runtime.Serialization;
 using System.Text;
 
@@ -1464,6 +1467,12 @@ namespace Org.BouncyCastle.Math
 
         public override int GetHashCode()
         {
+#if NETCOREAPP2_1_OR_GREATER || NETSTANDARD2_1_OR_GREATER
+            HashCode hc = default;
+            hc.AddBytes(MemoryMarshal.AsBytes(magnitude.AsSpan()));
+            hc.Add(sign);
+            return hc.ToHashCode();
+#else
             int hc = magnitude.Length;
             if (magnitude.Length > 0)
             {
@@ -1476,6 +1485,7 @@ namespace Org.BouncyCastle.Math
             }
 
             return sign < 0 ? ~hc : hc;
+#endif
         }
 
         // TODO Make public?