Skip to content

Commit

Permalink
Merge remote-tracking branch 'dsprenkels/black-box' into develop
Browse files Browse the repository at this point in the history
  • Loading branch information
isis-mc committed Apr 3, 2023
2 parents 4a5b65f + 5254934 commit a7ce809
Show file tree
Hide file tree
Showing 3 changed files with 3 additions and 26 deletions.
1 change: 1 addition & 0 deletions Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -30,6 +30,7 @@ rand = { version = "0.8" }

[features]
const-generics = []
# DEPRECATED: As of 2.5.1, this feature does nothing.
core_hint_black_box = []
default = ["std", "i128"]
std = []
Expand Down
10 changes: 1 addition & 9 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -26,10 +26,6 @@ prevent this refinement, the crate tries to hide the value of a `Choice`'s
inner `u8` by passing it through a volatile read. For more information, see
the _About_ section below.

Rust versions from 1.66 or higher support a new best-effort optimization
barrier ([`core::hint::black_box`]). To use the new optimization barrier,
enable the `core_hint_black_box` feature.

Rust versions from 1.51 or higher have const generics support. You may enable
`const-generics` feautre to have `subtle` traits implemented for arrays `[T; N]`.

Expand Down Expand Up @@ -59,11 +55,8 @@ Old versions of the optimization barrier in `impl From<u8> for Choice` were
based on Tim Maclean's [work on `rust-timing-shield`][rust-timing-shield],
which attempts to provide a more comprehensive approach for preventing
software side-channels in Rust code.

From version `2.2`, it was based on Diane Hosfelt and Amber Sprenkels' work on
"Secret Types in Rust". Version `2.5` adds the `core_hint_black_box` feature,
which uses the original method through the [`core::hint::black_box`] function
from the Rust standard library.
"Secret Types in Rust".

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

Expand All @@ -78,5 +71,4 @@ effort is fundamentally limited.
**USE AT YOUR OWN RISK**

[docs]: https://docs.rs/subtle
[`core::hint::black_box`]: https://doc.rust-lang.org/core/hint/fn.black_box.html
[rust-timing-shield]: https://www.chosenplaintext.ca/open-source/rust-timing-shield/security
18 changes: 1 addition & 17 deletions src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -41,10 +41,6 @@
//! inner `u8` by passing it through a volatile read. For more information, see
//! the _About_ section below.
//!
//! Rust versions from 1.66 or higher support a new best-effort optimization
//! barrier ([`core::hint::black_box`]). To use the new optimization barrier,
//! enable the `core_hint_black_box` feature.
//!
//! Rust versions from 1.51 or higher have const generics support. You may enable
//! `const-generics` feautre to have `subtle` traits implemented for arrays `[T; N]`.
//!
Expand Down Expand Up @@ -74,11 +70,8 @@
//! based on Tim Maclean's [work on `rust-timing-shield`][rust-timing-shield],
//! which attempts to provide a more comprehensive approach for preventing
//! software side-channels in Rust code.
//!
//! From version `2.2`, it was based on Diane Hosfelt and Amber Sprenkels' work on
//! "Secret Types in Rust". Version `2.5` adds the `core_hint_black_box` feature,
//! which uses the original method through the [`core::hint::black_box`] function
//! from the Rust standard library.
//! "Secret Types in Rust".
//!
//! `subtle` is authored by isis agora lovecruft and Henry de Valence.
//!
Expand All @@ -93,7 +86,6 @@
//! **USE AT YOUR OWN RISK**
//!
//! [docs]: https://docs.rs/subtle
//! [`core::hint::black_box`]: https://doc.rust-lang.org/core/hint/fn.black_box.html
//! [rust-timing-shield]: https://www.chosenplaintext.ca/open-source/rust-timing-shield/security

#[cfg(feature = "std")]
Expand Down Expand Up @@ -224,7 +216,6 @@ impl Not for Choice {
/// Note: Rust's notion of "volatile" is subject to change over time. While this
/// code may break in a non-destructive way in the future, “constant-time” code
/// is a continually moving target, and this is better than doing nothing.
#[cfg(not(feature = "core_hint_black_box"))]
#[inline(never)]
fn black_box(input: u8) -> u8 {
debug_assert!((input == 0u8) | (input == 1u8));
Expand All @@ -242,13 +233,6 @@ fn black_box(input: u8) -> u8 {
}
}

#[cfg(feature = "core_hint_black_box")]
#[inline(never)]
fn black_box(input: u8) -> u8 {
debug_assert!((input == 0u8) | (input == 1u8));
core::hint::black_box(input)
}

impl From<u8> for Choice {
#[inline]
fn from(input: u8) -> Choice {
Expand Down

0 comments on commit a7ce809

Please sign in to comment.