diff options
Diffstat (limited to 'crypto/src/util/Arrays.cs')
-rw-r--r-- | crypto/src/util/Arrays.cs | 18 |
1 files changed, 17 insertions, 1 deletions
diff --git a/crypto/src/util/Arrays.cs b/crypto/src/util/Arrays.cs index 7a1e80115..d3dae98a9 100644 --- a/crypto/src/util/Arrays.cs +++ b/crypto/src/util/Arrays.cs @@ -124,11 +124,27 @@ namespace Org.BouncyCastle.Utilities int d = 0; for (int i = 0; i < len; ++i) { - d |= (a[aOff + i] ^ b[bOff + i]); + d |= a[aOff + i] ^ b[bOff + i]; } return 0 == d; } +#if NETCOREAPP2_1_OR_GREATER || NETSTANDARD2_1_OR_GREATER + public static bool ConstantTimeAreEqual(Span<byte> a, Span<byte> b) + { + if (a.Length != b.Length) + throw new ArgumentException("Spans to compare must have equal length"); + + int d = 0; + for (int i = 0, count = a.Length; i < count; ++i) + { + d |= a[i] ^ b[i]; + } + return 0 == d; + + } +#endif + public static bool AreEqual( int[] a, int[] b) |