Skip to content
Open
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
6 changes: 3 additions & 3 deletions .github/workflows/pull_request.yml
Original file line number Diff line number Diff line change
Expand Up @@ -23,7 +23,7 @@ jobs:
uses: dtolnay/rust-toolchain@master
id: toolchain
with:
toolchain: nightly-2025-02-14
toolchain: nightly-2025-05-30
components: "rustfmt, miri"
- name: Override default toolchain
run: rustup override set ${{steps.toolchain.outputs.name}}
Expand Down Expand Up @@ -52,7 +52,7 @@ jobs:
uses: dtolnay/rust-toolchain@master
id: toolchain
with:
toolchain: nightly-2025-02-14
toolchain: nightly-2025-05-30
components: "clippy, rustfmt"
- name: Override default toolchain
run: rustup override set ${{steps.toolchain.outputs.name}}
Expand Down Expand Up @@ -80,7 +80,7 @@ jobs:
uses: dtolnay/rust-toolchain@master
id: toolchain
with:
toolchain: nightly-2025-02-14
toolchain: nightly-2025-05-30
components: rust-docs
- name: Override default toolchain
run: rustup override set ${{steps.toolchain.outputs.name}}
Expand Down
2 changes: 1 addition & 1 deletion .github/workflows/push.yml
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,7 @@ jobs:
uses: dtolnay/rust-toolchain@master
id: toolchain
with:
toolchain: nightly-2025-02-14
toolchain: nightly-2025-05-30
- name: Override default toolchain
run: rustup override set ${{steps.toolchain.outputs.name}}
- run: cargo --version
Expand Down
2 changes: 1 addition & 1 deletion .github/workflows/rustdoc.yml
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,7 @@ jobs:
uses: dtolnay/rust-toolchain@master
id: toolchain
with:
toolchain: nightly-2025-02-14
toolchain: nightly-2025-05-30
components: rust-docs
- name: Override default toolchain
run: rustup override set ${{steps.toolchain.outputs.name}}
Expand Down
3 changes: 1 addition & 2 deletions .gitignore
Original file line number Diff line number Diff line change
@@ -1,5 +1,4 @@
target
profile*.json*
perf.data*

.flyio
*.annotation
5 changes: 1 addition & 4 deletions .vscode/settings.json
Original file line number Diff line number Diff line change
@@ -1,8 +1,5 @@
{
"rust-analyzer.rustfmt.extraArgs": [
"+nightly"
],
"rust-analyzer.cargo.extraEnv": {
"RUSTUP_TOOLCHAIN": "nightly"
},
]
}
1 change: 1 addition & 0 deletions Cargo.lock

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

1 change: 1 addition & 0 deletions cryprot-core/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -32,6 +32,7 @@ rand.workspace = true
rand_core.workspace = true
rand_core_0_6.workspace = true
rayon = { workspace = true, optional = true }
seq-macro.workspace = true
serde = { workspace = true, features = ["derive"] }
subtle.workspace = true
thiserror.workspace = true
Expand Down
5 changes: 1 addition & 4 deletions cryprot-core/src/alloc.rs
Original file line number Diff line number Diff line change
Expand Up @@ -51,10 +51,7 @@ impl<T> HugePageMemory<T> {
// new_len <= self.capacity
// self[len..new_len] is initialized either because of Self::zeroed
// or with data written to it.
#[allow(unused_unsafe)]
unsafe {
self.len = new_len;
}
self.len = new_len;
}
}

