diff --git a/CHANGELOG.md b/CHANGELOG.md index 8f1fc29..ef106be 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -44,4 +44,4 @@ and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0 - XTS: reject non-16-byte-aligned input instead of silently truncating - SM9 `hash_to_range`: replaced variable-iteration `while` loop with constant-time conditional select -[0.1.0]: https://github.com/aspect-building/libsmx/releases/tag/v0.1.0 +[0.1.0]: https://github.com/kintaiW/libsmx/releases/tag/v0.1.0 diff --git a/CHANGELOG.zh-CN.md b/CHANGELOG.zh-CN.md new file mode 100644 index 0000000..5977075 --- /dev/null +++ b/CHANGELOG.zh-CN.md @@ -0,0 +1,47 @@ +# 变更日志 + +本文件记录项目的所有重要变更。 + +格式基于 [Keep a Changelog](https://keepachangelog.com/zh-CN/1.1.0/), +本项目遵循 [语义化版本](https://semver.org/lang/zh-CN/)。 + +## [0.1.0] - 2025-03-07 + +### 新增 + +- SM2 椭圆曲线密码 (GB/T 32918.1-5-2016) + - 密钥生成、数字签名(含 Z 值)、公钥加解密 + - 常量时间点运算的完整加法公式 + - 固定窗口 (w=4) 基点标量乘法及预计算表 + - 混合 Jacobian-Affine 加法优化验证(Shamir 技巧) + - 点压缩/解压(GB/T 32918.1 第 4.2.10 节) +- SM3 密码杂凑算法 (GB/T 32905-2016) + - 流式和一次性哈希 API + - HMAC-SM3,自动清零密钥材料 +- SM4 分组密码 (GB/T 32907-2016) + - 布尔电路 bitslice S-box(抗缓存时序攻击) + - 8 种工作模式:ECB、CBC、OFB、CFB、CTR、GCM、CCM、XTS + - GCM/CCM 认证加密,常量时间标签验证 +- SM9 标识密码 (GB/T 38635.1-2-2020) + - BN256 配对(最优 Ate,Miller 循环 + 最终幂) + - Fp12 塔式扩张:Fp -> Fp2(u²+2) -> Fp6(v³-u) -> Fp12(w²-v) + - 标识签名与验证 + - 标识加密与解密 +- 统一 `Error` 枚举,实现 `Display` 和条件 `std::error::Error` +- `no_std` 支持,可选 `alloc` 和 `std` 特性 +- 库级别强制 `#![forbid(unsafe_code)]` +- 通过 `zeroize::ZeroizeOnDrop` 自动清零私钥 +- 所有算法的 GB/T 标准测试向量 + +### 安全 + +- GCM `gf128_mul`:用掩码运算替换依赖秘密的 `if` 分支 +- SM2 `is_infinity`:用 `ConstantTimeEq` 替换短路 `Iterator::all` +- SM2 `add`:用完整加法公式 + `conditional_select` 替换 3 个条件分支 +- SM2 `double`:用 `conditional_select` 替换 `if is_infinity()` +- HMAC-SM3:为栈上的 `k_pad`/`ipad`/`opad` 密钥材料添加 `zeroize` +- CCM:拒绝 AAD > 510 字节,而非静默跳过 +- XTS:拒绝非 16 字节对齐输入,而非静默截断 +- SM9 `hash_to_range`:用常量时间条件选择替换可变迭代 `while` 循环 + +[0.1.0]: https://github.com/kintaiW/libsmx/releases/tag/v0.1.0 diff --git a/SECURITY.md b/SECURITY.md index 8f316b9..7d7ea46 100644 --- a/SECURITY.md +++ b/SECURITY.md @@ -21,7 +21,7 @@ If you discover a security vulnerability in libsmx, please report it responsibly **Response timeline**: -本项目由个人维护,响应时间不设固定期限。作者会尽快处理所有安全报告,但无法承诺具体的响应时间。 +This project is maintained by an individual. No fixed response time is guaranteed. The author will handle all security reports as soon as possible, but cannot commit to specific timelines. ## Scope diff --git a/SECURITY.zh-CN.md b/SECURITY.zh-CN.md new file mode 100644 index 0000000..8a91e6e --- /dev/null +++ b/SECURITY.zh-CN.md @@ -0,0 +1,54 @@ +# 安全策略 + +## 支持版本 + +| 版本 | 是否支持 | +|------|----------| +| 0.3.x | 是 | +| < 0.3 | 否 | + +## 报告漏洞 + +如果您发现 libsmx 存在安全漏洞,请负责任地报告: + +**邮箱**: [kintai@foxmail.com](mailto:kintai@foxmail.com) + +**请包含**: +- 漏洞描述 +- 复现步骤 +- 受影响版本 +- 潜在影响评估 + +**响应时间**: + +本项目由个人维护,不设固定响应时间。作者会尽快处理所有安全报告,但无法承诺具体的响应期限。 + +## 范围 + +以下领域属于安全报告的有效范围: + +- **时序侧信道**:执行时间依赖于秘密数据(私钥、明文、随机数)的操作 +- **内存安全**:缓冲区溢出、释放后使用或未初始化内存读取(注:本库使用 `#![forbid(unsafe_code)]`) +- **密钥材料泄露**:私钥或中间秘密值未正确清零 +- **密码学正确性**:偏离 GB/T 标准导致安全保证减弱 +- **认证绕过**:GCM/CCM 模式中 MAC/标签验证错误 + +## 不在范围内 + +- 不影响安全的性能问题 +- 依赖库漏洞(请向上游报告) +- 需要物理访问设备的攻击 + +## 安全设计 + +libsmx 采用以下防护措施: + +- **常量时间操作**:所有依赖秘密的代码使用 `subtle::ConstantTimeEq`、`ConditionallySelectable` 和固定迭代循环 +- **S-box 无表查找**:SM4 使用布尔电路 bitslice 实现,防止缓存时序攻击 +- **自动密钥清零**:所有私钥类型派生 `ZeroizeOnDrop` +- **无 unsafe 代码**:库级别强制 `#![forbid(unsafe_code)]` +- **完整 EC 公式**:SM2 点加法使用无分支完整加法公式(Renes-Costello-Batina 2016) + +## 披露策略 + +我们遵循协调披露原则。请**不要**为安全漏洞创建公开的 GitHub issue。