6 stable releases

2.2.2 Nov 27, 2019
2.1.1 Jul 31, 2019
2.0.0 Dec 13, 2018
2.0.0-pre.0 Nov 5, 2018
0.2.0 Jul 31, 2017

#10 in Cryptography

Download history 23678/week @ 2019-08-14 21998/week @ 2019-08-21 22145/week @ 2019-08-28 22893/week @ 2019-09-04 24046/week @ 2019-09-11 27930/week @ 2019-09-18 29811/week @ 2019-09-25 31130/week @ 2019-10-02 36351/week @ 2019-10-09 40630/week @ 2019-10-16 41812/week @ 2019-10-23 37198/week @ 2019-10-30 42354/week @ 2019-11-06 42481/week @ 2019-11-13 47280/week @ 2019-11-20

148,463 downloads per month
Used in 730 crates (52 directly)

BSD-3-Clause

24KB
325 lines

subtle

Pure-Rust traits and utilities for constant-time cryptographic implementations.

It consists of a Choice type, and a collection of traits using Choice instead of bool which are intended to execute in constant-time. The Choice type is a wrapper around a u8 that holds a 0 or 1.

This crate represents a “best-effort” attempt, since side-channels are ultimately a property of a deployed cryptographic system including the hardware it runs on, not just of software.

The traits are implemented using bitwise operations, and should execute in constant time provided that a) the bitwise operations are constant-time and b) the operations are not optimized into a branch.

To prevent the latter possibility, the crate attempts to hide the value of a Choice's inner u8 from the optimizer, by passing it through either an inline assembly block or a volatile read. For more information, see the About section below.

[dependencies.subtle]
version = "2.2"

Versions prior to 2.2 recommended use of the nightly feature to enable an optimization barrier; this is not required in versions 2.2 and above.

Documentation

Documentation is available here.

About

This library aims to be the Rust equivalent of Go’s crypto/subtle module.

The optimization barrier in impl From<u8> for Choice was based on Tim Maclean's work on rust-timing-shield, which attempts to provide a more comprehensive approach for preventing software side-channels in Rust code.

subtle is authored by isis agora lovecruft and Henry de Valence.

Warning

This code is a low-level library, intended for specific use-cases implementing cryptographic protocols. It represents a best-effort attempt to protect against some software side-channels. Because side-channel resistance is not a property of software alone, but of software together with hardware, any such effort is fundamentally limited.

USE AT YOUR OWN RISK

No runtime deps