Skip to content

Commit e1b8aff

Browse files
committed
polyval: use cpubits crate for soft backend selection
We provide both 32-bit and 64-bit pure Rust implementations of POLYVAL in `soft32.rs` and `soft64.rs`. This commit addresses a TODO to use the `cpubits` crate to select between them. It contains equivalent 64-bit overrides to what we already had, but also provides a common place to add additional such overrides for other targets in the future.
1 parent 389a460 commit e1b8aff

5 files changed

Lines changed: 19 additions & 27 deletions

File tree

Cargo.lock

Lines changed: 4 additions & 5 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

Cargo.toml

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -5,3 +5,6 @@ members = [
55
"polyval"
66
]
77
resolver = "2"
8+
9+
[patch.crates-io.cpubits]
10+
git = "https://github.com/RustCrypto/utils"

polyval/Cargo.toml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -16,7 +16,7 @@ rust-version = "1.85"
1616
edition = "2024"
1717

1818
[dependencies]
19-
cfg-if = "1"
19+
cpubits = "0.1.0-rc.0"
2020
universal-hash = { version = "0.6.0-rc.4", default-features = false }
2121
zeroize = { version = "1", optional = true, default-features = false }
2222

polyval/src/backend.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,7 @@
22
33
mod soft;
44

5-
use cfg_if::cfg_if;
5+
use cpubits::cfg_if;
66

77
cfg_if! {
88
if #[cfg(all(target_arch = "aarch64", not(polyval_backend = "soft")))] {

polyval/src/backend/soft.rs

Lines changed: 10 additions & 20 deletions
Original file line numberDiff line numberDiff line change
@@ -1,26 +1,16 @@
11
//! Portable software implementation. Provides implementations for low power 32-bit devices as well
22
//! as a 64-bit implementation.
33
4-
// Use 64-bit backend on 64-bit targets, ARMv7, and WASM.
5-
// Fall back to 32-bit backend on others
6-
// TODO(tarcieri): use `cpubits` crate when available?
7-
#[cfg_attr(
8-
not(any(
9-
target_pointer_width = "64",
10-
all(target_arch = "arm", target_feature = "v7"),
11-
target_family = "wasm"
12-
)),
13-
path = "soft/soft32.rs"
14-
)]
15-
#[cfg_attr(
16-
any(
17-
target_pointer_width = "64",
18-
all(target_arch = "arm", target_feature = "v7"),
19-
target_family = "wasm"
20-
),
21-
path = "soft/soft64.rs"
22-
)]
23-
mod soft_impl;
4+
cpubits::cpubits! {
5+
16 | 32 => {
6+
#[path = "soft/soft32.rs"]
7+
mod soft_impl;
8+
}
9+
64 => {
10+
#[path = "soft/soft64.rs"]
11+
mod soft_impl;
12+
}
13+
}
2414

2515
use crate::{Block, Key, Tag};
2616
use soft_impl::*;

0 commit comments

Comments
 (0)