Skip to content

Commit eab521d

Browse files
authored
ctutils: downgrade MSRV to 1.85 (#1259)
This is implemented as its own PR so we can easily revert it when we are ready to bump MSRV to 1.87. The main thing we lose here is `const fn` support for `Choice::to_u8` and `to_bool`, since these use `black_box`. In addition the macros to write the signed impls of `CtEq` and `CtSelect` become a little uglier, but that's not the end of the world.
1 parent 87d6dd2 commit eab521d

File tree

6 files changed

+14
-12
lines changed

6 files changed

+14
-12
lines changed

.github/workflows/ctutils.yml

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -31,7 +31,7 @@ jobs:
3131
strategy:
3232
matrix:
3333
rust:
34-
- 1.87.0 # MSRV
34+
- 1.85.0 # MSRV
3535
- stable
3636
target:
3737
- thumbv7em-none-eabi
@@ -55,7 +55,7 @@ jobs:
5555
strategy:
5656
matrix:
5757
rust:
58-
- 1.87.0 # MSRV
58+
- 1.85.0 # MSRV
5959
- stable
6060
steps:
6161
- uses: actions/checkout@v5

ctutils/Cargo.toml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -14,7 +14,7 @@ categories = ["cryptography", "no-std"]
1414
keywords = ["crypto", "intrinsics"]
1515
readme = "README.md"
1616
edition = "2024"
17-
rust-version = "1.87"
17+
rust-version = "1.85"
1818

1919
[dependencies]
2020
cmov = "0.4"

ctutils/README.md

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -57,7 +57,7 @@ dual licensed as above, without any additional terms or conditions.
5757
[docs-image]: https://docs.rs/ctutils/badge.svg
5858
[docs-link]: https://docs.rs/ctutils/
5959
[license-image]: https://img.shields.io/badge/license-Apache2.0/MIT-blue.svg
60-
[msrv-image]: https://img.shields.io/badge/rustc-1.87+-blue.svg
60+
[msrv-image]: https://img.shields.io/badge/rustc-1.85+-blue.svg
6161
[build-image]: https://github.com/RustCrypto/utils/actions/workflows/ctutils.yml/badge.svg?branch=master
6262
[build-link]: https://github.com/RustCrypto/utils/actions/workflows/ctutils.yml?query=branch:master
6363

ctutils/src/choice.rs

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -45,12 +45,14 @@ impl Choice {
4545
/// the small amount of timing variability it introduces can potentially be exploited. Whenever
4646
/// possible, prefer fully constant-time approaches instead.
4747
/// </div>
48-
pub const fn to_bool(self) -> bool {
48+
// TODO(tarcieri): `const fn` when MSRV 1.86
49+
pub fn to_bool(self) -> bool {
4950
self.to_u8() != 0
5051
}
5152

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

ctutils/src/traits/ct_eq.rs

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -38,20 +38,20 @@ macro_rules! impl_unsigned_ct_eq_with_cmov {
3838
// Impl `CtEq` by first casting to unsigned then using the unsigned `CtEq` impls
3939
// TODO(tarcieri): add signed integer support to `cmov`
4040
macro_rules! impl_signed_ct_eq_with_cmov {
41-
( $($int:ty),+ ) => {
41+
( $($int:ty => $uint:ty),+ ) => {
4242
$(
4343
impl CtEq for $int {
4444
#[inline]
4545
fn ct_eq(&self, other: &Self) -> Choice {
46-
self.cast_unsigned().ct_eq(&other.cast_unsigned())
46+
(*self as $uint).ct_eq(&(*other as $uint))
4747
}
4848
}
4949
)+
5050
};
5151
}
5252

5353
impl_unsigned_ct_eq_with_cmov!(u8, u16, u32, u64, u128);
54-
impl_signed_ct_eq_with_cmov!(i8, i16, i32, i64, i128);
54+
impl_signed_ct_eq_with_cmov!(i8 => u8, i16 => u16, i32 => u32, i64 => u64, i128 => u128);
5555

5656
#[cfg(any(target_pointer_width = "32", target_pointer_width = "64"))]
5757
impl CtEq for usize {

ctutils/src/traits/ct_select.rs

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -47,20 +47,20 @@ macro_rules! impl_unsigned_ct_select_with_cmov {
4747
// Impl `CtSelect` by first casting to unsigned then using the unsigned `CtSelect` impls
4848
// TODO(tarcieri): add signed integer support to `cmov`
4949
macro_rules! impl_signed_ct_select_with_cmov {
50-
( $($int:ty),+ ) => {
50+
( $($int:ty => $uint:ty),+ ) => {
5151
$(
5252
impl CtSelect for $int {
5353
#[inline]
5454
fn ct_select(&self, other: &Self, choice: Choice) -> Self {
55-
self.cast_unsigned().ct_select(&other.cast_unsigned(), choice).cast_signed()
55+
(*self as $uint).ct_select(&(*other as $uint), choice) as Self
5656
}
5757
}
5858
)+
5959
};
6060
}
6161

6262
impl_unsigned_ct_select_with_cmov!(u8, u16, u32, u64, u128);
63-
impl_signed_ct_select_with_cmov!(i8, i16, i32, i64, i128);
63+
impl_signed_ct_select_with_cmov!(i8 => u8, i16 => u16, i32 => u32, i64 => u64, i128 => u128);
6464

6565
#[cfg(any(target_pointer_width = "32", target_pointer_width = "64"))]
6666
impl CtSelect for usize {

0 commit comments

Comments
 (0)