rust-timing-shield

comprehensive timing leak protection for Rust
let secret: TpU64; // a timing-protected u64
let numbers: Vec<u64>; // a normal vector of u64

// TYPE ERROR:
// timing-protected value used in array index
let number = numbers[secret & 0xFF];

// TYPE ERROR:
// branch on timing-protected value
if (secret & 0x01) == 0x01 {
	// ...
}

Why does this exist

A fundamental challenge in writing software that operates on sensitive information is preventing timing leaks. A timing leak is when there exists a relationship between the values of secret variables in your program and the execution time of your code or other code running on the same hardware. Attackers who are aware of this relationship can use a high-resolution timer to learn secret information that they would not normally be able to access (e.g. extract an SSL key from a web server).
With cryptography code in particular, it is an established best practice to write code that is constant-time. For a full background on writing constant-time code, see A beginner's guide to constant-time cryptography.
rust-timing-shield is a framework for writing code without timing leaks, with the goal of making it easy to implement cryptography algorithms in constant-time.

Safe

timing vulnerabilities trigger compile-time errors

Easy to use

writing constant-time code doesn't need to be hard

Fast

minimal overhead, often zero-cost

Installation

Install the timing-shield crate with Cargo by adding it to the dependencies section of Cargo.toml:
[dependencies]
timing-shield = "0.3.0"
Alternatively, the source code is available on GitHub.
Next: Getting Started   →