Skip to content

Commit f1455ee

Browse files
committed
Bump MSRV to 1.64.
* Use core::ffi::{c_int, c_uint} and remove our polyfills, eliminating libc as a dev-dependency. * Somplify CI configuration for symbol prefixing since 1.64.0 has llvm-tools-preview. * Use `core::ffi::CStr` in aarch64-apple-* feature detection.
1 parent dfc9b54 commit f1455ee

File tree

10 files changed

+38
-98
lines changed

10 files changed

+38
-98
lines changed

.github/workflows/ci.yml

Lines changed: 6 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -169,7 +169,7 @@ jobs:
169169
rust_channel:
170170
- stable
171171
# Keep in sync with Cargo.toml and similar `rust_channel` sections.
172-
- 1.63.0 # MSRV
172+
- 1.64.0 # MSRV
173173
# TODO: Move these to a daily/pre-release job.
174174
# - nightly
175175
# - beta
@@ -305,12 +305,10 @@ jobs:
305305
# Check that all the needed symbol renaming was done.
306306
# TODO: Do this check on Windows too.
307307

308-
- if: ${{ (matrix.target != 'aarch64-apple-ios' || matrix.rust_channel != '1.63.0') &&
309-
!contains(matrix.host_os, 'windows') }}
308+
- if: ${{ !contains(matrix.host_os, 'windows') }}
310309
run: rustup toolchain install --component=llvm-tools-preview ${{ matrix.rust_channel }}
311310

312-
- if: ${{ (matrix.target != 'aarch64-apple-ios' || matrix.rust_channel != '1.63.0') &&
313-
!contains(matrix.host_os, 'windows') }}
311+
- if: ${{ !contains(matrix.host_os, 'windows') }}
314312
run: mk/check-symbol-prefixes.sh +${{ matrix.rust_channel }} --target=${{ matrix.target }}
315313

316314
test-bench:
@@ -387,7 +385,7 @@ jobs:
387385
- stable
388386
- nightly
389387
# Keep in sync with Cargo.toml and similar `rust_channel` sections.
390-
- 1.63.0 # MSRV
388+
- 1.64.0 # MSRV
391389

392390
include:
393391
- target: aarch64-unknown-linux-musl
@@ -435,12 +433,9 @@ jobs:
435433
# Check that all the needed symbol renaming was done.
436434
# TODO: Do this check on Windows too.
437435

438-
- if: ${{ (matrix.target != 'aarch64-apple-ios' || matrix.rust_channel != '1.63.0') &&
439-
!contains(matrix.host_os, 'windows') }}
440-
run: rustup toolchain install --component=llvm-tools-preview ${{ matrix.rust_channel }}
436+
- run: rustup toolchain install --component=llvm-tools-preview ${{ matrix.rust_channel }}
441437

442-
- if: ${{ (matrix.target != 'aarch64-apple-ios' || matrix.rust_channel != '1.63.0') &&
443-
!contains(matrix.host_os, 'windows') }}
438+
- if: ${{ !contains(matrix.host_os, 'windows') }}
444439
run: mk/check-symbol-prefixes.sh +${{ matrix.rust_channel }} --target=${{ matrix.target }}
445440

446441
# The wasm32-unknown-unknown targets have a different set of feature sets and
@@ -498,7 +493,6 @@ jobs:
498493
${{ matrix.webdriver }} mk/cargo.sh +${{ matrix.rust_channel }} test -vv --target=${{ matrix.target }} ${{ matrix.features }} ${{ matrix.mode }}
499494
500495
# Check that all the needed symbol renaming was done.
501-
# TODO: Do this check on Windows too.
502496
- run: rustup toolchain install --component=llvm-tools-preview ${{ matrix.rust_channel }}
503497
- run: mk/check-symbol-prefixes.sh +${{ matrix.rust_channel }} --target=${{ matrix.target }}
504498

Cargo.toml

Lines changed: 1 addition & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -11,7 +11,7 @@ repository = "https://github.com/briansmith/ring"
1111

1212
# Keep in sync with .github/workflows/ci.yml ("MSRV") and see the MSRV note
1313
# in cpu/arm.rs
14-
rust-version = "1.63.0"
14+
rust-version = "1.64.0"
1515

