#secret

secret_integers

Wrapping around Rust's integers to allow only constant-time operations

8 releases

0.1.7 Mar 20, 2023
0.1.6 Jan 30, 2020
0.1.5 Dec 23, 2019
0.1.3 Feb 7, 2019
0.1.2 Jan 30, 2019

#44 in #secret

Download history 70/week @ 2024-07-23 82/week @ 2024-07-30 138/week @ 2024-08-06 167/week @ 2024-08-13 146/week @ 2024-08-20 169/week @ 2024-08-27 262/week @ 2024-09-03 150/week @ 2024-09-10 207/week @ 2024-09-17 175/week @ 2024-09-24 132/week @ 2024-10-01 96/week @ 2024-10-08 174/week @ 2024-10-15 131/week @ 2024-10-22 181/week @ 2024-10-29 188/week @ 2024-11-05

699 downloads per month
Used in 12 crates (4 directly)

Apache-2.0

27KB
472 lines

Rust secret integers

This simple crate provides integer wrappers that guarantee that they are being used in a constant-time fashion. Hence, division and direct comparison are disallowed. Using Rust's type system, this crate will help the compiler check systematically whether your cryptographic code is constant-time relative to secret inputs.

To use the crate, just import everything (use secret_integers::*;) and replace your integer types with uppercase versions of their names (e.g. u8 -> U8).

Examples

Two examples show how to use the crate : Dalek and Chacha20. To build theses examples, use

cargo build --example dalek
cargo build --example chacha20

However, if you try:

cargo build --example biguint

You will get the following error message:

error[E0599]: no method named `leading_zeros` found for type `&secret_integers::U32` in the current scope
--> examples/biguint.rs:24:46
 |
24 |        let zeros = self.data.last().unwrap().leading_zeros();
 |                                              ^^^^^^^^^^^^^

error[E0369]: binary operation `!=` cannot be applied to type `secret_integers::U32`
--> examples/biguint.rs:48:11
 |
48 |     while r != 0 {
 |           ^^^^^^
 |
 = note: an implementation of `std::cmp::PartialEq` might be missing for `secret_integers::U32`

No runtime deps