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

no-std constant_time_eq

Compares two equal-sized byte strings in constant time

15 releases

new 0.4.0 Feb 22, 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 973372/week @ 2024-11-01 984269/week @ 2024-11-08 1025309/week @ 2024-11-15 888991/week @ 2024-11-22 932277/week @ 2024-11-29 1271932/week @ 2024-12-06 1077716/week @ 2024-12-13 522706/week @ 2024-12-20 530183/week @ 2024-12-27 988392/week @ 2025-01-03 1263781/week @ 2025-01-10 1116609/week @ 2025-01-17 1196931/week @ 2025-01-24 1260595/week @ 2025-01-31 1409736/week @ 2025-02-07 595969/week @ 2025-02-14

4,674,269 downloads per month
Used in 6,009 crates (68 directly)

CC0-1.0 OR MIT-0 OR Apache-2.0

45KB
777 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