Crate subtle [−] [src]
Pure-Rust traits and utilities for constant-time cryptographic implementations.
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.
It consists of a
Choice type, and a collection of traits using
bool which are intended to execute in constant-time. The
type is a wrapper around a
u8 that holds a
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 this, when using the
nightly feature (recommended), the crate
attempts to hide the value of a
u8 from the optimizer, by
passing it through an inline assembly block. For more information, see the
About section below.
When not using the
nightly feature, there is no protection against b). This
is unfortunate, but is no worse than C code.
[dependencies.subtle] version = "^0.6" features = ["nightly"]
i128support and the use of an optimization barrier to protect the
Choicetype. Using the
nightlyfeature is recommended for security.
generic-implsfeature (enabled by default) provides generic impls of some traits. It can be disabled to allow specialized impls without violating the orphan rules.
Documentation is available here.
This library aims to be the Rust equivalent of Go’s
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
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.
USE AT YOUR OWN RISK
Note that docs will only build on nightly Rust until RFC 1990 stabilizes.
A type which can be conditionally assigned in constant time.
A type which can be conditionally negated in constant time.
Select one of two inputs according to a
A type which is conditionally swappable in constant time.