修复 no_std 测试并升级 MSRV 至 1.83.0

- 修复 cargo test --no-default-features --lib 编译错误
  - SM3 测试:移除 alloc 依赖,改用手动十六进制解析
  - SM4 modes 测试:添加 #[cfg(feature = "alloc")]
- MSRV 升级至 1.83.0(crypto-bigint 0.6.x 的 ConstMontyForm 所需)
- 更新 CI 工作流中的 MSRV 版本
- 修正 Cargo.toml 仓库链接
This commit is contained in:
huangxt
2026-03-07 20:38:34 +08:00
parent a7eaf413d9
commit f369ae61de
8 changed files with 34 additions and 14 deletions
+2 -2
View File
@@ -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
+4
View File
@@ -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
+4
View File
@@ -38,6 +38,10 @@
- SM2 签名:258 µs,验签:316 µs
- SM9 签名:3.44 ms,验签:5.50 ms
### 变更
- MSRV 提升至 1.83.0crypto-bigint 0.6.x 的 ConstMontyForm 常量时间 Montgomery 算术所需)
### 安全
- GCM `gf128_mul`:用掩码运算替换依赖秘密的 `if` 分支
+3 -3
View File
@@ -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"
+2 -2
View File
@@ -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
+2 -2
View File
@@ -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 提升视为次版本号变更。
## 许可证
+16 -5
View File
@@ -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<u8> = (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
}
}
+1
View File
@@ -654,6 +654,7 @@ pub fn sm4_decrypt_xts(
// ── 测试 ──────────────────────────────────────────────────────────────────────
#[cfg(test)]
#[cfg(feature = "alloc")]
mod tests {
use super::*;