Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
4 changes: 2 additions & 2 deletions .github/workflows/ctutils.yml
Original file line number Diff line number Diff line change
Expand Up @@ -33,7 +33,7 @@ jobs:
strategy:
matrix:
rust:
- 1.85.0 # MSRV
- 1.86.0 # MSRV
- stable
target:
- thumbv7em-none-eabi
Expand All @@ -58,7 +58,7 @@ jobs:
strategy:
matrix:
rust:
- 1.85.0 # MSRV
- 1.86.0 # MSRV
- stable
steps:
- uses: actions/checkout@v7
Expand Down
2 changes: 1 addition & 1 deletion ctutils/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,7 @@ categories = ["cryptography", "no-std"]
keywords = ["constant-time", "crypto", "intrinsics"]
readme = "README.md"
edition = "2024"
rust-version = "1.85"
rust-version = "1.86"

[dependencies]
cmov = "0.5.3"
Expand Down
2 changes: 1 addition & 1 deletion ctutils/README.md
Original file line number Diff line number Diff line change
Expand Up @@ -79,7 +79,7 @@ dual licensed as above, without any additional terms or conditions.
[docs-image]: https://docs.rs/ctutils/badge.svg
[docs-link]: https://docs.rs/ctutils/
[license-image]: https://img.shields.io/badge/license-Apache2.0/MIT-blue.svg
[msrv-image]: https://img.shields.io/badge/rustc-1.85+-blue.svg
[msrv-image]: https://img.shields.io/badge/rustc-1.86+-blue.svg
[build-image]: https://github.com/RustCrypto/utils/actions/workflows/ctutils.yml/badge.svg
[build-link]: https://github.com/RustCrypto/utils/actions/workflows/ctutils.yml
[chat-image]: https://img.shields.io/badge/zulip-join_chat-blue.svg
Expand Down
22 changes: 10 additions & 12 deletions ctutils/src/choice.rs
Original file line number Diff line number Diff line change
Expand Up @@ -386,44 +386,42 @@ impl Choice {
/// the small amount of timing variability it introduces can potentially be exploited. Whenever
/// possible, prefer fully constant-time approaches instead.
/// </div>
// TODO(tarcieri): `const fn` when MSRV 1.86
#[must_use]
pub fn to_bool(self) -> bool {
pub const fn to_bool(self) -> bool {
self.to_u8() != 0
}

/// Convert [`Choice`] to a `u8`, attempting to apply a "best effort" optimization barrier.
// TODO(tarcieri): `const fn` when MSRV 1.86
#[must_use]
pub fn to_u8(self) -> u8 {
pub const fn to_u8(self) -> u8 {
// `black_box` is documented as working on a "best effort" basis. That's fine, this type is
// likewise documented as only working on a "best effort" basis itself. The only way we
// rely on `black_box` for correctness is it behaving as the identity function.
core::hint::black_box(self.0)
}

/// HACK: workaround to allow `const fn` boolean support on Rust 1.85.
/// DEPRECATED: previously a workaround to allow `const fn` boolean support on Rust 1.85.
///
/// This does not apply `black_box` to the output.
/// Use [`Choice::to_bool`] instead.
///
/// <div class = "warning">
/// <b>Security Warning</b>
///
/// See the security warnings for [`Choice::to_bool`].
/// </div>
// TODO(tarcieri): deprecate/remove this in favor of `to_bool` when MSRV is Rust 1.86
#[deprecated(since = "0.4.3", note = "use `Choice::to_bool` instead")]
#[must_use]
pub const fn to_bool_vartime(self) -> bool {
self.0 != 0
self.to_bool()
}

/// HACK: workaround to allow `const fn` boolean support on Rust 1.85.
/// DEPRECATED: previously a workaround to allow `const fn` boolean support on Rust 1.85.
///
/// This does not apply `black_box` to the output.
// TODO(tarcieri): deprecate/remove this in favor of `to_u8` when MSRV is Rust 1.86
/// Use [`Choice::to_u8`] instead.
#[deprecated(since = "0.4.3", note = "use `Choice::to_u8` instead")]
#[must_use]
pub const fn to_u8_vartime(self) -> u8 {
self.0
self.to_u8()
}

/// Create a `u8` bitmask.
Expand Down
8 changes: 3 additions & 5 deletions ctutils/src/ct_option.rs
Original file line number Diff line number Diff line change
Expand Up @@ -158,8 +158,7 @@ impl<T> CtOption<T> {
#[must_use]
#[track_caller]
pub const fn expect_ref(&self, msg: &str) -> &T {
// TODO(tarcieri): use `self.is_some().to_bool()` when MSRV is 1.86
assert!(self.is_some.to_bool_vartime(), "{}", msg);
assert!(self.is_some.to_bool(), "{}", msg);
self.as_inner_unchecked()
}

Expand Down Expand Up @@ -222,8 +221,7 @@ impl<T> CtOption<T> {
where
T: Copy,
{
// TODO(tarcieri): use `self.is_some().to_bool()` when MSRV is 1.86
if self.is_some.to_bool_vartime() {
if self.is_some.to_bool() {
Some(self.value)
} else {
None
Expand Down Expand Up @@ -693,7 +691,7 @@ mod tests {
// Don't actually use this! It's just a test function implemented in variable-time
#[allow(clippy::trivially_copy_pass_by_ref)]
const fn select_vartime(a: &u8, b: &u8, choice: Choice) -> u8 {
if choice.to_bool_vartime() { *b } else { *a }
if choice.to_bool() { *b } else { *a }
}

assert_eq!(
Expand Down
Loading