diff options
author | Peter Dettman <peter.dettman@bouncycastle.org> | 2014-02-27 13:01:12 +0700 |
---|---|---|
committer | Peter Dettman <peter.dettman@bouncycastle.org> | 2014-02-27 13:01:12 +0700 |
commit | 5e1ef1cb46ed4967423d16805b9ac780c4ba9599 (patch) | |
tree | 3002a808a4d7c745e0316b0a8b2f3a2946bec0b6 /crypto/src/util | |
parent | Optimize Sqrt() for custom secp384r1 (diff) | |
download | BouncyCastle.NET-ed25519-5e1ef1cb46ed4967423d16805b9ac780c4ba9599.tar.xz |
Equality/hashcode should ignore "excess" words
Diffstat (limited to 'crypto/src/util')
-rw-r--r-- | crypto/src/util/Arrays.cs | 54 |
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) { |