API
#crypto/sm9
Xu 0.8.8 API
import: #crypto/sm9
counts: 12 fns, 6 methods, 2 types, 6 consts, 0 ifaces
SM9 identity-based sign/encrypt/exchange. Pure Xu, not commercial-crypto certified.
const g1_size
Purpose
SM9 (GM/T 0044). Xu addition — has no crypto/sm9. Identifier signature hid=0x01 and KDF stream encryption hid=0x03. points 04||x||y (65). 04||x.u||x.y||y.u||y.y (129). Signature h||S (32+65). Ciphertext 04||C1||C3||C2 (C3=SM3). Key exchange hid=0x02 (GM/T 0044.4). H1/H2 take 40-byte Ha then (a mod (n-1))+1. Zero C, not a commercial-crypto certification. No ASN.1, not wired into GMTLS. XU-CT-CLASS: variable-time XU-CT-USE: fixed-shape-only math/big pairing/scalar arithmetic is variable-time; crypto/subtle covers only final fixed-shape integrity/equality checks. Value `65`.
Parameters
none
const g2_size
Purpose
Public constant `g2_size`. Value `129`.
Parameters
none
const signature_size
pub const signature_size = 97
Purpose
Public constant `signature_size`. Value `97`.
Parameters
none
const hid_sign
Purpose
Public constant `hid_sign`. Value `1`.
Parameters
none
const hid_enc
Purpose
Public constant `hid_enc`. Value `3`.
Parameters
none
const hid_exch
Purpose
Public constant `hid_exch`. Value `2`.
Parameters
none
sign_master_public
pub fn sign_master_public(ks &string) string
Purpose
Sign master public. Throws on failure.
Parameters
ks &string- ks (borrowed; caller keeps it; type &string)
Returns
string — result string
sign_user_key
pub fn sign_user_key(ks &string, id &string) string
Purpose
Sign user key. Throws on failure.
Parameters
ks &string- ks (borrowed; caller keeps it; type &string)
id &string- id (borrowed; caller keeps it; type &string)
Returns
string — result string
enc_master_public
pub fn enc_master_public(ke &string) string
Purpose
Enc master public. Throws on failure.
Parameters
ke &string- ke (borrowed; caller keeps it; type &string)
Returns
string — result string
enc_user_key
pub fn enc_user_key(ke &string, id &string) string
Purpose
Enc user key.
Parameters
ke &string- ke (borrowed; caller keeps it; type &string)
id &string- id (borrowed; caller keeps it; type &string)
Returns
string — result string
exch_user_key
pub fn exch_user_key(ke &string, id &string) string
Purpose
Exch user key.
Parameters
ke &string- ke (borrowed; caller keeps it; type &string)
id &string- id (borrowed; caller keeps it; type &string)
Returns
string — result string
sign_r
pub fn sign_r(dsa &string, mpk &string, msg &string, r &string) string
Purpose
Sign r. Throws on failure.
Parameters
dsa &string- dsa (borrowed; caller keeps it; type &string)
mpk &string- mpk (borrowed; caller keeps it; type &string)
msg &string- message (borrowed; caller keeps it; type &string)
r &string- rune (Unicode code point) (borrowed; caller keeps it; type &string)
Returns
string — result string
sign
pub fn sign(dsa &string, mpk &string, msg &string) string
Purpose
Sign. Throws on failure.
Parameters
dsa &string- dsa (borrowed; caller keeps it; type &string)
mpk &string- mpk (borrowed; caller keeps it; type &string)
msg &string- message (borrowed; caller keeps it; type &string)
Returns
string — result string
verify
pub fn verify(mpk &string, id &string, msg &string, sig &string) bool
Purpose
Verify.
Parameters
mpk &string- mpk (borrowed; caller keeps it; type &string)
id &string- id (borrowed; caller keeps it; type &string)
msg &string- message (borrowed; caller keeps it; type &string)
sig &string- sig (borrowed; caller keeps it; type &string)
Returns
bool — true or false
encrypt_r
pub fn encrypt_r(mpk &string, id &string, msg &string, r &string) string
Purpose
Encrypt r. Throws on failure.
Parameters
mpk &string- mpk (borrowed; caller keeps it; type &string)
id &string- id (borrowed; caller keeps it; type &string)
msg &string- message (borrowed; caller keeps it; type &string)
r &string- rune (Unicode code point) (borrowed; caller keeps it; type &string)
Returns
string — result string
encrypt
pub fn encrypt(mpk &string, id &string, msg &string) string
Purpose
Encrypt. Throws on failure.
Parameters
mpk &string- mpk (borrowed; caller keeps it; type &string)
id &string- id (borrowed; caller keeps it; type &string)
msg &string- message (borrowed; caller keeps it; type &string)
Returns
string — result string
decrypt
pub fn decrypt(d &string, id &string, ct &string) string
Purpose
Decrypt. Throws on failure.
Parameters
d &string- d (borrowed; caller keeps it; type &string)
id &string- id (borrowed; caller keeps it; type &string)
ct &string- ct (borrowed; caller keeps it; type &string)
Returns
string — result string
struct ExchCap
pub struct ExchCap {
pub point string
pub mac string
pub key string
}
Purpose
GM/T 0044.4 identifier key exchange. hid=0x02. Initiator: exch_new → init_r → confirm_responder. Responder: exch_new → respond_r → confirm_initiator. Optional SM3 MACs use prefixes 0x82 / 0x83. No ASN.1.
Parameters
point string- field (string)
mac string- field (string)
key string- key
struct Exch
Purpose
Public struct `Exch`.
Parameters
none
exch_new
pub fn exch_new(duk &string, mpk &string, uid &string, peer &string, klen int, gen_sig bool) Exch
Purpose
Exch new. Throws on failure.
Parameters
duk &string- duk (borrowed; caller keeps it; type &string)
mpk &string- mpk (borrowed; caller keeps it; type &string)
uid &string- uid (borrowed; caller keeps it; type &string)
peer &string- peer (borrowed; caller keeps it; type &string)
klen int- klen (int)
gen_sig bool- gen_sig (bool)
Returns
Exch — a value of this type
(&mut Exch) init_r
pub fn (e &mut Exch) init_r(r &string) string
Purpose
Method on `&mut Exch`: init r. Throws on failure.
Parameters
e &mut Exch- receiver &mut Exch (exclusive borrow)
r &string- rune (Unicode code point) (borrowed; caller keeps it; type &string)
Returns
string — result string
(&mut Exch) init
pub fn (e &mut Exch) init() string
Purpose
Call `init` on `&mut Exch`. Throws on failure.
Parameters
e &mut Exch- receiver &mut Exch (exclusive borrow)
Returns
string — result string
(&mut Exch) respond_r
pub fn (e &mut Exch) respond_r(r &string, ra &string) ExchCap
Purpose
Method on `&mut Exch`: respond r. Throws on failure.
Parameters
e &mut Exch- receiver &mut Exch (exclusive borrow)
r &string- rune (Unicode code point) (borrowed; caller keeps it; type &string)
ra &string- ra (borrowed; caller keeps it; type &string)
Returns
ExchCap — a value of this type
(&mut Exch) respond
pub fn (e &mut Exch) respond(ra &string) ExchCap
Purpose
Call `respond` on `&mut Exch`. Throws on failure.
Parameters
e &mut Exch- receiver &mut Exch (exclusive borrow)
ra &string- ra (borrowed; caller keeps it; type &string)
Returns
ExchCap — a value of this type
(&mut Exch) confirm_responder
pub fn (e &mut Exch) confirm_responder(rb &string, sb &string) ExchCap
Purpose
Method on `&mut Exch`: confirm responder. Throws on failure.
Parameters
e &mut Exch- receiver &mut Exch (exclusive borrow)
rb &string- rb (borrowed; caller keeps it; type &string)
sb &string- sb (borrowed; caller keeps it; type &string)
Returns
ExchCap — a value of this type
(&mut Exch) confirm_initiator
pub fn (e &mut Exch) confirm_initiator(sa &string) string
Purpose
Method on `&mut Exch`: confirm initiator. Throws on failure.
Parameters
e &mut Exch- receiver &mut Exch (exclusive borrow)
sa &string- sa (borrowed; caller keeps it; type &string)
Returns
string — result string