mind_sdk_fhe
is a Fully Homomorphic Encryption (FHE) Utility SDK written in Native Rust by Mind Network.
- π Rust Native β Safe memory management and high performance.
- π Fully Homomorphic Encryption (FHE) Support β Enables computation over encrypted data.
- π Multi-Type Support β Operations over int, shortint, and general data types.
TFHE-rs-v1.0.0 marks the first official stable release, see more details here.
Rustc-v1.84.0 is required to compile TFHE-rs v1.0.0. You can upgrade rustc like rustup update stable
.
[dependencies]
mind_sdk_fhe = "*
cargo run
pub fn test_new_in_memory() {
println!("\n== function: {} ==", function_name!());
let mut ts = mind_sdk_fhe::util::TimeDuration::new();
let mut tm = mind_sdk_fhe::util::TimeMessage::new();
ts.reset();
let mut fhe_general = mind_sdk_fhe::FheGeneral::default();
fhe_general.new_in_memory();
tm.insert("fhe_general gen", ts.duration());
let fhe = mind_sdk_fhe::FheInt::from(fhe_general);
tm.insert("fhe_int gen", ts.duration());
let x = 2;
let x_ct: tfhe::integer::RadixCiphertext = fhe.encrypt_by_public_key::<u8>(x);
tm.insert("encrypt_by_public_key", ts.duration_and_reset());
let z_ct = fhe
.compute_key
.as_ref()
.unwrap()
.checked_add(&x_ct, &x_ct)
.unwrap();
tm.insert("checked_add", ts.duration_and_reset());
let z_pt: u8 = fhe.decrypt_by_private_key::<u8>(&z_ct);
tm.insert("decrypt", ts.duration_and_reset());
println!(
"pt: {:?}, ct: {:?}, match: {}, bin: {:#066b}",
x + x,
&z_pt,
(x + x) == (z_pt),
&z_pt
);
tm.pprint();
}
pub fn test_new_in_memory() {
println!("\n== function: {} ==", function_name!());
let mut ts = mind_sdk_fhe::util::TimeDuration::new();
let mut tm = mind_sdk_fhe::util::TimeMessage::new();
ts.reset();
let mut fhe = mind_sdk_fhe::FheGeneral::default();
fhe.new_in_memory();
tm.insert("fhepk_load", ts.duration());
let x = 2;
let x_ct: tfhe::FheUint8 = fhe.encrypt_by_public_key::<u8, tfhe::FheUint8>(x);
tm.insert("encrypt_by_public_key", ts.duration_and_reset());
tfhe::set_server_key(fhe.compute_key.clone().unwrap());
tm.insert("set_server_key", ts.duration_and_reset());
let z_ct = &x_ct + &x_ct;
tm.insert("+", ts.duration_and_reset());
let z_pt: u8 = fhe.decrypt_by_private_key::<tfhe::FheUint8, u8>(&z_ct);
tm.insert("decrypt", ts.duration_and_reset());
println!(
"pt: {:?}, ct: {:?}, match: {}, bin: {:#066b}",
x + x,
&z_pt,
(x + x) == (z_pt),
&z_pt
);
tm.pprint();
}
pub fn test_new_in_memory() {
println!("\n== function: {} ==", function_name!());
let mut ts = mind_sdk_fhe::util::TimeDuration::new();
let mut tm = mind_sdk_fhe::util::TimeMessage::new();
ts.reset();
let mut fhe_general = mind_sdk_fhe::FheGeneral::default();
fhe_general.new_in_memory();
tm.insert("fhe_general gen", ts.duration());
let fhe_int = mind_sdk_fhe::FheInt::from(fhe_general);
tm.insert("fhe_int gen", ts.duration());
let fhe = mind_sdk_fhe::FheShortint::from(fhe_int);
tm.insert("fhe_int gen", ts.duration());
let x = 1;
let x_ct: tfhe::shortint::Ciphertext = fhe.encrypt_by_public_key(x);
tm.insert("encrypt_by_public_key", ts.duration_and_reset());
let z_ct = fhe
.compute_key
.as_ref()
.unwrap()
.checked_add(&x_ct, &x_ct)
.unwrap();
tm.insert("checked_add", ts.duration_and_reset());
let z_pt: u64 = fhe.decrypt_by_private_key(&z_ct);
tm.insert("decrypt", ts.duration_and_reset());
println!(
"pt: {:?}, ct: {:?}, match: {}, bin: {:#066b}",
x + x,
&z_pt,
(x + x) == (z_pt),
&z_pt
);
tm.pprint();
}
This project is licensed under the MIT License.
For questions or support, please contact Mind Network Official Channels.