1616
# Keep in sync with `links` below.
1717
version = "0.17.8"
@@ -171,9 +171,6 @@ windows-sys = { version = "0.52", features = ["Win32_Foundation", "Win32_System_
171171
[target.'cfg(all(target_arch = "wasm32", target_os = "unknown"))'.dev-dependencies]
172172
wasm-bindgen-test = { version = "0.3.37", default-features = false }
173173

174-
[target.'cfg(any(unix, windows, target_os = "wasi"))'.dev-dependencies]
175-
libc = { version = "0.2.148", default-features = false }
176-
177174
[build-dependencies]
178175
cc = { version = "1.0.83", default-features = false }
179176

src/aead/aes.rs

Lines changed: 8 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -18,7 +18,11 @@ use crate::{
1818
c, constant_time, cpu, error,
1919
polyfill::{self, slice},
2020
};
21-
use core::{num::NonZeroUsize, ops::RangeFrom};
21+
use core::{
22+
ffi::{c_int, c_uint},
23+
num::NonZeroUsize,
24+
ops::RangeFrom,
25+
};
2226

2327
#[derive(Clone)]
2428
pub(super) struct Key {
@@ -38,15 +42,15 @@ pub(super) struct Key {
3842
macro_rules! set_encrypt_key {
3943
( $name:ident, $key_bytes:expr, $key:expr, $cpu_features:expr ) => {{
4044
prefixed_extern! {
41-
fn $name(user_key: *const u8, bits: BitLength<c::int>, key: *mut AES_KEY) -> c::int;
45+
fn $name(user_key: *const u8, bits: BitLength<c_int>, key: *mut AES_KEY) -> c_int;
4246
}
4347
set_encrypt_key($name, $key_bytes, $key, $cpu_features)
4448
}};
4549
}
4650

4751
#[inline]
4852
unsafe fn set_encrypt_key(
49-
f: unsafe extern "C" fn(*const u8, BitLength<c::int>, *mut AES_KEY) -> c::int,
53+
f: unsafe extern "C" fn(*const u8, BitLength<c_int>, *mut AES_KEY) -> c_int,
5054
bytes: KeyBytes<'_>,
5155
key: &mut AES_KEY,
5256
_cpu_features: cpu::Features,
@@ -363,7 +367,7 @@ impl Key {
363367
#[derive(Clone)]
364368
pub(super) struct AES_KEY {
365369
pub rd_key: [u32; 4 * (MAX_ROUNDS + 1)],
366-
pub rounds: c::uint,
370+
pub rounds: c_uint,
367371
}
368372

369373
// Keep this in sync with `AES_MAXNR` in aes.h.

src/bssl.rs

Lines changed: 6 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -12,15 +12,16 @@
1212
// OF CONTRACT, NEGLIGENCE OR OTHER TORTIOUS ACTION, ARISING OUT OF OR IN
1313
// CONNECTION WITH THE USE OR PERFORMANCE OF THIS SOFTWARE.
1414

15-
use crate::{c, error};
15+
use crate::error;
16+
use core::ffi::c_int;
1617

1718
/// An `int` returned from a foreign function containing **1** if the function
1819
/// was successful or **0** if an error occurred. This is the convention used by
1920
/// C code in `ring`.
2021
#[derive(Clone, Copy, Debug)]
2122
#[must_use]
2223
#[repr(transparent)]
23-
pub struct Result(c::int);
24+
pub struct Result(c_int);
2425

2526
impl From<Result> for core::result::Result<(), error::Unspecified> {
2627
fn from(ret: Result) -> Self {
@@ -37,12 +38,12 @@ impl From<Result> for core::result::Result<(), error::Unspecified> {
3738
#[cfg(test)]
3839
mod tests {
3940
mod result {
40-
use crate::{bssl, c};
41-
use core::mem;
41+
use crate::bssl;
42+
use core::{ffi::c_int, mem};
4243

4344
#[test]
4445
fn size_and_alignment() {
45-
type Underlying = c::int;
46+
type Underlying = c_int;
4647
assert_eq!(mem::size_of::<bssl::Result>(), mem::size_of::<Underlying>());
4748
assert_eq!(
4849
mem::align_of::<bssl::Result>(),

src/c.rs

Lines changed: 0 additions & 33 deletions
Original file line numberDiff line numberDiff line change
@@ -19,41 +19,8 @@
1919
//! are all uniformly defined on the platforms we care about. This will
2020
//! probably change if/when we support 16-bit platforms or platforms where
2121
//! `usize` and `uintptr_t` are different sizes.
22-
//!
23-
//! TODO(MSRV-1.64): Use `core::ffi::{c_int, c_uint}`, remove the libc
24-
//! compatibility testing, and remove the libc dev-dependency.
25-
26-
// Keep in sync with the checks in base.h that verify these assumptions.
27-
28-
#![allow(dead_code)]
2922
3023
use core::num::NonZeroUsize;
3124

32-
pub(crate) type int = i32;
33-
pub(crate) type uint = u32;
3425
pub(crate) type size_t = usize;
3526
pub(crate) type NonZero_size_t = NonZeroUsize;
36-
37-
#[cfg(all(test, any(unix, windows)))]
38-
mod tests {
39-
use crate::c;
40-
41-
#[test]
42-
fn test_libc_compatible() {
43-
{
44-
let x: c::int = 1;
45-
let _x: libc::c_int = x;
46-
}
47-
48-
{
49-
let x: c::uint = 1;
50-
let _x: libc::c_uint = x;
51-
}
52-
53-
{
54-
let x: c::size_t = 1;
55-
let _x: libc::size_t = x;
56-
let _x: usize = x;
57-
}
58-
}
59-
}

src/constant_time.rs

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -15,6 +15,7 @@
1515
//! Constant-time operations.
1616
1717
use crate::{c, error};
18+
use core::ffi::c_int;
1819

1920
/// Returns `Ok(())` if `a == b` and `Err(error::Unspecified)` otherwise.
2021
/// The comparison of `a` and `b` is done in constant time with respect to the
@@ -32,7 +33,7 @@ pub fn verify_slices_are_equal(a: &[u8], b: &[u8]) -> Result<(), error::Unspecif
3233
}
3334

3435
prefixed_extern! {
35-
fn CRYPTO_memcmp(a: *const u8, b: *const u8, len: c::size_t) -> c::int;
36+
fn CRYPTO_memcmp(a: *const u8, b: *const u8, len: c::size_t) -> c_int;
3637
}
3738

3839
pub(crate) fn xor<const N: usize>(mut a: [u8; N], b: [u8; N]) -> [u8; N] {

src/cpu/arm/darwin.rs

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -14,6 +14,7 @@
1414

1515
use super::{AES, ARMCAP_STATIC, NEON, PMULL, SHA256, SHA512};
1616
use crate::polyfill::cstr;
17+
use core::ffi::{c_int, c_void, CStr};
1718

1819
// ```
1920
// $ rustc +1.61.0 --print cfg --target=aarch64-apple-ios | grep -E "neon|aes|sha|pmull"
@@ -51,10 +52,9 @@ const _AARCH64_APPLE_DARWIN_TARGETS_EXPECTED_FEATURES: () =
5152
assert!(ARMCAP_STATIC == MIN_STATIC_FEATURES);
5253

5354
pub fn detect_features() -> u32 {
54-
fn detect_feature(name: cstr::Ref) -> bool {
55+
fn detect_feature(name: &CStr) -> bool {
5556
use crate::polyfill;
5657
use core::mem;
57-
use libc::{c_int, c_void};
5858

5959
let mut value: c_int = 0;
6060
let mut len = mem::size_of_val(&value);
@@ -80,7 +80,7 @@ pub fn detect_features() -> u32 {
8080
let mut features = 0;
8181

8282
// TODO(MSRV 1.77): Use c"..." literal.
83-
const SHA512_NAME: cstr::Ref =
83+
const SHA512_NAME: &CStr =
8484
cstr::unwrap_const_from_bytes_with_nul(b"hw.optional.armv8_2_sha512\0");
8585
if detect_feature(SHA512_NAME) {
8686
features |= SHA512.mask;

src/ec/curve25519/ops.rs

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -17,10 +17,10 @@
1717
1818
pub use super::scalar::{MaskedScalar, Scalar, SCALAR_LEN};
1919
use crate::{
20-
bssl, c, cpu, error,
20+
bssl, cpu, error,
2121
limb::{Limb, LIMB_BITS},
2222
};
23-
use core::marker::PhantomData;
23+
use core::{ffi::c_int, marker::PhantomData};
2424

2525
// Elem<T>` is `fe` in curve25519/internal.h.
2626
// Elem<L> is `fe_loose` in curve25519/internal.h.
@@ -82,7 +82,7 @@ impl ExtPoint {
8282
t: Elem::zero(),
8383
};
8484
prefixed_extern! {
85-
fn x25519_ge_scalarmult_base(h: &mut ExtPoint, a: &Scalar, has_fe25519_adx: c::int);
85+
fn x25519_ge_scalarmult_base(h: &mut ExtPoint, a: &Scalar, has_fe25519_adx: c_int);
8686
}
8787
unsafe {
8888
x25519_ge_scalarmult_base(&mut r, scalar, has_fe25519_adx(cpu).into());

src/ec/curve25519/x25519.rs

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -15,7 +15,8 @@
1515
//! X25519 Key agreement.
1616
1717
use super::{ops, scalar::SCALAR_LEN};
18-
use crate::{agreement, c, constant_time, cpu, ec, error, rand};
18+
use crate::{agreement, constant_time, cpu, ec, error, rand};
19+
use core::ffi;
1920

2021
static CURVE25519: ec::Curve = ec::Curve {
2122
public_key_len: PUBLIC_KEY_LEN,
@@ -79,7 +80,7 @@ fn x25519_public_from_private(
7980
fn x25519_public_from_private_generic_masked(
8081
public_key_out: &mut PublicKey,
8182
private_key: &PrivateKey,
82-
use_adx: c::int,
83+
use_adx: ffi::c_int,
8384
);
8485
}
8586
unsafe {

src/polyfill/cstr.rs

Lines changed: 6 additions & 31 deletions
Original file line numberDiff line numberDiff line change
@@ -12,38 +12,14 @@
1212
// OF CONTRACT, NEGLIGENCE OR OTHER TORTIOUS ACTION, ARISING OUT OF OR IN
1313
// CONNECTION WITH THE USE OR PERFORMANCE OF THIS SOFTWARE.
1414

15-
//! Work around lack of `core::ffi::CStr` prior to Rust 1.64, and the lack of
16-
//! `const fn` support for `CStr` in later versions.
15+
//! Work around lack of `const fn` support for `CStr`.
1716
1817
#![cfg(all(target_arch = "aarch64", target_vendor = "apple"))]
1918

20-
// TODO(MSRV 1.64): Use `core::ffi::c_char`.
21-
use libc::c_char;
19+
use core::ffi::CStr;
2220

23-
// TODO(MSRV 1.64): Replace with `&core::ffi::CStr`.
24-
pub struct Ref(&'static [u8]);
25-
26-
impl Ref {
27-
#[inline(always)]
28-
pub fn as_ptr(&self) -> *const c_char {
29-
const _SAME_ALIGNMENT: () =
30-
assert!(core::mem::align_of::<u8>() == core::mem::align_of::<c_char>());
31-
const _SAME_SIZE: () =
32-
assert!(core::mem::size_of::<u8>() == core::mem::size_of::<c_char>());
33-
34-
// It is safe to cast a `*const u8` to a `const c_char` as they are the
35-
// same size and alignment.
36-
self.0.as_ptr().cast()
37-
}
38-
39-
// SAFETY: Same as `CStr::from_bytes_with_nul_unchecked`.
40-
const unsafe fn from_bytes_with_nul_unchecked(value: &'static [u8]) -> Self {
41-
Self(value)
42-
}
43-
}
44-
45-
pub const fn unwrap_const_from_bytes_with_nul(value: &'static [u8]) -> Ref {
46-
// XXX: We cannot use `unwrap_const` since `Ref`/`CStr` is not `Copy`.
21+
pub const fn unwrap_const_from_bytes_with_nul(value: &'static [u8]) -> &'static CStr {
22+
// XXX: We cannot use `unwrap_const` since `CStr` is not `Copy`.
4723
match const_from_bytes_with_nul(value) {
4824
Some(r) => r,
4925
None => panic!("const_from_bytes_with_nul failed"),
@@ -52,7 +28,7 @@ pub const fn unwrap_const_from_bytes_with_nul(value: &'static [u8]) -> Ref {
5228

5329
// TODO(MSRV 1.72): Replace with `CStr::from_bytes_with_nul`.
5430
#[inline(always)]
55-
const fn const_from_bytes_with_nul(value: &'static [u8]) -> Option<Ref> {
31+
const fn const_from_bytes_with_nul(value: &'static [u8]) -> Option<&'static CStr> {
5632
const fn const_contains(mut value: &[u8], needle: &u8) -> bool {
5733
while let [head, tail @ ..] = value {
5834
if *head == *needle {
@@ -69,8 +45,7 @@ const fn const_from_bytes_with_nul(value: &'static [u8]) -> Option<Ref> {
6945
// SAFETY:
7046
// * `value` is nul-terminated according to the slice pattern.
7147
// * `value` doesn't contain any interior null, by the guard.
72-
// TODO(MSRV 1.64): Use `CStr::from_bytes_with_nul_unchecked`
73-
Some(unsafe { Ref::from_bytes_with_nul_unchecked(value) })
48+
Some(unsafe { CStr::from_bytes_with_nul_unchecked(value) })
7449
}
7550
_ => None,
7651
}

0 commit comments

Comments
 (0)