mind_sdk_fhe

Crates.iomind_sdk_fhe
lib.rsmind_sdk_fhe
version0.1.3
created_at2025-02-20 15:48:27.532008+00
updated_at2025-03-05 17:43:32.084228+00
descriptionMind Network Rust SDK
homepagehttps://github.com/mind-network
repositoryhttps://github.com/mind-network/mind-sdk-fhe-rust
max_upload_size
id1562746
size102,339
MindNetwork (mindadmin)

documentation

README

mind-sdk-fhe-rust

mind_sdk_fhe is a Fully Homomorphic Encryption (FHE) Utility SDK written in Native Rust by Mind Network.

mind_sdk_fhe on crates.io Documentation on docs.rs Licensed Github Github

Features

  • 🚀 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.

Quick Start

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.

Install

[dependencies]
mind_sdk_fhe = "*

Run

cargo run

FHE General Example

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();
}

FHE Integer Example

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();
}

FHE ShortInt Example

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();
}

License

This project is licensed under the MIT License.

Contact

For questions or support, please contact Mind Network Official Channels.

Commit count: 11

cargo fmt