diff options
author | Peter Dettman <peter.dettman@bouncycastle.org> | 2022-08-30 17:35:03 +0700 |
---|---|---|
committer | Peter Dettman <peter.dettman@bouncycastle.org> | 2022-08-30 17:35:03 +0700 |
commit | 114297f192b5da1b789ea554ed02e7329cc2e9fb (patch) | |
tree | e1588266581b85a54ef88ca9e7ae6c52798a0252 /crypto/src/util | |
parent | Add span concatenation methods (diff) | |
download | BouncyCastle.NET-ed25519-114297f192b5da1b789ea554ed02e7329cc2e9fb.tar.xz |
Span-based variant for IAeadCipher.DoFinal
Diffstat (limited to 'crypto/src/util')
-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) |