diff --git a/.github/workflows/ci.yml b/.github/workflows/ci.yml index dba55c0..20a016b 100644 --- a/.github/workflows/ci.yml +++ b/.github/workflows/ci.yml @@ -111,7 +111,7 @@ jobs: # Job 3: MSRV 验证(最低支持版本) # ============================================================================= msrv: - name: MSRV (1.72.0) + name: MSRV (1.83.0) needs: lint runs-on: ubuntu-latest steps: @@ -121,7 +121,7 @@ jobs: - name: 安装 MSRV 工具链 uses: dtolnay/rust-toolchain@master with: - toolchain: "1.72.0" + toolchain: "1.83.0" - name: 缓存 Cargo 编译产物 uses: Swatinem/rust-cache@v2 diff --git a/CHANGELOG.md b/CHANGELOG.md index 094d7da..9581e19 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -38,6 +38,10 @@ and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0 - SM2 sign: 258 µs, verify: 316 µs - SM9 sign: 3.44 ms, verify: 5.50 ms +### Changed + +- MSRV raised to 1.83.0 (required by crypto-bigint 0.6.x for ConstMontyForm constant-time Montgomery arithmetic) + ### Security - GCM `gf128_mul`: replaced secret-dependent `if` branches with mask arithmetic diff --git a/CHANGELOG.zh-CN.md b/CHANGELOG.zh-CN.md index 8b599c6..b27d4bf 100644 --- a/CHANGELOG.zh-CN.md +++ b/CHANGELOG.zh-CN.md @@ -38,6 +38,10 @@ - SM2 签名:258 µs,验签:316 µs - SM9 签名:3.44 ms,验签:5.50 ms +### 变更 + +- MSRV 提升至 1.83.0(crypto-bigint 0.6.x 的 ConstMontyForm 常量时间 Montgomery 算术所需) + ### 安全 - GCM `gf128_mul`:用掩码运算替换依赖秘密的 `if` 分支 diff --git a/Cargo.toml b/Cargo.toml index 62dbc78..3786604 100644 --- a/Cargo.toml +++ b/Cargo.toml @@ -2,12 +2,12 @@ name = "libsmx" version = "0.1.0" edition = "2021" -rust-version = "1.72.0" +rust-version = "1.83.0" license = "Apache-2.0" description = "Pure-Rust, no_std, constant-time SM2/SM3/SM4/SM9 Chinese cryptography (GB/T 32918/32905/32907/38635)" -repository = "https://github.com/aspect-building/libsmx" +repository = "https://github.com/kintaiW/libsmx" documentation = "https://docs.rs/libsmx" -homepage = "https://github.com/aspect-building/libsmx" +homepage = "https://github.com/kintaiW/libsmx" categories = ["cryptography", "no-std"] keywords = ["sm2", "sm3", "sm4", "sm9", "gmssl"] readme = "README.md" diff --git a/README.md b/README.md index e0c03f1..6d7e79d 100644 --- a/README.md +++ b/README.md @@ -5,7 +5,7 @@ [![docs.rs](https://img.shields.io/docsrs/libsmx)](https://docs.rs/libsmx) [![codecov](https://codecov.io/gh/kintaiW/libsmx/graph/badge.svg)](https://codecov.io/gh/kintaiW/libsmx) [![License](https://img.shields.io/crates/l/libsmx.svg)](LICENSE) -[![MSRV](https://img.shields.io/badge/MSRV-1.72.0-blue.svg)](https://blog.rust-lang.org/2023/08/24/Rust-1.72.0.html) +[![MSRV](https://img.shields.io/badge/MSRV-1.83.0-blue.svg)](https://blog.rust-lang.org/2024/11/28/Rust-1.83.0.html) Pure-Rust, `#![no_std]` implementation of Chinese commercial cryptography standards with constant-time operations throughout. @@ -211,7 +211,7 @@ cargo bench ## MSRV Policy -The minimum supported Rust version is **1.72.0**. MSRV bumps are treated as minor version changes. +The minimum supported Rust version is **1.83.0**. MSRV bumps are treated as minor version changes. ## License diff --git a/README.zh-CN.md b/README.zh-CN.md index b57570e..a1801f5 100644 --- a/README.zh-CN.md +++ b/README.zh-CN.md @@ -5,7 +5,7 @@ [![docs.rs](https://img.shields.io/docsrs/libsmx)](https://docs.rs/libsmx) [![codecov](https://codecov.io/gh/kintaiW/libsmx/graph/badge.svg)](https://codecov.io/gh/kintaiW/libsmx) [![License](https://img.shields.io/crates/l/libsmx.svg)](LICENSE) -[![MSRV](https://img.shields.io/badge/MSRV-1.72.0-blue.svg)](https://blog.rust-lang.org/2023/08/24/Rust-1.72.0.html) +[![MSRV](https://img.shields.io/badge/MSRV-1.83.0-blue.svg)](https://blog.rust-lang.org/2024/11/28/Rust-1.83.0.html) 纯 Rust、`#![no_std]` 实现的中国商用密码算法库,全程常量时间操作。 @@ -246,7 +246,7 @@ cargo bench ## 最低支持 Rust 版本(MSRV) -最低支持版本为 **Rust 1.72.0**。MSRV 提升视为次版本号变更。 +最低支持版本为 **Rust 1.83.0**。MSRV 提升视为次版本号变更。 ## 许可证 diff --git a/src/sm3/mod.rs b/src/sm3/mod.rs index 1974c3c..0c621c0 100644 --- a/src/sm3/mod.rs +++ b/src/sm3/mod.rs @@ -265,11 +265,22 @@ mod tests { // 辅助:从十六进制字符串构造 [u8; 32] fn hex_literal(s: &str) -> [u8; 32] { let mut out = [0u8; 32]; - let bytes: alloc::vec::Vec = (0..s.len()) - .step_by(2) - .map(|i| u8::from_str_radix(&s[i..i + 2], 16).unwrap()) - .collect(); - out.copy_from_slice(&bytes); + let b = s.as_bytes(); + for i in 0..32 { + let hi = match b[i * 2] { + c @ b'0'..=b'9' => c - b'0', + c @ b'a'..=b'f' => c - b'a' + 10, + c @ b'A'..=b'F' => c - b'A' + 10, + _ => panic!("invalid hex"), + }; + let lo = match b[i * 2 + 1] { + c @ b'0'..=b'9' => c - b'0', + c @ b'a'..=b'f' => c - b'a' + 10, + c @ b'A'..=b'F' => c - b'A' + 10, + _ => panic!("invalid hex"), + }; + out[i] = hi << 4 | lo; + } out } } diff --git a/src/sm4/modes.rs b/src/sm4/modes.rs index 9bf1e97..9290a80 100644 --- a/src/sm4/modes.rs +++ b/src/sm4/modes.rs @@ -654,6 +654,7 @@ pub fn sm4_decrypt_xts( // ── 测试 ────────────────────────────────────────────────────────────────────── #[cfg(test)] +#[cfg(feature = "alloc")] mod tests { use super::*;