SM9
Pure Rust implementation of the SM9 identity-based cryptographic algorithms as defined in the Chinese national standard GM/T 0044-2016 as well as ISO/IEC 11770.
Usage
Add the sm9 crate to your dependencies in Cargo.toml
[]
= "0.4.0"
Examples
Example1: Encrypt
(See encryption.rs for the full example.)
use *;
let usr_id = b"Bob";
let txt = b"Chinese IBE standard";
let m = encrypt;
println!;
let msg = decrypt.expect;
println!;
assert_eq!;
assert_eq!;
use fs;
let master_public_key =
read_to_string.expect;
let m = encrypt2;
println!;
let bob_private_key =
read_to_string.expect;
let msg = decrypt2.expect;
println!;
assert_eq!;
assert_eq!;
Example2: Signature
(See signature.rs for the full example.)
use *;
//Sign
let m = b"Chinese IBS standard";
let user_id = b"Alice";
let sig = sign;
println!;
println!;
//Verify
let mut bytes = Vec::new;
bytes.extend_from_slice;
bytes.extend_from_slice;
let sig_rev = from_slice.unwrap;
assert!;
use fs;
let master_signature_public_key = read_to_string
.expect;
let alice_signature_private_key = read_to_string
.expect;
let sig = sign2;
assert!;
Example3: Key Exchange
(See exchange.rs for the full example.)
use *;
let mpk = read_pem_file
.expect;
let alice_id = b"Alice";
let alice_key = read_pem_file
.expect;
let bob_id = b"Bob";
let bob_key = read_pem_file
.expect;
// the initiator A
let mut initiator = new.unwrap;
// the responder B
let mut responder = new.unwrap;
// A Step 3: compute 𝑅𝐴
let ra = initiator.generate_ephemeral_secret.unwrap;
// A Step 4: send 𝑅𝐴 to B
// B Step 3: compute 𝑅B
let rb = responder.generate_ephemeral_secret.unwrap;
// B Step 4: send 𝑅B to A
// A compute shared_secret use received rb
let rb_received = from_slice;
let ska = initiator.generate_shared_secret.unwrap;
// B compute shared_secret use received ra
let ra_received = from_slice;
let skb = responder.generate_shared_secret.unwrap;
assert_eq!;
// B Step 6: (optional) compute SB, and send it to A
let sb = responder.generate_comfirmable_secret.unwrap;
// A (optional) confirmation from B to A
let sb_received = from_slice;
let confirmation_a = initiator.comfirm.unwrap;
// A Step 8: (optional) compute 𝑆𝐴, and send it to B,
let sa = initiator.generate_comfirmable_secret.unwrap;
// B (optional) confirmation from A to B
let sa_received = from_slice;
let confirmation_b = responder.comfirm.unwrap;
assert!;
assert!;
License
Licensed under either of
at your option.
Copyright 2023 - 2025 John-Yu.
Authors
Contribution
Unless you explicitly state otherwise, any contribution intentionally submitted for inclusion in the work by you, as defined in the Apache-2.0 license, shall be dual licensed as above, without any additional terms or conditions.