The documentation is currently being reviewed, so you may see some inconsistencies between sections.
For the complete documentation index, see llms.txt. This page is also available as Markdown.

Constant time

Purpose

Whenever you interact with secrets and cryptographic parameters, you should use constant time functions to avoid leaking information via timing to an attacker. Such leaks can completely compromise security.

For example, you should increment counters/nonces, compare tags, compare retyped passwords, and so on using this class.

Usage

Equals

Returns whether two spans are equal in length and contain equal data.

bool equal = ConstantTime.Equals(ReadOnlySpan<byte> a, ReadOnlySpan<byte> b);

Exceptions

ArgumentOutOfRangeException

a.Length is equal to 0.

ArgumentOutOfRangeException

b.Length is equal to 0.

Increment

Increments a span counter in little-endian format.

Exceptions

ArgumentOutOfRangeException

buffer.Length is equal to 0.

Add

Fills a span with the sum of two spans in little-endian format.

Exceptions

ArgumentOutOfRangeException

buffer.Length is equal to 0.

ArgumentOutOfRangeException

a.Length is equal to 0 or not equal to buffer.Length.

ArgumentOutOfRangeException

b.Length is equal to 0 or not equal to a.Length.

Subtract

Fills a span with the result of subtracting the second span from the first span in little-endian format.

Exceptions

ArgumentOutOfRangeException

buffer.Length is equal to 0.

ArgumentOutOfRangeException

a.Length is equal to 0 or not equal to buffer.Length.

ArgumentOutOfRangeException

b.Length is equal to 0 or not equal to a.Length.

IsLessThan

Returns whether the contents of the first span is less than the second span in little-endian format.

Exceptions

ArgumentOutOfRangeException

a.Length is equal to 0 or not equal to b.Length.

ArgumentOutOfRangeException

b.Length is equal to 0.

IsGreaterThan

Returns whether the contents of the first span is greater than the second span in little-endian format.

Exceptions

ArgumentOutOfRangeException

a.Length is equal to 0 or not equal to b.Length.

ArgumentOutOfRangeException

b.Length is equal to 0.

IsAllZeros

Returns whether a span only contains zeros.

Exceptions

ArgumentOutOfRangeException

buffer.Length is equal to 0.

Notes

Last updated