From 114297f192b5da1b789ea554ed02e7329cc2e9fb Mon Sep 17 00:00:00 2001 From: Peter Dettman Date: Tue, 30 Aug 2022 17:35:03 +0700 Subject: Span-based variant for IAeadCipher.DoFinal --- crypto/src/util/Arrays.cs | 18 +++++++++++++++++- 1 file changed, 17 insertions(+), 1 deletion(-) (limited to 'crypto/src/util') 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 a, Span 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) -- cgit 1.4.1