diff options
author | Peter Dettman <peter.dettman@bouncycastle.org> | 2019-10-23 15:14:32 +0700 |
---|---|---|
committer | Peter Dettman <peter.dettman@bouncycastle.org> | 2019-10-23 15:14:32 +0700 |
commit | e602a69f7523bb60ce3c8770bc2340f79a39a7ae (patch) | |
tree | 8ddb5beec0f6ac8eb7990ac465e5d157dd6cde1c /crypto/src/util/Arrays.cs | |
parent | Add ChaCha ciphers to factory classes (diff) | |
download | BouncyCastle.NET-ed25519-e602a69f7523bb60ce3c8770bc2340f79a39a7ae.tar.xz |
Improve ChaCha20Poly1305 tests
- focused on processing array sub-ranges
Diffstat (limited to 'crypto/src/util/Arrays.cs')
-rw-r--r-- | crypto/src/util/Arrays.cs | 21 |
1 files changed, 18 insertions, 3 deletions
diff --git a/crypto/src/util/Arrays.cs b/crypto/src/util/Arrays.cs index 6f2503d2d..7b1766bba 100644 --- a/crypto/src/util/Arrays.cs +++ b/crypto/src/util/Arrays.cs @@ -53,9 +53,7 @@ namespace Org.BouncyCastle.Utilities /// <param name="a">Left side.</param> /// <param name="b">Right side.</param> /// <returns>True if equal.</returns> - public static bool AreEqual( - byte[] a, - byte[] b) + public static bool AreEqual(byte[] a, byte[] b) { if (a == b) return true; @@ -66,6 +64,23 @@ namespace Org.BouncyCastle.Utilities return HaveSameContents(a, b); } + public static bool AreEqual(byte[] a, int aFromIndex, int aToIndex, byte[] b, int bFromIndex, int bToIndex) + { + int aLength = aToIndex - aFromIndex; + int bLength = bToIndex - bFromIndex; + + if (aLength != bLength) + return false; + + for (int i = 0; i < aLength; ++i) + { + if (a[aFromIndex + i] != b[bFromIndex + i]) + return false; + } + + return true; + } + [Obsolete("Use 'AreEqual' method instead")] public static bool AreSame( byte[] a, |