diff --git a/crates/field/Cargo.toml b/crates/field/Cargo.toml index 544cbfd3f..e5fa4c363 100644 --- a/crates/field/Cargo.toml +++ b/crates/field/Cargo.toml @@ -59,10 +59,6 @@ harness = false name = "packed_field_multiply" harness = false -[[bench]] -name = "packed_field_mul_alpha" -harness = false - [[bench]] name = "packed_field_slice_iter" harness = false diff --git a/crates/field/benches/packed_field_invert.rs b/crates/field/benches/packed_field_invert.rs index c2f2f1f9c..05c8c67f8 100644 --- a/crates/field/benches/packed_field_invert.rs +++ b/crates/field/benches/packed_field_invert.rs @@ -20,8 +20,7 @@ fn invert_main(val: T) -> T { cfg_if! { if #[cfg(feature = "benchmark_alternative_strategies")] { use binius_field::{ - arch::{PackedStrategy, PairwiseRecursiveStrategy, PairwiseStrategy, - PairwiseTableStrategy, }, + arch::{PackedStrategy, PairwiseStrategy, PairwiseTableStrategy}, arithmetic_traits::TaggedInvertOrZero, }; @@ -29,10 +28,6 @@ cfg_if! { val.invert_or_zero() } - fn invert_pairwise_recursive>(val: T) -> T { - val.invert_or_zero() - } - fn invert_pairwise_table>(val: T) -> T { val.invert_or_zero() } @@ -47,7 +42,6 @@ cfg_if! { strategies @ ( (main, PackedField, invert_main), (pairwise, TaggedInvertOrZero::, invert_pairwise), - (pairwise_recursive, TaggedInvertOrZero::, invert_pairwise_recursive), (pairwise_table, TaggedInvertOrZero::, invert_pairwise_table), (packed, TaggedInvertOrZero::, invert_packed), ) diff --git a/crates/field/benches/packed_field_mul_alpha.rs b/crates/field/benches/packed_field_mul_alpha.rs deleted file mode 100644 index e54e8f39d..000000000 --- a/crates/field/benches/packed_field_mul_alpha.rs +++ /dev/null @@ -1,66 +0,0 @@ -// Copyright 2024-2025 Irreducible Inc. - -mod packed_field_utils; - -use binius_field::{ - arch::{ - packed_128::*, packed_256::*, packed_512::*, packed_aes_128::*, packed_aes_256::*, - packed_aes_512::*, packed_ghash_128::*, packed_ghash_256::*, packed_ghash_512::*, - }, - arithmetic_traits::MulAlpha, -}; -use cfg_if::cfg_if; -use criterion::criterion_main; -use packed_field_utils::benchmark_packed_operation; - -fn mul_alpha_main(val: T) -> T { - val.mul_alpha() -} - -cfg_if! { - if #[cfg(feature = "benchmark_alternative_strategies")] { - use binius_field::{ - arch::{PackedStrategy, PairwiseRecursiveStrategy, PairwiseStrategy, - PairwiseTableStrategy, }, - arithmetic_traits::TaggedMulAlpha - }; - - fn mul_alpha_pairwise>(val: T) -> T { - val.mul_alpha() - } - - fn mul_alpha_pairwise_recursive>(val: T) -> T { - val.mul_alpha() - } - - fn mul_alpha_pairwise_table>(val: T) -> T { - val.mul_alpha() - } - - fn mul_alpha_packed>(val: T) -> T { - val.mul_alpha() - } - - benchmark_packed_operation!( - op_name @ mul_alpha, - bench_type @ unary_op, - strategies @ ( - (main, MulAlpha, mul_alpha_main), - (pairwise, TaggedMulAlpha::, mul_alpha_pairwise), - (pairwise_recursive, TaggedMulAlpha::, mul_alpha_pairwise_recursive), - (pairwise_table, TaggedMulAlpha::, mul_alpha_pairwise_table), - (packed, TaggedMulAlpha::, mul_alpha_packed), - ) - ); - } else { - benchmark_packed_operation!( - op_name @ mul_alpha, - bench_type @ unary_op, - strategies @ ( - (main, MulAlpha, mul_alpha_main), - ) - ); - } -} - -criterion_main!(mul_alpha); diff --git a/crates/field/benches/packed_field_multiply.rs b/crates/field/benches/packed_field_multiply.rs index 407e14a27..bc21805bc 100644 --- a/crates/field/benches/packed_field_multiply.rs +++ b/crates/field/benches/packed_field_multiply.rs @@ -24,8 +24,7 @@ fn mul_main(lhs: T, rhs: T) -> T { cfg_if! { if #[cfg(feature = "benchmark_alternative_strategies")] { use binius_field::{ - arch::{PackedStrategy, PairwiseRecursiveStrategy, PairwiseStrategy, - PairwiseTableStrategy, }, + arch::{PackedStrategy, PairwiseStrategy, PairwiseTableStrategy}, arithmetic_traits::TaggedMul }; @@ -37,10 +36,6 @@ cfg_if! { TaggedMul::::mul(lhs, rhs) } - fn mul_pairwise_recursive>(lhs: T, rhs: T) -> T { - TaggedMul::::mul(lhs, rhs) - } - fn mul_packed>(lhs: T, rhs: T) -> T { TaggedMul::::mul(lhs, rhs) } @@ -51,7 +46,6 @@ cfg_if! { strategies @ ( (main, SelfMul, mul_main), (pairwise, TaggedMul::, mul_pairwise), - (pairwise_recursive, TaggedMul::, mul_pairwise_recursive), (pairwise_table, TaggedMul::, mul_pairwise_table), (packed, TaggedMul::, mul_packed), ) diff --git a/crates/field/benches/packed_field_square.rs b/crates/field/benches/packed_field_square.rs index 9c0f542ab..ffb7b1c8c 100644 --- a/crates/field/benches/packed_field_square.rs +++ b/crates/field/benches/packed_field_square.rs @@ -20,8 +20,7 @@ fn square_main(val: T) -> T { cfg_if! { if #[cfg(feature = "benchmark_alternative_strategies")] { use binius_field::{ - arch::{PackedStrategy, PairwiseStrategy, PairwiseRecursiveStrategy, - PairwiseTableStrategy}, + arch::{PackedStrategy, PairwiseStrategy, PairwiseTableStrategy}, arithmetic_traits::TaggedSquare }; @@ -29,10 +28,6 @@ cfg_if! { val.square() } - fn square_pairwise_recursive>(val: T) -> T { - val.square() - } - fn square_pairwise_table>(val: T) -> T { val.square() } @@ -47,7 +42,6 @@ cfg_if! { strategies @ ( (main, PackedField, square_main), (pairwise, TaggedSquare::, square_pairwise), - (pairwise_recursive, TaggedSquare::, square_pairwise_recursive), (pairwise_table, TaggedSquare::, square_pairwise_table), (packed, TaggedSquare::, square_packed), ) diff --git a/crates/field/src/aes_field.rs b/crates/field/src/aes_field.rs index 3625eff62..4b075ad2a 100644 --- a/crates/field/src/aes_field.rs +++ b/crates/field/src/aes_field.rs @@ -49,14 +49,6 @@ impl TowerField for AESTowerField8b { _ => 3, } } - - fn mul_primitive(self, iota: usize) -> Self { - match iota { - 0..=1 => self * ISOMORPHIC_ALPHAS[iota], - 2 => self.multiply_alpha(), - _ => panic!("iota {iota} must be less than tower level 3"), - } - } } /// A 3- step transformation : @@ -82,13 +74,6 @@ where } } -/// Values isomorphic to 0x02, 0x04 and 0x10 in BinaryField8b -const ISOMORPHIC_ALPHAS: [AESTowerField8b; 3] = [ - AESTowerField8b(0xBC), - AESTowerField8b(0xB0), - AESTowerField8b(0xD3), -]; - impl SerializeBytes for AESTowerField8b { fn serialize(&self, write_buf: impl BufMut) -> Result<(), SerializationError> { self.0.serialize(write_buf) @@ -111,9 +96,7 @@ mod tests { use rand::prelude::*; use super::*; - use crate::{ - Random, binary_field::tests::is_binary_field_valid_generator, underlier::WithUnderlier, - }; + use crate::{Random, binary_field::tests::is_binary_field_valid_generator}; fn check_square(f: impl Field) { assert_eq!(f.square(), f * f); @@ -185,30 +168,6 @@ mod tests { assert!(is_binary_field_valid_generator::()); } - fn test_mul_primitive_valid>>( - val: F, - iota: usize, - ) { - let result = val.mul_primitive(iota); - let expected = - val * F::from_underlier(F::Underlier::from(ISOMORPHIC_ALPHAS[iota].to_underlier())); - assert_eq!(result, expected); - } - - proptest! { - #[test] - fn test_mul_primitive_8b(val in 0u8.., iota in 0usize..3) { - test_mul_primitive_valid::(val.into(), iota) - } - } - - #[test] - #[should_panic(expected = "must be less than tower level")] - fn test_mul_primitive_out_of_range() { - let val = AESTowerField8b::from(1u8); - val.mul_primitive(3); - } - #[test] fn test_serialization() { let mut buffer = BytesMut::new(); diff --git a/crates/field/src/arch/aarch64/packed_128.rs b/crates/field/src/arch/aarch64/packed_128.rs index 0458aedb4..cbb0955e7 100644 --- a/crates/field/src/arch/aarch64/packed_128.rs +++ b/crates/field/src/arch/aarch64/packed_128.rs @@ -15,7 +15,6 @@ define_packed_binary_fields!( mul: (BitwiseAndStrategy), square: (BitwiseAndStrategy), invert: (BitwiseAndStrategy), - mul_alpha: (BitwiseAndStrategy), transform: (PackedStrategy), }, ] diff --git a/crates/field/src/arch/aarch64/packed_aes_128.rs b/crates/field/src/arch/aarch64/packed_aes_128.rs index f4751359e..61ad1bdf8 100644 --- a/crates/field/src/arch/aarch64/packed_aes_128.rs +++ b/crates/field/src/arch/aarch64/packed_aes_128.rs @@ -6,14 +6,13 @@ use std::ops::Mul; use super::{ m128::M128, simd_arithmetic::{ - packed_aes_16x8b_invert_or_zero, packed_aes_16x8b_mul_alpha, packed_aes_16x8b_multiply, - packed_aes_16x8b_square, + packed_aes_16x8b_invert_or_zero, packed_aes_16x8b_multiply, packed_aes_16x8b_square, }, }; use crate::{ aes_field::AESTowerField8b, arch::portable::packed::PackedPrimitiveType, - arithmetic_traits::{InvertOrZero, MulAlpha, Square}, + arithmetic_traits::{InvertOrZero, Square}, underlier::WithUnderlier, }; @@ -41,12 +40,6 @@ impl InvertOrZero for PackedAESBinaryField16x8b { } } -impl MulAlpha for PackedAESBinaryField16x8b { - fn mul_alpha(self) -> Self { - self.mutate_underlier(packed_aes_16x8b_mul_alpha) - } -} - #[cfg(test)] mod tests { use proptest::prelude::*; diff --git a/crates/field/src/arch/aarch64/packed_ghash_128.rs b/crates/field/src/arch/aarch64/packed_ghash_128.rs index a48176a2c..03b5770e2 100644 --- a/crates/field/src/arch/aarch64/packed_ghash_128.rs +++ b/crates/field/src/arch/aarch64/packed_ghash_128.rs @@ -60,7 +60,6 @@ define_packed_binary_field!( (GhashStrategy), (GhashStrategy), (GhashStrategy), - (None), (None) ); diff --git a/crates/field/src/arch/aarch64/simd_arithmetic.rs b/crates/field/src/arch/aarch64/simd_arithmetic.rs index 4c5d82fd7..1ab591fd4 100644 --- a/crates/field/src/arch/aarch64/simd_arithmetic.rs +++ b/crates/field/src/arch/aarch64/simd_arithmetic.rs @@ -53,12 +53,6 @@ pub fn packed_aes_16x8b_square(x: M128) -> M128 { } } -#[inline] -pub fn packed_aes_16x8b_mul_alpha(x: M128) -> M128 { - // 0xD3 corresponds to 0x10 after isomorphism from BinaryField8b to AESField - packed_aes_16x8b_multiply(x, M128::from_le_bytes([0xD3; 16])) -} - #[inline] pub fn packed_aes_16x8b_multiply(a: M128, b: M128) -> M128 { //! Performs a multiplication in GF(2^8) on the packed bytes. diff --git a/crates/field/src/arch/portable/bitwise_and_arithmetic.rs b/crates/field/src/arch/portable/bitwise_and_arithmetic.rs index 366fbd8b4..17430529b 100644 --- a/crates/field/src/arch/portable/bitwise_and_arithmetic.rs +++ b/crates/field/src/arch/portable/bitwise_and_arithmetic.rs @@ -4,7 +4,7 @@ use super::packed::PackedPrimitiveType; use crate::{ BinaryField1b, arch::BitwiseAndStrategy, - arithmetic_traits::{TaggedInvertOrZero, TaggedMul, TaggedMulAlpha, TaggedSquare}, + arithmetic_traits::{TaggedInvertOrZero, TaggedMul, TaggedSquare}, underlier::UnderlierWithBitOps, }; @@ -34,12 +34,3 @@ impl TaggedInvertOrZero self } } - -impl TaggedMulAlpha - for PackedPrimitiveType -{ - #[inline] - fn mul_alpha(self) -> Self { - self - } -} diff --git a/crates/field/src/arch/portable/mod.rs b/crates/field/src/arch/portable/mod.rs index f89d26a59..04d6c3b50 100644 --- a/crates/field/src/arch/portable/mod.rs +++ b/crates/field/src/arch/portable/mod.rs @@ -32,7 +32,6 @@ pub(crate) mod univariate_mul_utils_128; pub(super) mod bitwise_and_arithmetic; pub(crate) mod packed_arithmetic; pub(super) mod pairwise_arithmetic; -pub(super) mod pairwise_recursive_arithmetic; pub(super) mod pairwise_table_arithmetic; pub(super) mod reuse_multiply_arithmetic; pub(super) mod scaled_arithmetic; diff --git a/crates/field/src/arch/portable/packed.rs b/crates/field/src/arch/portable/packed.rs index b78b14b5b..2e4392135 100644 --- a/crates/field/src/arch/portable/packed.rs +++ b/crates/field/src/arch/portable/packed.rs @@ -22,7 +22,7 @@ use rand::{ use crate::{ BinaryField, Divisible, ExtensionField, Field, PackedField, - arithmetic_traits::{InvertOrZero, MulAlpha, Square}, + arithmetic_traits::{InvertOrZero, Square}, field::FieldOps, underlier::{NumCast, UnderlierType, UnderlierWithBitOps, WithUnderlier}, }; @@ -551,20 +551,3 @@ where PT1::from_underlier(PT1::Underlier::num_cast_from(bigger_result.to_underlier())) } - -/// Multiply by alpha `PT1` values by upcasting to wider `PT2` type with the same scalar. -/// This is useful for the cases when SIMD multiply by alpha is faster. -#[allow(dead_code)] -pub fn mul_alpha_as_bigger_type(val: PT1) -> PT1 -where - PT1: PackedField + WithUnderlier, - PT2: PackedField + WithUnderlier + MulAlpha, - PT2::Underlier: From, - PT1::Underlier: NumCast, -{ - let bigger_val = PT2::from_underlier(val.to_underlier().into()); - - let bigger_result = bigger_val.mul_alpha(); - - PT1::from_underlier(PT1::Underlier::num_cast_from(bigger_result.to_underlier())) -} diff --git a/crates/field/src/arch/portable/packed_1.rs b/crates/field/src/arch/portable/packed_1.rs index 6943256d0..dd8887cc9 100644 --- a/crates/field/src/arch/portable/packed_1.rs +++ b/crates/field/src/arch/portable/packed_1.rs @@ -17,7 +17,6 @@ define_packed_binary_fields!( mul: (BitwiseAndStrategy), square: (BitwiseAndStrategy), invert: (BitwiseAndStrategy), - mul_alpha: (BitwiseAndStrategy), transform: (PackedStrategy), }, ] diff --git a/crates/field/src/arch/portable/packed_128.rs b/crates/field/src/arch/portable/packed_128.rs index da6d63d79..6aa8ee22a 100644 --- a/crates/field/src/arch/portable/packed_128.rs +++ b/crates/field/src/arch/portable/packed_128.rs @@ -16,7 +16,6 @@ define_packed_binary_fields!( mul: (BitwiseAndStrategy), square: (BitwiseAndStrategy), invert: (BitwiseAndStrategy), - mul_alpha: (BitwiseAndStrategy), transform: (PackedStrategy), }, ] diff --git a/crates/field/src/arch/portable/packed_16.rs b/crates/field/src/arch/portable/packed_16.rs index a200651eb..97b991bc0 100644 --- a/crates/field/src/arch/portable/packed_16.rs +++ b/crates/field/src/arch/portable/packed_16.rs @@ -14,7 +14,6 @@ define_packed_binary_fields!( mul: (BitwiseAndStrategy), square: (BitwiseAndStrategy), invert: (BitwiseAndStrategy), - mul_alpha: (BitwiseAndStrategy), transform: (PackedStrategy), }, ] diff --git a/crates/field/src/arch/portable/packed_2.rs b/crates/field/src/arch/portable/packed_2.rs index 1230d3c4f..15f171f0d 100644 --- a/crates/field/src/arch/portable/packed_2.rs +++ b/crates/field/src/arch/portable/packed_2.rs @@ -17,7 +17,6 @@ define_packed_binary_fields!( mul: (BitwiseAndStrategy), square: (BitwiseAndStrategy), invert: (BitwiseAndStrategy), - mul_alpha: (BitwiseAndStrategy), transform: (PackedStrategy), }, ] diff --git a/crates/field/src/arch/portable/packed_256.rs b/crates/field/src/arch/portable/packed_256.rs index 7e1cd1562..06001b87e 100644 --- a/crates/field/src/arch/portable/packed_256.rs +++ b/crates/field/src/arch/portable/packed_256.rs @@ -20,7 +20,6 @@ define_packed_binary_fields!( mul: (ScaledStrategy), square: (ScaledStrategy), invert: (ScaledStrategy), - mul_alpha: (ScaledStrategy), transform: (ScaledStrategy), }, ] diff --git a/crates/field/src/arch/portable/packed_32.rs b/crates/field/src/arch/portable/packed_32.rs index 8e9dfc899..b2ab14ac7 100644 --- a/crates/field/src/arch/portable/packed_32.rs +++ b/crates/field/src/arch/portable/packed_32.rs @@ -14,7 +14,6 @@ define_packed_binary_fields!( mul: (BitwiseAndStrategy), square: (BitwiseAndStrategy), invert: (BitwiseAndStrategy), - mul_alpha: (BitwiseAndStrategy), transform: (PackedStrategy), }, ] diff --git a/crates/field/src/arch/portable/packed_4.rs b/crates/field/src/arch/portable/packed_4.rs index 65809c117..02c891815 100644 --- a/crates/field/src/arch/portable/packed_4.rs +++ b/crates/field/src/arch/portable/packed_4.rs @@ -17,7 +17,6 @@ define_packed_binary_fields!( mul: (BitwiseAndStrategy), square: (BitwiseAndStrategy), invert: (BitwiseAndStrategy), - mul_alpha: (BitwiseAndStrategy), transform: (PackedStrategy), }, ] diff --git a/crates/field/src/arch/portable/packed_512.rs b/crates/field/src/arch/portable/packed_512.rs index fca6737d4..963a2002e 100644 --- a/crates/field/src/arch/portable/packed_512.rs +++ b/crates/field/src/arch/portable/packed_512.rs @@ -20,7 +20,6 @@ define_packed_binary_fields!( mul: (ScaledStrategy), square: (ScaledStrategy), invert: (ScaledStrategy), - mul_alpha: (ScaledStrategy), transform: (ScaledStrategy), }, ] diff --git a/crates/field/src/arch/portable/packed_64.rs b/crates/field/src/arch/portable/packed_64.rs index 6641ab7e1..e9971a036 100644 --- a/crates/field/src/arch/portable/packed_64.rs +++ b/crates/field/src/arch/portable/packed_64.rs @@ -14,7 +14,6 @@ define_packed_binary_fields!( mul: (BitwiseAndStrategy), square: (BitwiseAndStrategy), invert: (BitwiseAndStrategy), - mul_alpha: (BitwiseAndStrategy), transform: (PackedStrategy), }, ] diff --git a/crates/field/src/arch/portable/packed_8.rs b/crates/field/src/arch/portable/packed_8.rs index 02c978194..cade7cde5 100644 --- a/crates/field/src/arch/portable/packed_8.rs +++ b/crates/field/src/arch/portable/packed_8.rs @@ -14,7 +14,6 @@ define_packed_binary_fields!( mul: (BitwiseAndStrategy), square: (BitwiseAndStrategy), invert: (BitwiseAndStrategy), - mul_alpha: (BitwiseAndStrategy), transform: (PackedStrategy), }, ] diff --git a/crates/field/src/arch/portable/packed_aes_128.rs b/crates/field/src/arch/portable/packed_aes_128.rs index dbd5d5ea2..df9a49fd1 100644 --- a/crates/field/src/arch/portable/packed_aes_128.rs +++ b/crates/field/src/arch/portable/packed_aes_128.rs @@ -5,7 +5,7 @@ use crate::{ PairwiseTableStrategy, portable::packed_macros::{portable_macros::*, *}, }, - arithmetic_traits::{impl_invert_with, impl_mul_alpha_with, impl_mul_with, impl_square_with}, + arithmetic_traits::{impl_invert_with, impl_mul_with, impl_square_with}, }; define_packed_binary_fields!( @@ -17,7 +17,6 @@ define_packed_binary_fields!( mul: (PairwiseTableStrategy), square: (PairwiseTableStrategy), invert: (PairwiseTableStrategy), - mul_alpha: (PairwiseTableStrategy), transform: (PackedStrategy), }, ] diff --git a/crates/field/src/arch/portable/packed_aes_16.rs b/crates/field/src/arch/portable/packed_aes_16.rs index 655e5ac03..76ad298e8 100644 --- a/crates/field/src/arch/portable/packed_aes_16.rs +++ b/crates/field/src/arch/portable/packed_aes_16.rs @@ -5,7 +5,7 @@ use crate::{ PairwiseTableStrategy, portable::packed_macros::{portable_macros::*, *}, }, - arithmetic_traits::{impl_invert_with, impl_mul_alpha_with, impl_mul_with, impl_square_with}, + arithmetic_traits::{impl_invert_with, impl_mul_with, impl_square_with}, }; define_packed_binary_fields!( @@ -17,7 +17,6 @@ define_packed_binary_fields!( mul: (PairwiseTableStrategy), square: (PairwiseTableStrategy), invert: (PairwiseTableStrategy), - mul_alpha: (PairwiseTableStrategy), transform: (PackedStrategy), }, ] diff --git a/crates/field/src/arch/portable/packed_aes_256.rs b/crates/field/src/arch/portable/packed_aes_256.rs index 6c8f27ab6..041dbef99 100644 --- a/crates/field/src/arch/portable/packed_aes_256.rs +++ b/crates/field/src/arch/portable/packed_aes_256.rs @@ -15,7 +15,6 @@ define_packed_binary_fields!( mul: (ScaledStrategy), square: (ScaledStrategy), invert: (ScaledStrategy), - mul_alpha: (ScaledStrategy), transform: (ScaledStrategy), }, ] diff --git a/crates/field/src/arch/portable/packed_aes_32.rs b/crates/field/src/arch/portable/packed_aes_32.rs index caf774f21..0659700dc 100644 --- a/crates/field/src/arch/portable/packed_aes_32.rs +++ b/crates/field/src/arch/portable/packed_aes_32.rs @@ -7,7 +7,7 @@ use crate::{ PairwiseTableStrategy, portable::packed_macros::{portable_macros::*, *}, }, - arithmetic_traits::{impl_invert_with, impl_mul_alpha_with, impl_mul_with, impl_square_with}, + arithmetic_traits::{impl_invert_with, impl_mul_with, impl_square_with}, }; define_packed_binary_fields!( @@ -19,7 +19,6 @@ define_packed_binary_fields!( mul: (if gfni_x86 PackedAESBinaryField16x8b else PairwiseTableStrategy), square: (PairwiseTableStrategy), invert: (if gfni_x86 PackedAESBinaryField16x8b else PairwiseTableStrategy), - mul_alpha: (PairwiseTableStrategy), transform: (PackedStrategy), }, ] diff --git a/crates/field/src/arch/portable/packed_aes_512.rs b/crates/field/src/arch/portable/packed_aes_512.rs index ad40a8c4b..7ed207cf0 100644 --- a/crates/field/src/arch/portable/packed_aes_512.rs +++ b/crates/field/src/arch/portable/packed_aes_512.rs @@ -15,7 +15,6 @@ define_packed_binary_fields!( mul: (ScaledStrategy), square: (ScaledStrategy), invert: (ScaledStrategy), - mul_alpha: (ScaledStrategy), transform: (ScaledStrategy), }, ] diff --git a/crates/field/src/arch/portable/packed_aes_64.rs b/crates/field/src/arch/portable/packed_aes_64.rs index e2c6ddec3..be3aba870 100644 --- a/crates/field/src/arch/portable/packed_aes_64.rs +++ b/crates/field/src/arch/portable/packed_aes_64.rs @@ -3,11 +3,8 @@ use cfg_if::cfg_if; use crate::{ - arch::{ - PairwiseTableStrategy, - portable::packed_macros::{portable_macros::*, *}, - }, - arithmetic_traits::{impl_invert_with, impl_mul_alpha_with, impl_mul_with, impl_square_with}, + arch::portable::packed_macros::{portable_macros::*, *}, + arithmetic_traits::{impl_invert_with, impl_mul_with, impl_square_with}, }; define_packed_binary_fields!( @@ -19,7 +16,6 @@ define_packed_binary_fields!( mul: (if gfni_x86 PackedAESBinaryField16x8b else PairwiseTableStrategy), square: (if gfni_x86 PackedAESBinaryField16x8b else PairwiseTableStrategy), invert: (if gfni_x86 PackedAESBinaryField16x8b else PairwiseTableStrategy), - mul_alpha: (PairwiseTableStrategy), transform: (PackedStrategy), }, ] diff --git a/crates/field/src/arch/portable/packed_aes_8.rs b/crates/field/src/arch/portable/packed_aes_8.rs index acfa357e3..9a84f30fd 100644 --- a/crates/field/src/arch/portable/packed_aes_8.rs +++ b/crates/field/src/arch/portable/packed_aes_8.rs @@ -5,7 +5,7 @@ use crate::{ PairwiseTableStrategy, portable::packed_macros::{portable_macros::*, *}, }, - arithmetic_traits::{impl_invert_with, impl_mul_alpha_with, impl_mul_with, impl_square_with}, + arithmetic_traits::{impl_invert_with, impl_mul_with, impl_square_with}, }; define_packed_binary_fields!( @@ -17,7 +17,6 @@ define_packed_binary_fields!( mul: (PairwiseTableStrategy), square: (PairwiseTableStrategy), invert: (PairwiseTableStrategy), - mul_alpha: (PairwiseTableStrategy), transform: (PairwiseStrategy), }, ] diff --git a/crates/field/src/arch/portable/packed_ghash_128.rs b/crates/field/src/arch/portable/packed_ghash_128.rs index 9aee710e9..98d09af9e 100644 --- a/crates/field/src/arch/portable/packed_ghash_128.rs +++ b/crates/field/src/arch/portable/packed_ghash_128.rs @@ -104,7 +104,6 @@ define_packed_binary_field!( (GhashStrategy), (GhashStrategy), (GhashStrategy), - (None), (None) ); diff --git a/crates/field/src/arch/portable/packed_ghash_256.rs b/crates/field/src/arch/portable/packed_ghash_256.rs index c9b550a0b..3cde9b404 100644 --- a/crates/field/src/arch/portable/packed_ghash_256.rs +++ b/crates/field/src/arch/portable/packed_ghash_256.rs @@ -15,7 +15,6 @@ define_packed_binary_fields!( mul: (ScaledStrategy), square: (ScaledStrategy), invert: (ScaledStrategy), - mul_alpha: (None), transform: (None), }, ] diff --git a/crates/field/src/arch/portable/packed_ghash_512.rs b/crates/field/src/arch/portable/packed_ghash_512.rs index dc350ad8e..9b253c504 100644 --- a/crates/field/src/arch/portable/packed_ghash_512.rs +++ b/crates/field/src/arch/portable/packed_ghash_512.rs @@ -15,7 +15,6 @@ define_packed_binary_fields!( mul: (ScaledStrategy), square: (ScaledStrategy), invert: (ScaledStrategy), - mul_alpha: (None), transform: (None), }, ] diff --git a/crates/field/src/arch/portable/packed_macros.rs b/crates/field/src/arch/portable/packed_macros.rs index 6e434e28d..8a5d4cbf4 100644 --- a/crates/field/src/arch/portable/packed_macros.rs +++ b/crates/field/src/arch/portable/packed_macros.rs @@ -11,7 +11,6 @@ macro_rules! define_packed_binary_fields { mul: ($($mul:tt)*), square: ($($square:tt)*), invert: ($($invert:tt)*), - mul_alpha: ($($mul_alpha:tt)*), transform: ($($transform:tt)*), } ),* $(,)? @@ -25,7 +24,6 @@ macro_rules! define_packed_binary_fields { ($($mul)*), ($($square)*), ($($invert)*), - ($($mul_alpha)*), ($($transform)*) ); )* @@ -38,7 +36,6 @@ macro_rules! define_packed_binary_field { ($($mul:tt)*), ($($square:tt)*), ($($invert:tt)*), - ($($mul_alpha:tt)*), ($($transform:tt)*) ) => { // Define packed field types @@ -56,9 +53,6 @@ macro_rules! define_packed_binary_field { // Define invert impl_strategy!(impl_invert_with $name, ($($invert)*)); - // Define multiply by alpha - impl_strategy!(impl_mul_alpha_with $name, ($($mul_alpha)*)); - // Define linear transformations //impl_transformation!($name, ($($transform)*)); }; @@ -92,9 +86,7 @@ pub(crate) use define_packed_binary_field; pub(crate) use define_packed_binary_fields; pub(crate) use impl_serialize_deserialize_for_packed_binary_field; -pub(crate) use crate::arithmetic_traits::{ - impl_invert_with, impl_mul_alpha_with, impl_mul_with, impl_square_with, -}; +pub(crate) use crate::arithmetic_traits::{impl_invert_with, impl_mul_with, impl_square_with}; pub(crate) mod portable_macros { macro_rules! impl_strategy { diff --git a/crates/field/src/arch/portable/pairwise_arithmetic.rs b/crates/field/src/arch/portable/pairwise_arithmetic.rs index c34fcd372..684e8e0ea 100644 --- a/crates/field/src/arch/portable/pairwise_arithmetic.rs +++ b/crates/field/src/arch/portable/pairwise_arithmetic.rs @@ -2,9 +2,7 @@ use crate::{ arch::PairwiseStrategy, - arithmetic_traits::{ - InvertOrZero, MulAlpha, Square, TaggedInvertOrZero, TaggedMul, TaggedMulAlpha, TaggedSquare, - }, + arithmetic_traits::{InvertOrZero, Square, TaggedInvertOrZero, TaggedMul, TaggedSquare}, linear_transformation::Transformation, packed::PackedField, }; @@ -51,21 +49,6 @@ where } } -impl TaggedMulAlpha for PT -where - PT::Scalar: MulAlpha, -{ - #[inline] - fn mul_alpha(self) -> Self { - if PT::WIDTH == 1 { - // fallback to be able to benchmark this strategy - MulAlpha::mul_alpha(self) - } else { - Self::from_fn(|i| MulAlpha::mul_alpha(self.get(i))) - } - } -} - /// Per element transformation pub struct PairwiseTransformation { inner: I, diff --git a/crates/field/src/arch/portable/pairwise_recursive_arithmetic.rs b/crates/field/src/arch/portable/pairwise_recursive_arithmetic.rs deleted file mode 100644 index da1b17d37..000000000 --- a/crates/field/src/arch/portable/pairwise_recursive_arithmetic.rs +++ /dev/null @@ -1,102 +0,0 @@ -// Copyright 2024-2025 Irreducible Inc. - -use crate::{ - TowerExtensionField, - arch::PairwiseRecursiveStrategy, - arithmetic_traits::{ - InvertOrZero, MulAlpha, Square, TaggedInvertOrZero, TaggedMul, TaggedMulAlpha, TaggedSquare, - }, - packed::PackedField, -}; - -impl

TaggedMul for P -where - P: PackedField, - P::Scalar: TowerExtensionField, -{ - #[inline] - fn mul(self, rhs: Self) -> Self { - P::from_fn(|i| { - let (a0, a1) = self.get(i).into(); - let (b0, b1) = rhs.get(i).into(); - let (z0, z2) = (a0 * b0, a1 * b1); - let z0z2 = z0 + z2; - let z1 = (a0 + a1) * (b0 + b1) - z0z2; - let z2a = MulAlpha::mul_alpha(z2); - - (z0z2, z1 + z2a).into() - }) - } -} - -impl

TaggedSquare for P -where - P: PackedField, - P::Scalar: TowerExtensionField, -{ - #[inline] - fn square(self) -> Self { - P::from_fn(|i| { - let (a0, a1) = self.get(i).into(); - let (z0, z2) = (Square::square(a0), Square::square(a1)); - let z2a = MulAlpha::mul_alpha(z2); - (z0 + z2, z2a).into() - }) - } -} - -impl

TaggedMulAlpha for P -where - P: PackedField, - P::Scalar: TowerExtensionField, -{ - #[inline] - fn mul_alpha(self) -> Self { - P::from_fn(|i| { - let (a0, a1) = self.get(i).into(); - let z1 = MulAlpha::mul_alpha(a1); - - (a1, a0 + z1).into() - }) - } -} - -impl

TaggedInvertOrZero for P -where - P: PackedField, - P::Scalar: TowerExtensionField, -{ - #[inline] - fn invert_or_zero(self) -> Self { - P::from_fn(|i| { - let (a0, a1) = self.get(i).into(); - let a0z1 = a0 + MulAlpha::mul_alpha(a1); - let delta = a0 * a0z1 + Square::square(a1); - let delta_inv = InvertOrZero::invert_or_zero(delta); - let inv0 = delta_inv * a0z1; - let inv1 = delta_inv * a1; - (inv0, inv1).into() - }) - } -} - -#[cfg(test)] -mod tests { - use super::*; - use crate::test_utils::{define_invert_tests, define_multiply_tests, define_square_tests}; - - define_multiply_tests!( - TaggedMul::mul, - TaggedMul - ); - - define_square_tests!( - TaggedSquare::square, - TaggedSquare - ); - - define_invert_tests!( - TaggedInvertOrZero::invert_or_zero, - TaggedInvertOrZero - ); -} diff --git a/crates/field/src/arch/portable/pairwise_table_arithmetic.rs b/crates/field/src/arch/portable/pairwise_table_arithmetic.rs index 0d13f7d9d..aad84285e 100644 --- a/crates/field/src/arch/portable/pairwise_table_arithmetic.rs +++ b/crates/field/src/arch/portable/pairwise_table_arithmetic.rs @@ -4,7 +4,7 @@ use super::packed::PackedPrimitiveType; use crate::{ AESTowerField8b, arch::PairwiseTableStrategy, - arithmetic_traits::{TaggedInvertOrZero, TaggedMul, TaggedMulAlpha, TaggedSquare}, + arithmetic_traits::{TaggedInvertOrZero, TaggedMul, TaggedSquare}, packed::PackedField, underlier::UnderlierType, }; @@ -144,28 +144,6 @@ const AES_TOWER_8B_SQUARE_MAP: [u8; 256] = [ impl_unary_ops!(TaggedSquare, square, AES_TOWER_8B_SQUARE_MAP, AESTowerField8b); -#[rustfmt::skip] -const AES_TOWER_8B_MUL_ALPHA_MAP: [u8; 256] = [ - 0x00, 0xd3, 0xbd, 0x6e, 0x61, 0xb2, 0xdc, 0x0f, 0xc2, 0x11, 0x7f, 0xac, 0xa3, 0x70, 0x1e, 0xcd, - 0x9f, 0x4c, 0x22, 0xf1, 0xfe, 0x2d, 0x43, 0x90, 0x5d, 0x8e, 0xe0, 0x33, 0x3c, 0xef, 0x81, 0x52, - 0x25, 0xf6, 0x98, 0x4b, 0x44, 0x97, 0xf9, 0x2a, 0xe7, 0x34, 0x5a, 0x89, 0x86, 0x55, 0x3b, 0xe8, - 0xba, 0x69, 0x07, 0xd4, 0xdb, 0x08, 0x66, 0xb5, 0x78, 0xab, 0xc5, 0x16, 0x19, 0xca, 0xa4, 0x77, - 0x4a, 0x99, 0xf7, 0x24, 0x2b, 0xf8, 0x96, 0x45, 0x88, 0x5b, 0x35, 0xe6, 0xe9, 0x3a, 0x54, 0x87, - 0xd5, 0x06, 0x68, 0xbb, 0xb4, 0x67, 0x09, 0xda, 0x17, 0xc4, 0xaa, 0x79, 0x76, 0xa5, 0xcb, 0x18, - 0x6f, 0xbc, 0xd2, 0x01, 0x0e, 0xdd, 0xb3, 0x60, 0xad, 0x7e, 0x10, 0xc3, 0xcc, 0x1f, 0x71, 0xa2, - 0xf0, 0x23, 0x4d, 0x9e, 0x91, 0x42, 0x2c, 0xff, 0x32, 0xe1, 0x8f, 0x5c, 0x53, 0x80, 0xee, 0x3d, - 0x94, 0x47, 0x29, 0xfa, 0xf5, 0x26, 0x48, 0x9b, 0x56, 0x85, 0xeb, 0x38, 0x37, 0xe4, 0x8a, 0x59, - 0x0b, 0xd8, 0xb6, 0x65, 0x6a, 0xb9, 0xd7, 0x04, 0xc9, 0x1a, 0x74, 0xa7, 0xa8, 0x7b, 0x15, 0xc6, - 0xb1, 0x62, 0x0c, 0xdf, 0xd0, 0x03, 0x6d, 0xbe, 0x73, 0xa0, 0xce, 0x1d, 0x12, 0xc1, 0xaf, 0x7c, - 0x2e, 0xfd, 0x93, 0x40, 0x4f, 0x9c, 0xf2, 0x21, 0xec, 0x3f, 0x51, 0x82, 0x8d, 0x5e, 0x30, 0xe3, - 0xde, 0x0d, 0x63, 0xb0, 0xbf, 0x6c, 0x02, 0xd1, 0x1c, 0xcf, 0xa1, 0x72, 0x7d, 0xae, 0xc0, 0x13, - 0x41, 0x92, 0xfc, 0x2f, 0x20, 0xf3, 0x9d, 0x4e, 0x83, 0x50, 0x3e, 0xed, 0xe2, 0x31, 0x5f, 0x8c, - 0xfb, 0x28, 0x46, 0x95, 0x9a, 0x49, 0x27, 0xf4, 0x39, 0xea, 0x84, 0x57, 0x58, 0x8b, 0xe5, 0x36, - 0x64, 0xb7, 0xd9, 0x0a, 0x05, 0xd6, 0xb8, 0x6b, 0xa6, 0x75, 0x1b, 0xc8, 0xc7, 0x14, 0x7a, 0xa9, -]; - -impl_unary_ops!(TaggedMulAlpha, mul_alpha, AES_TOWER_8B_MUL_ALPHA_MAP, AESTowerField8b); - #[rustfmt::skip] const AES_TOWER_8B_INVERT_MAP: [u8; 256] = [ 0x00, 0x01, 0x8d, 0xf6, 0xcb, 0x52, 0x7b, 0xd1, 0xe8, 0x4f, 0x29, 0xc0, 0xb0, 0xe1, 0xe5, 0xc7, diff --git a/crates/field/src/arch/portable/reuse_multiply_arithmetic.rs b/crates/field/src/arch/portable/reuse_multiply_arithmetic.rs index 241443fd0..6bee2932b 100644 --- a/crates/field/src/arch/portable/reuse_multiply_arithmetic.rs +++ b/crates/field/src/arch/portable/reuse_multiply_arithmetic.rs @@ -2,10 +2,7 @@ use std::ops::Mul; -use crate::{ - arch::ReuseMultiplyStrategy, - arithmetic_traits::{TaggedMulAlpha, TaggedSquare}, -}; +use crate::{arch::ReuseMultiplyStrategy, arithmetic_traits::TaggedSquare}; impl TaggedSquare for T where @@ -15,17 +12,3 @@ where self * self } } - -pub trait Alpha { - fn alpha() -> Self; -} - -impl TaggedMulAlpha for T -where - T: Mul + Alpha, -{ - #[inline] - fn mul_alpha(self) -> Self { - self * Self::alpha() - } -} diff --git a/crates/field/src/arch/portable/scaled_arithmetic.rs b/crates/field/src/arch/portable/scaled_arithmetic.rs index b733349fe..cbd18466b 100644 --- a/crates/field/src/arch/portable/scaled_arithmetic.rs +++ b/crates/field/src/arch/portable/scaled_arithmetic.rs @@ -8,9 +8,7 @@ use super::packed::PackedPrimitiveType; use crate::{ BinaryField, arch::ScaledStrategy, - arithmetic_traits::{ - InvertOrZero, MulAlpha, Square, TaggedInvertOrZero, TaggedMul, TaggedMulAlpha, TaggedSquare, - }, + arithmetic_traits::{InvertOrZero, Square, TaggedInvertOrZero, TaggedMul, TaggedSquare}, underlier::{ScaledUnderlier, UnderlierType}, }; @@ -30,18 +28,6 @@ where } } -impl TaggedMulAlpha - for PackedPrimitiveType, Scalar> -where - PackedPrimitiveType: MulAlpha, -{ - fn mul_alpha(self) -> Self { - Self::wrap(ScaledUnderlier(self.0.0.map(|sub_underlier| { - PackedPrimitiveType::peel(PackedPrimitiveType::wrap(sub_underlier).mul_alpha()) - }))) - } -} - impl TaggedSquare for PackedPrimitiveType, Scalar> where diff --git a/crates/field/src/arch/strategies.rs b/crates/field/src/arch/strategies.rs index db2b5118f..c3739b75b 100644 --- a/crates/field/src/arch/strategies.rs +++ b/crates/field/src/arch/strategies.rs @@ -4,9 +4,6 @@ /// (Uses arithmetic operations with underlier and subfield to simultaneously calculate the result /// for all packed values) pub struct PackedStrategy; -/// Pairwise recursive strategy. Calculates the result by applying recursive algorithm for each -/// packed value independently. -pub struct PairwiseRecursiveStrategy; /// Pairwise strategy. Apply the result of the operation to each packed element independently. pub struct PairwiseStrategy; /// Get result of operation from the table for each sub-element diff --git a/crates/field/src/arch/x86_64/packed_128.rs b/crates/field/src/arch/x86_64/packed_128.rs index a1371453b..db1603cf9 100644 --- a/crates/field/src/arch/x86_64/packed_128.rs +++ b/crates/field/src/arch/x86_64/packed_128.rs @@ -15,7 +15,6 @@ define_packed_binary_fields!( mul: (BitwiseAndStrategy), square: (BitwiseAndStrategy), invert: (BitwiseAndStrategy), - mul_alpha: (BitwiseAndStrategy), transform: (None), }, ] diff --git a/crates/field/src/arch/x86_64/packed_256.rs b/crates/field/src/arch/x86_64/packed_256.rs index 794d50888..612c23d4e 100644 --- a/crates/field/src/arch/x86_64/packed_256.rs +++ b/crates/field/src/arch/x86_64/packed_256.rs @@ -15,7 +15,6 @@ define_packed_binary_fields!( mul: (BitwiseAndStrategy), square: (BitwiseAndStrategy), invert: (BitwiseAndStrategy), - mul_alpha: (BitwiseAndStrategy), transform: (SimdStrategy), }, ] diff --git a/crates/field/src/arch/x86_64/packed_512.rs b/crates/field/src/arch/x86_64/packed_512.rs index 6bc86cdb8..565eb2e37 100644 --- a/crates/field/src/arch/x86_64/packed_512.rs +++ b/crates/field/src/arch/x86_64/packed_512.rs @@ -15,7 +15,6 @@ define_packed_binary_fields!( mul: (BitwiseAndStrategy), square: (BitwiseAndStrategy), invert: (BitwiseAndStrategy), - mul_alpha: (BitwiseAndStrategy), transform: (SimdStrategy), }, ] diff --git a/crates/field/src/arch/x86_64/packed_aes_128.rs b/crates/field/src/arch/x86_64/packed_aes_128.rs index 1924322b3..0fb2a2fc0 100644 --- a/crates/field/src/arch/x86_64/packed_aes_128.rs +++ b/crates/field/src/arch/x86_64/packed_aes_128.rs @@ -5,7 +5,7 @@ use cfg_if::cfg_if; use super::m128::M128; use crate::{ arch::portable::packed_macros::{portable_macros::*, *}, - arithmetic_traits::{impl_invert_with, impl_mul_alpha_with, impl_mul_with, impl_square_with}, + arithmetic_traits::{impl_invert_with, impl_mul_with, impl_square_with}, }; define_packed_binary_fields!( @@ -17,7 +17,6 @@ define_packed_binary_fields!( mul: (if gfni GfniStrategy else PairwiseTableStrategy), square: (if gfni ReuseMultiplyStrategy else PairwiseTableStrategy), invert: (if gfni GfniStrategy else PairwiseTableStrategy), - mul_alpha: (if gfni ReuseMultiplyStrategy else PairwiseTableStrategy), transform: (if gfni GfniStrategy else SimdStrategy), }, ] diff --git a/crates/field/src/arch/x86_64/packed_aes_256.rs b/crates/field/src/arch/x86_64/packed_aes_256.rs index f24973a83..e0195ca68 100644 --- a/crates/field/src/arch/x86_64/packed_aes_256.rs +++ b/crates/field/src/arch/x86_64/packed_aes_256.rs @@ -5,7 +5,7 @@ use cfg_if::cfg_if; use super::m256::M256; use crate::{ arch::portable::packed_macros::{portable_macros::*, *}, - arithmetic_traits::{impl_invert_with, impl_mul_alpha_with, impl_mul_with, impl_square_with}, + arithmetic_traits::{impl_invert_with, impl_mul_with, impl_square_with}, }; define_packed_binary_fields!( @@ -17,7 +17,6 @@ define_packed_binary_fields!( mul: (if gfni GfniStrategy else PairwiseTableStrategy), square: (if gfni ReuseMultiplyStrategy else PairwiseTableStrategy), invert: (if gfni GfniStrategy else PairwiseTableStrategy), - mul_alpha: (if gfni ReuseMultiplyStrategy else PairwiseTableStrategy), transform: (if gfni GfniStrategy else SimdStrategy), }, ] diff --git a/crates/field/src/arch/x86_64/packed_aes_512.rs b/crates/field/src/arch/x86_64/packed_aes_512.rs index 5f9ef182d..cf6344f0c 100644 --- a/crates/field/src/arch/x86_64/packed_aes_512.rs +++ b/crates/field/src/arch/x86_64/packed_aes_512.rs @@ -5,7 +5,7 @@ use cfg_if::cfg_if; use super::m512::M512; use crate::{ arch::portable::packed_macros::{portable_macros::*, *}, - arithmetic_traits::{impl_invert_with, impl_mul_alpha_with, impl_mul_with, impl_square_with}, + arithmetic_traits::{impl_invert_with, impl_mul_with, impl_square_with}, }; define_packed_binary_fields!( @@ -17,7 +17,6 @@ define_packed_binary_fields!( mul: (if gfni GfniStrategy else PairwiseTableStrategy), square: (if gfni ReuseMultiplyStrategy else PairwiseTableStrategy), invert: (if gfni GfniStrategy else PairwiseTableStrategy), - mul_alpha: (if gfni ReuseMultiplyStrategy else PairwiseTableStrategy), transform: (if gfni GfniStrategy else SimdStrategy), }, ] diff --git a/crates/field/src/arch/x86_64/packed_ghash_128.rs b/crates/field/src/arch/x86_64/packed_ghash_128.rs index 69c32e5a4..ddd0a22da 100644 --- a/crates/field/src/arch/x86_64/packed_ghash_128.rs +++ b/crates/field/src/arch/x86_64/packed_ghash_128.rs @@ -42,7 +42,6 @@ define_packed_binary_field!( (GhashStrategy), (GhashStrategy), (GhashStrategy), - (None), (None) ); diff --git a/crates/field/src/arch/x86_64/packed_ghash_256.rs b/crates/field/src/arch/x86_64/packed_ghash_256.rs index 9147a897a..10c92fe0c 100644 --- a/crates/field/src/arch/x86_64/packed_ghash_256.rs +++ b/crates/field/src/arch/x86_64/packed_ghash_256.rs @@ -51,7 +51,6 @@ define_packed_binary_field!( (Ghash256Strategy), (Ghash256Strategy), (Ghash256Strategy), - (None), (None) ); diff --git a/crates/field/src/arch/x86_64/packed_ghash_512.rs b/crates/field/src/arch/x86_64/packed_ghash_512.rs index e4728e8e1..91c277005 100644 --- a/crates/field/src/arch/x86_64/packed_ghash_512.rs +++ b/crates/field/src/arch/x86_64/packed_ghash_512.rs @@ -49,7 +49,6 @@ define_packed_binary_field!( (Ghash512Strategy), (Ghash512Strategy), (Ghash512Strategy), - (None), (None) ); diff --git a/crates/field/src/arch/x86_64/simd/simd_arithmetic.rs b/crates/field/src/arch/x86_64/simd/simd_arithmetic.rs index 52cc4b18f..6128be93e 100644 --- a/crates/field/src/arch/x86_64/simd/simd_arithmetic.rs +++ b/crates/field/src/arch/x86_64/simd/simd_arithmetic.rs @@ -2,13 +2,9 @@ use std::{any::TypeId, arch::x86_64::*}; -use crate::{ - BinaryField, TowerField, - aes_field::AESTowerField8b, - arch::portable::{packed::PackedPrimitiveType, reuse_multiply_arithmetic::Alpha}, - underlier::{UnderlierType, UnderlierWithBitOps}, -}; +use crate::{BinaryField, aes_field::AESTowerField8b, underlier::UnderlierWithBitOps}; +#[allow(dead_code)] pub trait TowerSimdType: Sized + Copy + UnderlierWithBitOps { /// Blend odd and even elements fn blend_odd_even(a: Self, b: Self) -> Self; @@ -116,12 +112,3 @@ pub trait TowerSimdType: Sized + Copy + UnderlierWithBitOps { Self::set1_epi128(mask_128) } } - -impl Alpha - for PackedPrimitiveType -{ - #[inline(always)] - fn alpha() -> Self { - U::alpha::().into() - } -} diff --git a/crates/field/src/arithmetic_traits.rs b/crates/field/src/arithmetic_traits.rs index 6eea98e54..e9537b274 100644 --- a/crates/field/src/arithmetic_traits.rs +++ b/crates/field/src/arithmetic_traits.rs @@ -12,12 +12,6 @@ pub trait InvertOrZero { fn invert_or_zero(self) -> Self; } -/// Value that can be multiplied by alpha -pub trait MulAlpha { - /// Multiply self by alpha - fn mul_alpha(self) -> Self; -} - /// Multiplication that is parameterized with some some strategy. pub trait TaggedMul { fn mul(self, rhs: Self) -> Self; @@ -101,29 +95,3 @@ macro_rules! impl_invert_with { } pub(crate) use impl_invert_with; - -/// Multiply by alpha operation that is parameterized with some some strategy. -pub trait TaggedMulAlpha { - fn mul_alpha(self) -> Self; -} - -macro_rules! impl_mul_alpha_with { - ($name:ident @ $strategy:ty) => { - impl $crate::arithmetic_traits::MulAlpha for $name { - #[inline] - fn mul_alpha(self) -> Self { - $crate::arithmetic_traits::TaggedMulAlpha::<$strategy>::mul_alpha(self) - } - } - }; - ($name:ty => $bigger:ty) => { - impl $crate::arithmetic_traits::MulAlpha for $name { - #[inline] - fn mul_alpha(self) -> Self { - $crate::arch::portable::packed::mul_alpha_as_bigger_type::<_, $bigger>(self) - } - } - }; -} - -pub(crate) use impl_mul_alpha_with; diff --git a/crates/field/src/binary_field.rs b/crates/field/src/binary_field.rs index 7fa3cad4d..44ed84c0c 100644 --- a/crates/field/src/binary_field.rs +++ b/crates/field/src/binary_field.rs @@ -56,25 +56,6 @@ pub trait TowerField: BinaryField { assert!(i < n_basis_elts, "index {i} out of range for {n_basis_elts} basis elements"); >::basis(i << iota) } - - /// Multiplies a field element by the canonical primitive element of the extension $T_{\iota + - /// 1} / T_{iota}$. - /// - /// We represent the tower field $T_{\iota + 1}$ as a vector space over $T_{\iota}$ with the - /// basis $\{1, \beta^{(\iota)}_1\}$. This operation multiplies the element by - /// $\beta^{(\iota)}_1$. - /// - /// # Preconditions - /// - /// * `iota` must be less than `TOWER_LEVEL`. - fn mul_primitive(self, iota: usize) -> Self { - assert!( - iota < Self::TOWER_LEVEL, - "iota {iota} must be less than tower level {}", - Self::TOWER_LEVEL - ); - self * >::basis(1 << iota) - } } /// Returns the i'th basis element of `FExt` as a field extension of `FSub`. @@ -93,15 +74,6 @@ where >::basis(i) } -pub(super) trait TowerExtensionField: - TowerField - + ExtensionField - + From<(Self::DirectSubfield, Self::DirectSubfield)> - + Into<(Self::DirectSubfield, Self::DirectSubfield)> -{ - type DirectSubfield: TowerField; -} - /// Macro to generate an implementation of a BinaryField. macro_rules! binary_field { ($vis:vis $name:ident($typ:ty), $gen:expr) => { diff --git a/crates/field/src/binary_field_arithmetic.rs b/crates/field/src/binary_field_arithmetic.rs index ebdf01354..5f571c946 100644 --- a/crates/field/src/binary_field_arithmetic.rs +++ b/crates/field/src/binary_field_arithmetic.rs @@ -1,13 +1,11 @@ // Copyright 2023-2025 Irreducible Inc. use super::{arithmetic_traits::InvertOrZero, binary_field::*}; -use crate::{PackedField, arithmetic_traits::MulAlpha}; +use crate::PackedField; pub(crate) trait TowerFieldArithmetic: TowerField { fn multiply(self, rhs: Self) -> Self; - fn multiply_alpha(self) -> Self; - fn square(self) -> Self; } @@ -34,15 +32,6 @@ macro_rules! impl_arithmetic_using_packed { ) } - #[inline] - fn multiply_alpha(self) -> Self { - use $crate::packed_extension::PackedSubfield; - - $crate::binary_field_arithmetic::mul_alpha_using_packed::>( - self, - ) - } - #[inline] fn square(self) -> Self { use $crate::packed_extension::PackedSubfield; @@ -62,11 +51,6 @@ impl TowerField for BinaryField1b { fn min_tower_level(self) -> usize { 0 } - - #[inline] - fn mul_primitive(self, iota: usize) -> Self { - panic!("mul_primitive called on BinaryField1b with iota={iota}, but tower level is 0"); - } } impl InvertOrZero for BinaryField1b { @@ -82,11 +66,6 @@ impl TowerFieldArithmetic for BinaryField1b { Self(self.0 & rhs.0) } - #[inline] - fn multiply_alpha(self) -> Self { - self - } - #[inline] fn square(self) -> Self { self @@ -109,8 +88,3 @@ pub(super) fn square_using_packed(value: P::Scalar) -> P::Scalar pub(super) fn invert_or_zero_using_packed(value: P::Scalar) -> P::Scalar { P::set_single(value).invert_or_zero().get(0) } - -#[inline] -pub(super) fn mul_alpha_using_packed(value: P::Scalar) -> P::Scalar { - P::set_single(value).mul_alpha().get(0) -} diff --git a/crates/field/src/field.rs b/crates/field/src/field.rs index c6b207dfe..cd5371217 100644 --- a/crates/field/src/field.rs +++ b/crates/field/src/field.rs @@ -83,36 +83,7 @@ pub trait Field: /// Exponentiates `self` by `exp`, where `exp` is a little-endian order integer /// exponent. - /// - /// # Guarantees - /// - /// This operation is constant time with respect to `self`, for all exponents with the - /// same number of digits (`exp.as_ref().len()`). It is variable time with respect to - /// the number of digits in the exponent. fn pow>(&self, exp: S) -> Self { - let mut res = Self::ONE; - for e in exp.as_ref().iter().rev() { - for i in (0..64).rev() { - res = res.square(); - let mut tmp = res; - tmp *= self; - if ((*e >> i) & 1) != 0 { - res = tmp; - } - } - } - res - } - - /// Exponentiates `self` by `exp`, where `exp` is a little-endian order integer - /// exponent. - /// - /// # Guarantees - /// - /// **This operation is variable time with respect to `self`, for all exponent.** If - /// the exponent is fixed, this operation is effectively constant time. However, for - /// stronger constant-time guarantees, [`Field::pow`] should be used. - fn pow_vartime>(&self, exp: S) -> Self { let mut res = Self::ONE; for e in exp.as_ref().iter().rev() { for i in (0..64).rev() { diff --git a/crates/field/src/ghash.rs b/crates/field/src/ghash.rs index 8c27ab639..68db85382 100644 --- a/crates/field/src/ghash.rs +++ b/crates/field/src/ghash.rs @@ -460,12 +460,6 @@ impl TowerField for BinaryField128bGhash { _ => 7, } } - - fn mul_primitive(self, _iota: usize) -> Self { - // This method could be implemented by multiplying by isomorphic alpha value - // But it's not being used as for now - unimplemented!() - } } impl From for BinaryField128bGhash {