From 5e1ef1cb46ed4967423d16805b9ac780c4ba9599 Mon Sep 17 00:00:00 2001 From: Peter Dettman Date: Thu, 27 Feb 2014 13:01:12 +0700 Subject: Equality/hashcode should ignore "excess" words --- crypto/src/util/Arrays.cs | 54 +++++++++++++++++++++++++++++++++++++++++++++++ 1 file changed, 54 insertions(+) (limited to 'crypto/src/util/Arrays.cs') 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) { -- cgit 1.4.1