summary refs log tree commit diff
path: root/crypto/src/util/Arrays.cs
diff options
context:
space:
mode:
authorPeter Dettman <peter.dettman@bouncycastle.org>2014-02-27 13:01:12 +0700
committerPeter Dettman <peter.dettman@bouncycastle.org>2014-02-27 13:01:12 +0700
commit5e1ef1cb46ed4967423d16805b9ac780c4ba9599 (patch)
tree3002a808a4d7c745e0316b0a8b2f3a2946bec0b6 /crypto/src/util/Arrays.cs
parentOptimize Sqrt() for custom secp384r1 (diff)
downloadBouncyCastle.NET-ed25519-5e1ef1cb46ed4967423d16805b9ac780c4ba9599.tar.xz
Equality/hashcode should ignore "excess" words
Diffstat (limited to 'crypto/src/util/Arrays.cs')
-rw-r--r--crypto/src/util/Arrays.cs54
1 files changed, 54 insertions, 0 deletions
diff --git a/crypto/src/util/Arrays.cs b/crypto/src/util/Arrays.cs
index cc2025ef3..a21dd00b1 100644
--- a/crypto/src/util/Arrays.cs
+++ b/crypto/src/util/Arrays.cs
@@ -220,6 +220,25 @@ namespace Org.BouncyCastle.Utilities
             return hc;
         }
 
+        public static int GetHashCode(byte[] data, int off, int len)
+        {
+            if (data == null)
+            {
+                return 0;
+            }
+
+            int i = len;
+            int hc = i + 1;
+
+            while (--i >= 0)
+            {
+                hc *= 257;
+                hc ^= data[off + i];
+            }
+
+            return hc;
+        }
+
         public static int GetHashCode(int[] data)
         {
             if (data == null)
@@ -237,6 +256,23 @@ namespace Org.BouncyCastle.Utilities
             return hc;
         }
 
+        public static int GetHashCode(int[] data, int off, int len)
+        {
+            if (data == null)
+                return 0;
+
+            int i = len;
+            int hc = i + 1;
+
+            while (--i >= 0)
+            {
+                hc *= 257;
+                hc ^= data[off + i];
+            }
+
+            return hc;
+        }
+
         [CLSCompliantAttribute(false)]
         public static int GetHashCode(uint[] data)
         {
@@ -255,6 +291,24 @@ namespace Org.BouncyCastle.Utilities
             return hc;
         }
 
+        [CLSCompliantAttribute(false)]
+        public static int GetHashCode(uint[] data, int off, int len)
+        {
+            if (data == null)
+                return 0;
+
+            int i = len;
+            int hc = i + 1;
+
+            while (--i >= 0)
+            {
+                hc *= 257;
+                hc ^= (int)data[off + i];
+            }
+
+            return hc;
+        }
+
         public static byte[] Clone(
             byte[] data)
         {