-
Notifications
You must be signed in to change notification settings - Fork 34
Expand file tree
/
Copy pathpacked_aes_128.rs
More file actions
62 lines (49 loc) · 1.41 KB
/
packed_aes_128.rs
File metadata and controls
62 lines (49 loc) · 1.41 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
// Copyright 2024-2025 Irreducible Inc.
// Copyright 2026 The Binius Developers
use std::ops::Mul;
use super::{
m128::M128,
simd_arithmetic::{
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, Square},
underlier::WithUnderlier,
};
pub type PackedAESBinaryField16x8b = PackedPrimitiveType<M128, AESTowerField8b>;
impl Mul for PackedAESBinaryField16x8b {
type Output = Self;
fn mul(self, rhs: Self) -> Self {
crate::tracing::trace_multiplication!(PackedAESBinaryField16x8b);
self.mutate_underlier(|underlier| packed_aes_16x8b_multiply(underlier, rhs.to_underlier()))
}
}
impl Square for PackedAESBinaryField16x8b {
fn square(self) -> Self {
self.mutate_underlier(packed_aes_16x8b_square)
}
}
impl InvertOrZero for PackedAESBinaryField16x8b {
fn invert_or_zero(self) -> Self {
self.mutate_underlier(packed_aes_16x8b_invert_or_zero)
}
}
#[cfg(test)]
mod tests {
use proptest::prelude::*;
use super::*;
use crate::packed::PackedField;
proptest! {
#[test]
fn test_square_equals_self_mul_self(a_val in any::<u128>()) {
let a = PackedAESBinaryField16x8b::from_underlier(a_val.into());
let squared = Square::square(a);
for i in 0..PackedAESBinaryField16x8b::WIDTH {
assert_eq!(squared.get(i), a.get(i) * a.get(i));
}
}
}
}