Skip to content

Commit d49e463

Browse files
committed
Revert "Add core_hint_black_box feature that uses core::hint::black_box"
This reverts commit 0dfc572.
1 parent 415cb23 commit d49e463

File tree

4 files changed

+7
-58
lines changed

4 files changed

+7
-58
lines changed

.travis.yml

Lines changed: 1 addition & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -26,10 +26,8 @@ script:
2626
- cargo test && cargo test --no-default-features &&
2727
cargo test --no-default-features --features std &&
2828
cargo test --no-default-features --features "std i128" &&
29-
cargo test --no-default-features --features "std core_hint_black_box" &&
3029
cargo test --no-default-features --features "std const-generics" &&
31-
cargo test --no-default-features --features "std i128 core_hint_black_box" &&
32-
cargo test --no-default-features --features "std i128 core_hint_black_box const-generics"
30+
cargo test --no-default-features --features "std i128 const-generics"
3331

3432
notifications:
3533
slack:

Cargo.toml

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -30,6 +30,7 @@ rand = { version = "0.8" }
3030

3131
[features]
3232
const-generics = []
33+
# DEPRECATED: As of 2.5.1, this feature does nothing.
3334
core_hint_black_box = []
3435
default = ["std", "i128"]
3536
std = []

README.md

Lines changed: 2 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -26,10 +26,6 @@ prevent this refinement, the crate tries to hide the value of a `Choice`'s
2626
inner `u8` by passing it through a volatile read. For more information, see
2727
the _About_ section below.
2828

29-
Rust versions from 1.66 or higher support a new best-effort optimization
30-
barrier ([`core::hint::black_box`]). To use the new optimization barrier,
31-
enable the `core_hint_black_box` feature.
32-
3329
Rust versions from 1.51 or higher have const generics support. You may enable
3430
`const-generics` feautre to have `subtle` traits implemented for arrays `[T; N]`.
3531

@@ -47,7 +43,7 @@ Documentation is available [here][docs].
4743

4844
## Minimum Supported Rust Version
4945

50-
Rust **1.41** or higher.
46+
Rust **1.66** or higher.
5147

5248
Minimum supported Rust version can be changed in the future, but it will be done with a minor version bump.
5349

@@ -59,11 +55,8 @@ Old versions of the optimization barrier in `impl From<u8> for Choice` were
5955
based on Tim Maclean's [work on `rust-timing-shield`][rust-timing-shield],
6056
which attempts to provide a more comprehensive approach for preventing
6157
software side-channels in Rust code.
62-
6358
From version `2.2`, it was based on Diane Hosfelt and Amber Sprenkels' work on
64-
"Secret Types in Rust". Version `2.5` adds the `core_hint_black_box` feature,
65-
which uses the original method through the [`core::hint::black_box`] function
66-
from the Rust standard library.
59+
"Secret Types in Rust".
6760

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

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

8073
[docs]: https://docs.rs/subtle
81-
[`core::hint::black_box`]: https://doc.rust-lang.org/core/hint/fn.black_box.html
8274
[rust-timing-shield]: https://www.chosenplaintext.ca/open-source/rust-timing-shield/security

src/lib.rs

Lines changed: 3 additions & 45 deletions
Original file line numberDiff line numberDiff line change
@@ -41,10 +41,6 @@
4141
//! inner `u8` by passing it through a volatile read. For more information, see
4242
//! the _About_ section below.
4343
//!
44-
//! Rust versions from 1.66 or higher support a new best-effort optimization
45-
//! barrier ([`core::hint::black_box`]). To use the new optimization barrier,
46-
//! enable the `core_hint_black_box` feature.
47-
//!
4844
//! Rust versions from 1.51 or higher have const generics support. You may enable
4945
//! `const-generics` feautre to have `subtle` traits implemented for arrays `[T; N]`.
5046
//!
@@ -74,11 +70,8 @@
7470
//! based on Tim Maclean's [work on `rust-timing-shield`][rust-timing-shield],
7571
//! which attempts to provide a more comprehensive approach for preventing
7672
//! software side-channels in Rust code.
77-
//!
7873
//! From version `2.2`, it was based on Diane Hosfelt and Amber Sprenkels' work on
79-
//! "Secret Types in Rust". Version `2.5` adds the `core_hint_black_box` feature,
80-
//! which uses the original method through the [`core::hint::black_box`] function
81-
//! from the Rust standard library.
74+
//! "Secret Types in Rust".
8275
//!
8376
//! `subtle` is authored by isis agora lovecruft and Henry de Valence.
8477
//!
@@ -93,7 +86,6 @@
9386
//! **USE AT YOUR OWN RISK**
9487
//!
9588
//! [docs]: https://docs.rs/subtle
96-
//! [`core::hint::black_box`]: https://doc.rust-lang.org/core/hint/fn.black_box.html
9789
//! [rust-timing-shield]: https://www.chosenplaintext.ca/open-source/rust-timing-shield/security
9890
9991
#[cfg(feature = "std")]
@@ -214,47 +206,13 @@ impl Not for Choice {
214206
}
215207
}
216208

217-
/// This function is a best-effort attempt to prevent the compiler from knowing
218-
/// anything about the value of the returned `u8`, other than its type.
219-
///
220-
/// Because we want to support stable Rust, we don't have access to inline
221-
/// assembly or test::black_box, so we use the fact that volatile values will
222-
/// never be elided to register values.
223-
///
224-
/// Note: Rust's notion of "volatile" is subject to change over time. While this
225-
/// code may break in a non-destructive way in the future, “constant-time” code
226-
/// is a continually moving target, and this is better than doing nothing.
227-
#[cfg(not(feature = "core_hint_black_box"))]
228-
#[inline(never)]
229-
fn black_box(input: u8) -> u8 {
230-
debug_assert!((input == 0u8) | (input == 1u8));
231-
232-
unsafe {
233-
// Optimization barrier
234-
//
235-
// Unsafe is ok, because:
236-
// - &input is not NULL;
237-
// - size of input is not zero;
238-
// - u8 is neither Sync, nor Send;
239-
// - u8 is Copy, so input is always live;
240-
// - u8 type is always properly aligned.
241-
core::ptr::read_volatile(&input as *const u8)
242-
}
243-
}
244-
245-
#[cfg(feature = "core_hint_black_box")]
246-
#[inline]
247-
fn black_box(input: u8) -> u8 {
248-
debug_assert!((input == 0u8) | (input == 1u8));
249-
core::hint::black_box(input)
250-
}
251-
252209
impl From<u8> for Choice {
253210
#[inline]
254211
fn from(input: u8) -> Choice {
212+
debug_assert!((input == 0u8) | (input == 1u8));
255213
// Our goal is to prevent the compiler from inferring that the value held inside the
256214
// resulting `Choice` struct is really an `i1` instead of an `i8`.
257-
Choice(black_box(input))
215+
Choice(core::hint::black_box(input))
258216
}
259217
}
260218

0 commit comments

Comments
 (0)