mirror of
https://github.com/Sunscreen-tech/Sunscreen.git
synced 2026-01-14 16:17:56 -05:00
32 lines
899 B
Rust
32 lines
899 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 app = Compiler::new()
|
|
.fhe_program(foo)
|
|
.additional_noise_budget(5)
|
|
.plain_modulus_constraint(PlainModulusConstraint::Raw(500))
|
|
.compile()
|
|
.unwrap();
|
|
|
|
let runtime = Runtime::new(app.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(app.get_program(foo).unwrap(), vec![a, b], &public_key)
|
|
.unwrap();
|
|
|
|
let c: Signed = runtime.decrypt(&result[0], &private_key).unwrap();
|
|
|
|
assert_eq!(c, 20.into());
|
|
}
|