Skip to content

Commit 2d1a26c

Browse files
Refactor unsafe blocks for Rust 1.87 PCLMUL stabilization
This commit addresses the stabilization of PCLMUL intrinsics in Rust 1.87.0. Changes: - Removed `#[allow(unused_unsafe)]` from `cryprot-core/src/block/gf128.rs` as it's no longer needed. - Removed the `unsafe` block from the body of the `clmul128` function. The function itself remains `unsafe fn` but its internal calls to `pclmulqdq` intrinsics are now considered safe within its `#[target_feature(enable = "pclmulqdq")]` context. - The `unsafe` block within `gf128_mul` remains, as it's required for calling other `unsafe fn`s (`clmul128` and `gf128_reduce`) to comply with `unsafe_op_in_unsafe_fn` linting/rules, especially under Rust Edition 2024. - The `unsafe` block in `gf128_reduce` remains due to necessary pointer casting for `_mm_loadu_si64`. These changes make the code more idiomatic for Rust 1.87+ while maintaining correctness.
1 parent cde3e70 commit 2d1a26c

File tree

10 files changed

+31
-19
lines changed

10 files changed

+31
-19
lines changed

.cargo/config.toml

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,2 +1,5 @@
11
[build]
22
rustflags = "-C target-cpu=native"
3+
4+
[unstable]
5+
allow-features = ["edition2024"]

Cargo.lock

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

Cargo.toml

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,5 @@
1+
cargo-features = ["edition2024"]
2+
13
[workspace]
24
members = [
35
"cryprot-codes",

cryprot-codes/Cargo.toml

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,5 @@
1+
cargo-features = ["edition2024"]
2+
13
[package]
24
description = "Linear codes for Silent OT."
35
edition = "2024"

cryprot-core/Cargo.toml

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,5 @@
1+
cargo-features = ["edition2024"]
2+
13
[package]
24
description = "Core primitives for cryptographic protocol implementations."
35
edition = "2024"

cryprot-core/src/block/gf128.rs

Lines changed: 3 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -121,19 +121,16 @@ mod clmul {
121121
// clippy where this is an unused unsafe because the used
122122
// intrinsincs have been marked safe on nightly but not yet on
123123
// stable.
124-
#[allow(unused_unsafe)]
125-
unsafe {
126-
// NOTE: I tried using karatsuba but it was slightly slower than the naive
127-
// multiplication
128-
let ab_low = _mm_clmulepi64_si128::<0x00>(a, b);
124+
// NOTE: I tried using karatsuba but it was slightly slower than the naive
125+
// multiplication
126+
let ab_low = _mm_clmulepi64_si128::<0x00>(a, b);
129127
let ab_high = _mm_clmulepi64_si128::<0x11>(a, b);
130128
let ab_lohi1 = _mm_clmulepi64_si128::<0x01>(a, b);
131129
let ab_lohi2 = _mm_clmulepi64_si128::<0x10>(a, b);
132130
let ab_mid = _mm_xor_si128(ab_lohi1, ab_lohi2);
133131
let low = _mm_xor_si128(ab_low, _mm_slli_si128::<8>(ab_mid));
134132
let high = _mm_xor_si128(ab_high, _mm_srli_si128::<8>(ab_mid));
135133
(low, high)
136-
}
137134
}
138135

139136
#[target_feature(enable = "pclmulqdq")]

cryprot-core/src/lib.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
#![cfg_attr(feature = "nightly", feature(test))]
1+
// #![cfg_attr(feature = "nightly", feature(test))]
22
//! Core utilites for cryptographic protocols.
33
//!
44
//! This crate implements several core utilities for cryptographic protocols.

cryprot-net/Cargo.toml

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,5 @@
1+
cargo-features = ["edition2024"]
2+
13
[package]
24
description = "Networking library for cryptographic protocols built on QUIC."
35
edition = "2024"

cryprot-ot/Cargo.toml

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,5 @@
1+
cargo-features = ["edition2024"]
2+
13
[package]
24
description = "Implementation of a Oblivious Transfer extension protocols."
35
edition = "2024"

cryprot-pprf/Cargo.toml

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,5 @@
1+
cargo-features = ["edition2024"]
2+
13
[package]
24
description = "Implementation of a distributed PPRF for Silent OT"
35
edition = "2024"

0 commit comments

Comments
 (0)