发布 v0.3.0:rustls CryptoProvider 支持
新增功能: - rustls CryptoProvider:完整 rustls 0.23.x 支持 - SM3 Hash/Context trait 实现 - SM3 HMAC trait 实现 - SM4-GCM/CCM AEAD 密码套件 - SM2 ECDHE 密钥交换 - SM2 签名/验签算法 - SM3 流式 HMAC(HmacSm3) - SM2 SPKI DER 编码 - SM2 DEFAULT_ID 常量 文档更新: - README 依赖版本更新为 0.3 - CHANGELOG 添加 v0.3.0 变更记录 - SECURITY 更新版本支持表
This commit is contained in:
@@ -0,0 +1,51 @@
|
||||
//! SM3 → rustls `crypto::hash::Hash` / `crypto::hash::Context`
|
||||
|
||||
use alloc::boxed::Box;
|
||||
|
||||
use rustls::crypto::{self, HashAlgorithm};
|
||||
|
||||
use crate::sm3::Sm3Hasher;
|
||||
|
||||
/// 静态 SM3 哈希实现
|
||||
pub(crate) static SM3: Sm3Hash = Sm3Hash;
|
||||
|
||||
pub(crate) struct Sm3Hash;
|
||||
|
||||
impl crypto::hash::Hash for Sm3Hash {
|
||||
fn start(&self) -> Box<dyn crypto::hash::Context> {
|
||||
Box::new(Sm3Context(Sm3Hasher::new()))
|
||||
}
|
||||
|
||||
fn hash(&self, data: &[u8]) -> crypto::hash::Output {
|
||||
crypto::hash::Output::new(&Sm3Hasher::digest(data))
|
||||
}
|
||||
|
||||
fn output_len(&self) -> usize {
|
||||
32
|
||||
}
|
||||
|
||||
fn algorithm(&self) -> HashAlgorithm {
|
||||
// Reason: SM3 尚无 IANA TLS HashAlgorithm 标准编号,暂用 Unknown(0x07)
|
||||
HashAlgorithm::Unknown(0x07)
|
||||
}
|
||||
}
|
||||
|
||||
struct Sm3Context(Sm3Hasher);
|
||||
|
||||
impl crypto::hash::Context for Sm3Context {
|
||||
fn fork_finish(&self) -> crypto::hash::Output {
|
||||
crypto::hash::Output::new(&self.0.clone().finalize())
|
||||
}
|
||||
|
||||
fn fork(&self) -> Box<dyn crypto::hash::Context> {
|
||||
Box::new(Sm3Context(self.0.clone()))
|
||||
}
|
||||
|
||||
fn finish(self: Box<Self>) -> crypto::hash::Output {
|
||||
crypto::hash::Output::new(&self.0.finalize())
|
||||
}
|
||||
|
||||
fn update(&mut self, data: &[u8]) {
|
||||
self.0.update(data);
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user