Expand Down
64 changes: 27 additions & 37 deletions cryprot-core/src/block/gf128.rs
Original file line number Diff line number Diff line change
Expand Up @@ -104,59 +104,49 @@ mod clmul {

#[target_feature(enable = "pclmulqdq")]
#[inline]
pub unsafe fn gf128_mul(a: __m128i, b: __m128i) -> __m128i {
unsafe {
let (low, high) = clmul128(a, b);
gf128_reduce(low, high)
}
pub fn gf128_mul(a: __m128i, b: __m128i) -> __m128i {
let (low, high) = clmul128(a, b);
gf128_reduce(low, high)
}

/// Carry-less multiply of two 128-bit numbers.
///
/// Return (low, high) bits
#[target_feature(enable = "pclmulqdq")]
#[inline]
pub unsafe fn clmul128(a: __m128i, b: __m128i) -> (__m128i, __m128i) {
// This is currently needed because we run the nightly version of
// clippy where this is an unused unsafe because the used
// intrinsincs have been marked safe on nightly but not yet on
// stable.
#[allow(unused_unsafe)]
unsafe {
// NOTE: I tried using karatsuba but it was slightly slower than the naive
// multiplication
let ab_low = _mm_clmulepi64_si128::<0x00>(a, b);
let ab_high = _mm_clmulepi64_si128::<0x11>(a, b);
let ab_lohi1 = _mm_clmulepi64_si128::<0x01>(a, b);
let ab_lohi2 = _mm_clmulepi64_si128::<0x10>(a, b);
let ab_mid = _mm_xor_si128(ab_lohi1, ab_lohi2);
let low = _mm_xor_si128(ab_low, _mm_slli_si128::<8>(ab_mid));
let high = _mm_xor_si128(ab_high, _mm_srli_si128::<8>(ab_mid));
(low, high)
}
pub fn clmul128(a: __m128i, b: __m128i) -> (__m128i, __m128i) {
// NOTE: I tried using karatsuba but it was slightly slower than the naive
// multiplication
let ab_low = _mm_clmulepi64_si128::<0x00>(a, b);
let ab_high = _mm_clmulepi64_si128::<0x11>(a, b);
let ab_lohi1 = _mm_clmulepi64_si128::<0x01>(a, b);
let ab_lohi2 = _mm_clmulepi64_si128::<0x10>(a, b);
let ab_mid = _mm_xor_si128(ab_lohi1, ab_lohi2);
let low = _mm_xor_si128(ab_low, _mm_slli_si128::<8>(ab_mid));
let high = _mm_xor_si128(ab_high, _mm_srli_si128::<8>(ab_mid));
(low, high)
}

#[target_feature(enable = "pclmulqdq")]
#[inline]
pub unsafe fn gf128_reduce(mut low: __m128i, mut high: __m128i) -> __m128i {
pub fn gf128_reduce(mut low: __m128i, mut high: __m128i) -> __m128i {
// NOTE: I tried a sse shift based reduction but it was slower than the clmul
// implementation
unsafe {
let modulus = [MOD, 0];
let modulus = _mm_loadu_si64(modulus.as_ptr().cast());
let modulus = [MOD, 0];
// SAFETY: Ptr to modulus is valid and pclmulqdq implies sse2 is enabled
let modulus = unsafe { _mm_loadu_si64(modulus.as_ptr().cast()) };

let tmp = _mm_clmulepi64_si128::<0x01>(high, modulus);
let tmp_shifted = _mm_slli_si128::<8>(tmp);
low = _mm_xor_si128(low, tmp_shifted);
high = _mm_xor_si128(high, tmp_shifted);
let tmp = _mm_clmulepi64_si128::<0x01>(high, modulus);
let tmp_shifted = _mm_slli_si128::<8>(tmp);
low = _mm_xor_si128(low, tmp_shifted);
high = _mm_xor_si128(high, tmp_shifted);

// reduce overflow
let tmp = _mm_clmulepi64_si128::<0x01>(tmp, modulus);
low = _mm_xor_si128(low, tmp);
// reduce overflow
let tmp = _mm_clmulepi64_si128::<0x01>(tmp, modulus);
low = _mm_xor_si128(low, tmp);

let tmp = _mm_clmulepi64_si128::<0x00>(high, modulus);
_mm_xor_si128(low, tmp)
}
let tmp = _mm_clmulepi64_si128::<0x00>(high, modulus);
_mm_xor_si128(low, tmp)
}

#[cfg(all(test, target_feature = "pclmulqdq"))]
Expand Down
Loading