4 releases
0.2.3 | Jan 2, 2024 |
---|---|
0.2.2 | Dec 23, 2023 |
0.2.1 | Dec 18, 2023 |
0.2.0 |
|
0.1.0 | Dec 16, 2023 |
#637 in Cryptography
39 downloads per month
3MB
809 lines
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
[dependencies]
sm9 = "0.2.3"
Examples
(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
));
License
Licensed under either of
at your option.
Copyright 2023 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.
Dependencies
~6.5MB
~41K SLoC