From a6f3c239012e1c5b35459c1e555c744f2f975059 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=E5=88=98=E8=88=AA=E5=AE=87?= <3364451258@qq.com> Date: Tue, 16 Jun 2026 23:35:19 +0800 Subject: [PATCH] =?UTF-8?q?fix:=20galois=20=E2=80=94=20=E6=B7=BB=E5=8A=A0?= =?UTF-8?q?=20#[inline]=20=E5=92=8C=20div=5Fby=5Fzero=20=E6=B5=8B=E8=AF=95?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- core/src/ecc/galois.rs | 9 +++++++++ 1 file changed, 9 insertions(+) diff --git a/core/src/ecc/galois.rs b/core/src/ecc/galois.rs index 0130542..9af2121 100644 --- a/core/src/ecc/galois.rs +++ b/core/src/ecc/galois.rs @@ -56,6 +56,7 @@ pub fn sub(a: u8, b: u8) -> u8 { } /// GF(2⁸) 乘法:a * b +#[inline] pub fn mul(a: u8, b: u8) -> u8 { if a == 0 || b == 0 { return 0; @@ -66,6 +67,7 @@ pub fn mul(a: u8, b: u8) -> u8 { } /// GF(2⁸) 除法:a / b +#[inline] pub fn div(a: u8, b: u8) -> u8 { if a == 0 { return 0; @@ -80,6 +82,7 @@ pub fn div(a: u8, b: u8) -> u8 { } /// GF(2⁸) 幂运算:base^exp +#[inline] pub fn pow(base: u8, exp: usize) -> u8 { if exp == 0 { return 1; @@ -154,6 +157,12 @@ mod tests { } } + #[test] + #[should_panic(expected = "除以零")] + fn test_div_by_zero_panics() { + div(1, 0); + } + #[test] fn test_pow() { // α^0 = 1