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.
Add the sm9
crate to your dependencies in Cargo.toml
[dependencies]
sm9 = "0.2.2"
(See encryption.rs
for the full example.)
use sm9::*;
let usr_id = b"Bob";
let txt = b"Chinese IBE standard";
let m = Sm9::encrypt("master_public_key.pem", usr_id, txt);
println!("{:02X?}", m);
let msg = Sm9::decrypt("bob_private_key.pem", usr_id, m).expect("decrypt error");
println!("{:02X?}", msg);
assert_eq!(msg.len(), txt.len());
assert_eq!(txt, msg.as_slice());
(See signature.rs
for the full example.)
use sm9::*;
let m = b"Chinese IBS standard";
let user_id = b"Alice";
let sig = Sm9::sign(
"master_signature_public_key.pem",
"alice_signature_private_key.pem",
m,
);
println!("{:02X?}", sig.h_as_ref());
println!("{:02X?}", sig.s_as_ref());
assert!(Sm9::verify(
"master_signature_public_key.pem",
user_id,
m,
&sig
));
Licensed under either of
at your option.
Copyright 2023 John-Yu.
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.