Expand description
Constant-time-designed pure-Rust SM2 / SM3 / SM4 primitives.
See the workspace README.md for scope, threat model, and the honest
framing of the in-CI dudect-based timing-leak regression harness.
§Modules
sm2— SM2 elliptic-curve sign / verify / encrypt / decrypt (GB/T 32918). Comb-table fixed-base scalar mult (v0.3 W6). The opt-insm2-key-exchangefeature (v1.1) addssm2::key_exchange— GM/T 0003.3 key agreement with key confirmation (Sm2KxInitiator/Sm2KxResponderrole state-machines).sm3— SM3 hash (GB/T 32905) with streamingnew/update/finalize.sm4— SM4 block cipher (GB/T 32907) + CBC and CTR modes (single-shot and streaming). The opt-insm4-aeadfeature adds SM4-GCM (single-shot + incremental-input buffered) and SM4-CCM; the opt-insm4-xtsfeature adds SM4-XTS (GB/T 17964-2021, single-shot + in-place multi-sector). v0.4 W3 adds an opt-in bitsliced (table-less, gate-only) S-box behind thesm4-bitslicedfeature.hmac— HMAC-SM3 (RFC 2104), single-shot + v0.3 W5 streaming.kdf— PBKDF2-HMAC-SM3 (RFC 8018 §5.2).asn1— strict-canonical DER reader / writer / OID constants (v0.3 W1); GM/T 0009 SM2 ciphertext SEQUENCE; RFC 3279 SM2 signature SEQUENCE.pem— RFC 7468 PEM codec (v0.3 W2; hand-rolled,no_std).spki— RFC 5280SubjectPublicKeyInfofor SM2 (v0.3 W2).sec1— RFC 5915ECPrivateKey+ SEC1 uncompressed point (v0.3 W2).pkcs8— RFC 5958OneAsymmetricKey+ RFC 8018 PBES2 (v0.3 W2).- [
traits] — in-crateHash/Mac/BlockCiphertraits (v0.3 W5). v0.4 W2 adds RustCrypto-trait fit (digest::Digest,digest::Mac,cipher::BlockCipherEncrypt/BlockCipherDecrypt) behind the opt-indigest-traits/cipher-traitsfeatures (migrated todigest 0.11/cipher 0.5in v0.11).
§Crate features
default—no_std,alloc-only. No optional dependencies.digest-traits— opt-in (v0.4 W2). Implementsdigest::Digestforsm3::Sm3anddigest::Macforhmac::HmacSm3. Pullsdigest = "0.11"— a pre-1.0 ecosystem crate, so a breakingdigestrelease is not covered bygmcrypto-core’sSemVer(bump your own).cipher-traits— opt-in (v0.4 W2). Implementscipher::{BlockCipherEncrypt, BlockCipherDecrypt, BlockSizeUser, KeySizeUser, KeyInit}forsm4::Sm4Cipher. Pullscipher = "0.5"— a pre-1.0 ecosystem crate, so a breakingcipherrelease is not covered bygmcrypto-core’sSemVer(bump your own).sm4-bitsliced— opt-in (v0.4 W3). Routes the SM4 S-box through a bitsliced (table-less, gate-only) Itoh-Tsujii inversion in GF(2^8). Byte-identical output to the default linear-scan path; constant-time by construction (no table lookups, no branches on secret bits).sm4-bitsliced-simd— opt-in (v0.5 W4 scaffolding; AVX2 / NEON intrinsic implementations land in v0.5.x). Impliessm4-bitsliced. Default-off.crypto-bigint-scalar— opt-in (v0.5 W5). Exposessm2::Sm2PrivateKey::from_scalarwhich takes acrypto_bigint::U256directly. Default-off; the always-onfrom_bytes_beconstructor is the recommended path for callers who don’t want a transitivecrypto-bigintdep.sm4-aead— opt-in (v0.8). SM4-GCM (sm4::mode_gcm, plus the v0.9 incremental-input bufferedsm4::gcm_streaming) and SM4-CCM (sm4::mode_ccm) authenticated encryption. Pulls the workspace-internalgmcrypto-simdfor the GHASH primitive (CLMUL / PMULL / constant-time software fallback).sm4-xts— opt-in (v0.12). SM4-XTS tweakable disk/sector mode (sm4::mode_xts; GB/T 17964-2021, bit-reflected α-doubling — not IEEE 1619), single-shot + the v0.15 in-place multi-sector helpers. Pure-core, no new dependency. Confidentiality only — XTS does not authenticate.sm2-key-exchange— opt-in (v1.1). GM/T 0003.3 ≡ GB/T 32918.3-2016 key agreement with mandatory key confirmation (sm2::key_exchange): consume-on-transition role state-machines, single-use ephemerals, commit-on-confirm key release,ZeroizeOnDropagreed key. Pure-core, no new dependency; byte-identical to the GM/T 0003.5 recommended-curve worked example. The C ABI projection ships ingmcrypto-c(v1.2).
§wasm32-unknown-unknown
Builds clean as of v0.4 W1. The crate is no_std + alloc only and
does NOT pull getrandom’s wasm_js backend or wasm-bindgen /
js-sys into its default dep graph. Wasm callers wire their own
rand_core::Rng impl — see the workspace README.md.
Modules§
- asn1
- Minimal ASN.1 DER subset.
- hmac
- HMAC-SM3 — RFC 2104 keyed MAC over GB/T 32905-2016 SM3.
- kdf
- Key derivation functions.
- pem
- Hand-rolled PEM (RFC 7468) codec.
- pkcs8
- PKCS#8
OneAsymmetricKeycodec (RFC 5958) + PBES2 encryption (RFC 8018). - sec1
- SEC1
ECPrivateKeycodec (RFC 5915) for SM2 keys. - sm2
- SM2 elliptic curve cryptography (GB/T 32918-2017).
- sm3
- SM3 hash function (GB/T 32905-2016).
- sm4
- SM4 block cipher (GB/T 32907-2016) and operating modes.
- spki
- X.509
SubjectPublicKeyInfocodec (RFC 5280 §4.1.2.7) for SM2 keys.
Enums§
- Error
- Workspace-wide failure type (v0.5 W5).