Skip to main content

Crate libsmx

Crate libsmx 

Source
Expand description

§libsmx

Production-grade implementation of Chinese commercial cryptography standards:

  • SM2 — Elliptic Curve Public Key Cryptography (GB/T 32918.1-5)
  • SM3 — Cryptographic Hash Algorithm (GB/T 32905)
  • SM4 — Block Cipher Algorithm (GB/T 32907)
  • SM9 — Identity-Based Cryptographic Algorithm (GB/T 38635.1-2)

§Features

  • no_std compatible (requires alloc feature for SM2/SM9 operations)
  • Constant-time operations via subtle
  • Automatic key zeroization via zeroize
  • All implementations validated against official GB/T test vectors

§Quick Start

use libsmx::sm3::Sm3Hasher;

let mut h = Sm3Hasher::new();
h.update(b"hello world");
let digest = h.finalize();
assert_eq!(digest.len(), 32);

§Security Notice

This library uses constant-time operations throughout to prevent timing side-channel attacks. Private keys are zeroized on drop. However, this library has not been independently audited. Use in production at your own risk.

§Standards Compliance

AlgorithmStandard
SM2GB/T 32918.1-5-2016
SM3GB/T 32905-2016
SM4GB/T 32907-2016
SM9GB/T 38635.1-2-2020

Modules§

bls
BLS 签名方案(基于 SM9 BN256 配对)
error
统一错误类型
fpe
FPE(Format-Preserving Encryption)保留格式加密
sm2
SM2 椭圆曲线公钥密码算法(GB/T 32918.1-5-2016)
sm3
SM3 密码杂凑算法(GB/T 32905-2016)
sm4
SM4 分组密码(GB/T 32907-2016) 实现见各子模块。
sm9
SM9 标识密码算法(GB/T 38635.1-2-2020)