mirror of
https://github.com/Sunscreen-tech/Sunscreen.git
synced 2026-01-14 16:17:56 -05:00
29 lines
878 B
Rust
29 lines
878 B
Rust
use sunscreen::{types::bfv::Signed, types::Cipher, *};
|
|
|
|
#[test]
|
|
fn can_encrypt_decrypt() {
|
|
#[fhe_program(scheme = "bfv")]
|
|
fn foo(a: Cipher<Signed>, b: Cipher<Signed>) -> Cipher<Signed> {
|
|
a + b
|
|
}
|
|
|
|
let fhe_program = Compiler::with_fhe_program(foo)
|
|
.additional_noise_budget(5)
|
|
.plain_modulus_constraint(PlainModulusConstraint::Raw(500))
|
|
.compile()
|
|
.unwrap();
|
|
|
|
let runtime = Runtime::new(&fhe_program.metadata.params).unwrap();
|
|
|
|
let (public_key, private_key) = runtime.generate_keys().unwrap();
|
|
|
|
let a = runtime.encrypt(Signed::from(15), &public_key).unwrap();
|
|
let b = runtime.encrypt(Signed::from(5), &public_key).unwrap();
|
|
|
|
let result = runtime.run(&fhe_program, vec![a, b], &public_key).unwrap();
|
|
|
|
let c: Signed = runtime.decrypt(&result[0], &private_key).unwrap();
|
|
|
|
assert_eq!(c, 20.into());
|
|
}
|