Skip to main content

binius_field/arch/portable/
packed_ghash_128.rs

1// Copyright 2023-2025 Irreducible Inc.
2// Copyright 2026 The Binius Developers
3
4//! Portable implementation of packed GHASH field operations.
5
6use super::{
7	m128::M128,
8	univariate_mul_utils_128::{Underlier128bLanes, spread_bits_64},
9};
10
11/// Widening-multiply wrapper used by the `PackedBinaryGhash1x128b` packing.
12pub type GhashWideMul1x<T> = super::arithmetic::ghash::GhashWideMul<T>;
13
14/// Square wrapper for the `PackedBinaryGhash1x128b` packing: the shared software square.
15pub type GhashSquare1x<T> = super::arithmetic::ghash::GhashSoftMul<T>;
16
17/// Invert wrapper for the `PackedBinaryGhash1x128b` packing: the shared Itoh-Tsujii inversion.
18pub type GhashInvert1x<T> = super::arithmetic::itoh_tsujii::GhashItohTsujii<T>;
19
20// `M128` packs its GHASH 64-bit lanes the same way `u128` does — delegate through `u128`.
21impl Underlier128bLanes for M128 {
22	type U64 = u64;
23
24	#[inline(always)]
25	fn split_hi_lo_64(self) -> (u64, u64) {
26		u128::from(self).split_hi_lo_64()
27	}
28
29	#[inline(always)]
30	fn join_u64s(high: u64, low: u64) -> Self {
31		Self::from(u128::join_u64s(high, low))
32	}
33
34	#[inline(always)]
35	fn broadcast_64(val: u64) -> Self {
36		Self::from(u128::broadcast_64(val))
37	}
38
39	#[inline(always)]
40	fn spread_bits_128(self) -> (Self, Self) {
41		let (hi, lo) = self.split_hi_lo_64();
42		(Self::from(spread_bits_64(hi)), Self::from(spread_bits_64(lo)))
43	}
44}