#constant-time #byte-string #comparison #input #linux-kernel

no-std constant_time_eq

Compares two equal-sized byte strings in constant time

16 releases

new 0.4.1 Mar 4, 2025
0.3.1 Aug 27, 2024
0.3.0 Jun 17, 2023
0.2.5 Mar 12, 2023
0.1.0 May 22, 2015

#25 in Cryptography

Download history 1007613/week @ 2024-11-17 834701/week @ 2024-11-24 988544/week @ 2024-12-01 1329311/week @ 2024-12-08 1002894/week @ 2024-12-15 443393/week @ 2024-12-22 598469/week @ 2024-12-29 1072006/week @ 2025-01-05 1263033/week @ 2025-01-12 1122871/week @ 2025-01-19 1194478/week @ 2025-01-26 1302055/week @ 2025-02-02 1435605/week @ 2025-02-09 1481166/week @ 2025-02-16 1390028/week @ 2025-02-23 1730219/week @ 2025-03-02

6,131,946 downloads per month
Used in 6,067 crates (68 directly)

CC0-1.0 OR MIT-0 OR Apache-2.0

44KB
760 lines

Compares two equal-sized byte strings in constant time.

Inspired by the Linux kernel's crypto_memneq.

Licensed under either of

  • Apache License, Version 2.0 (LICENSE-APACHE)
  • MIT No Attribution License (LICENSE-MIT0)
  • CC0 1.0 Universal (LICENSE-CC0)

at your option.


lib.rs:

Compares two equal-sized byte strings in constant time.

The time of the comparison does not depend on:

  • The contents of the inputs;
  • The position of the difference(s) between the inputs.

The time of the comparison can depend on:

  • The memory addresses of the inputs;
  • The length of the inputs.

No runtime deps