binius_field/arch/portable/
packed_aes_128.rs

1// Copyright 2024-2025 Irreducible Inc.
2
3use super::{
4	packed::{impl_broadcast, PackedPrimitiveType},
5	packed_arithmetic::{alphas, impl_tower_constants},
6};
7use crate::{
8	aes_field::{
9		AESTowerField128b, AESTowerField16b, AESTowerField32b, AESTowerField64b, AESTowerField8b,
10	},
11	arch::{PackedStrategy, PairwiseRecursiveStrategy, PairwiseStrategy, PairwiseTableStrategy},
12	arithmetic_traits::{
13		impl_invert_with, impl_mul_alpha_with, impl_mul_with, impl_square_with,
14		impl_transformation_with_strategy,
15	},
16};
17
18// Define 128 bit packed AES field types
19pub type PackedAESBinaryField16x8b = PackedPrimitiveType<u128, AESTowerField8b>;
20pub type PackedAESBinaryField8x16b = PackedPrimitiveType<u128, AESTowerField16b>;
21pub type PackedAESBinaryField4x32b = PackedPrimitiveType<u128, AESTowerField32b>;
22pub type PackedAESBinaryField2x64b = PackedPrimitiveType<u128, AESTowerField64b>;
23pub type PackedAESBinaryField1x128b = PackedPrimitiveType<u128, AESTowerField128b>;
24
25// Define broadcast
26impl_broadcast!(u128, AESTowerField8b);
27impl_broadcast!(u128, AESTowerField16b);
28impl_broadcast!(u128, AESTowerField32b);
29impl_broadcast!(u128, AESTowerField64b);
30impl_broadcast!(u128, AESTowerField128b);
31
32// Define contants
33// 0xD3 corresponds to 0x10 after isomorphism from BinaryField8b to AESField
34impl_tower_constants!(AESTowerField8b, u128, 0x00d300d300d300d300d300d300d300d3);
35impl_tower_constants!(AESTowerField16b, u128, { alphas!(u128, 4) });
36impl_tower_constants!(AESTowerField32b, u128, { alphas!(u128, 5) });
37impl_tower_constants!(AESTowerField64b, u128, { alphas!(u128, 6) });
38
39// Define multiplication
40impl_mul_with!(PackedAESBinaryField16x8b @ PairwiseTableStrategy);
41impl_mul_with!(PackedAESBinaryField8x16b @ PairwiseRecursiveStrategy);
42impl_mul_with!(PackedAESBinaryField4x32b @ PairwiseRecursiveStrategy);
43impl_mul_with!(PackedAESBinaryField2x64b @ PairwiseRecursiveStrategy);
44impl_mul_with!(PackedAESBinaryField1x128b @ PairwiseRecursiveStrategy);
45
46// Define square
47impl_square_with!(PackedAESBinaryField16x8b @ PairwiseTableStrategy);
48impl_square_with!(PackedAESBinaryField8x16b @ PairwiseRecursiveStrategy);
49impl_square_with!(PackedAESBinaryField4x32b @ PackedStrategy);
50impl_square_with!(PackedAESBinaryField2x64b @ PackedStrategy);
51impl_square_with!(PackedAESBinaryField1x128b @ PairwiseRecursiveStrategy);
52
53// Define invert
54impl_invert_with!(PackedAESBinaryField16x8b @ PairwiseTableStrategy);
55impl_invert_with!(PackedAESBinaryField8x16b @ PairwiseRecursiveStrategy);
56impl_invert_with!(PackedAESBinaryField4x32b @ PairwiseRecursiveStrategy);
57impl_invert_with!(PackedAESBinaryField2x64b @ PairwiseRecursiveStrategy);
58impl_invert_with!(PackedAESBinaryField1x128b @ PairwiseRecursiveStrategy);
59
60// Define multiply by alpha
61impl_mul_alpha_with!(PackedAESBinaryField16x8b @ PairwiseTableStrategy);
62impl_mul_alpha_with!(PackedAESBinaryField8x16b @ PackedStrategy);
63impl_mul_alpha_with!(PackedAESBinaryField4x32b @ PackedStrategy);
64impl_mul_alpha_with!(PackedAESBinaryField2x64b @ PairwiseRecursiveStrategy);
65impl_mul_alpha_with!(PackedAESBinaryField1x128b @ PairwiseRecursiveStrategy);
66
67// Define linear transformations
68impl_transformation_with_strategy!(PackedAESBinaryField16x8b, PackedStrategy);
69impl_transformation_with_strategy!(PackedAESBinaryField8x16b, PackedStrategy);
70impl_transformation_with_strategy!(PackedAESBinaryField4x32b, PackedStrategy);
71impl_transformation_with_strategy!(PackedAESBinaryField2x64b, PairwiseStrategy);
72impl_transformation_with_strategy!(PackedAESBinaryField1x128b, PairwiseStrategy);