mirror of
https://github.com/Sunscreen-tech/Sunscreen.git
synced 2026-01-14 16:17:56 -05:00
62 lines
1.6 KiB
Rust
62 lines
1.6 KiB
Rust
use sunscreen::{
|
|
types::{bfv::Signed, Cipher},
|
|
Compiler,
|
|
};
|
|
use sunscreen_compiler_macros::fhe_program;
|
|
use sunscreen_runtime::{FheProgramInput, Runtime};
|
|
|
|
#[cfg(not(feature = "transparent-ciphertexts"))]
|
|
mod transparent_ciphertexts {
|
|
use super::*;
|
|
|
|
#[test]
|
|
#[should_panic]
|
|
fn panics_on_transparent_ciphertext() {
|
|
#[fhe_program(scheme = "bfv")]
|
|
fn add(a: Cipher<Signed>, b: Signed) -> Cipher<Signed> {
|
|
a * b
|
|
}
|
|
|
|
let app = Compiler::new().fhe_program(add).compile().unwrap();
|
|
|
|
let runtime = Runtime::new_fhe(app.params()).unwrap();
|
|
|
|
let (public, _) = runtime.generate_keys().unwrap();
|
|
|
|
let a = runtime.encrypt(Signed::from(42), &public).unwrap();
|
|
|
|
let args: Vec<FheProgramInput> = vec![a.into(), Signed::from(0).into()];
|
|
|
|
runtime
|
|
.run(app.get_fhe_program(add).unwrap(), args, &public)
|
|
.unwrap();
|
|
}
|
|
}
|
|
|
|
#[cfg(feature = "transparent-ciphertexts")]
|
|
mod transparent_ciphertexts {
|
|
use super::*;
|
|
|
|
#[test]
|
|
fn no_panic_on_transparent_ciphertext() {
|
|
#[fhe_program(scheme = "bfv")]
|
|
fn add(a: Cipher<Signed>, b: Signed) -> Cipher<Signed> {
|
|
a * b
|
|
}
|
|
|
|
let app = Compiler::new().fhe_program(add).compile().unwrap();
|
|
|
|
let runtime = Runtime::new_fhe(app.params()).unwrap();
|
|
|
|
let (public, _) = runtime.generate_keys().unwrap();
|
|
|
|
let a = runtime.encrypt(Signed::from(42), &public).unwrap();
|
|
|
|
let args: Vec<FheProgramInput> = vec![a.into(), Signed::from(0).into()];
|
|
|
|
runtime
|
|
.run(app.get_fhe_program(add).unwrap(), args, &public)
|
|
.unwrap();
|
|
}
|
|
}
|