CryptographicOperations.FixedTimeEquals Method

Definition

Determines the equality of two byte sequences in an amount of time that depends on the length of the sequences, but not their values.

C#
public static bool FixedTimeEquals(ReadOnlySpan<byte> left, ReadOnlySpan<byte> right);

Parameters

left
ReadOnlySpan<Byte>

The first buffer to compare.

right
ReadOnlySpan<Byte>

The second buffer to compare.

Returns

true if left and right have the same values for Length and the same contents; otherwise, false.

Remarks

This method compares the contents from two buffers for equality in a way that doesn't leak timing information, making it ideal for use within cryptographic routines.

This method will short-circuit and return false only if left and right have different lengths.

Fixed-time behavior is guaranteed in all other cases, including when left and right reference the same address.

Applies to

Product Versions
.NET Core 2.1, Core 2.2, Core 3.0, Core 3.1, 5, 6, 7, 8, 9, 10
.NET Standard 2.1