3 unstable releases
0.2.0 | Oct 2, 2024 |
---|---|
0.1.1 | Jul 7, 2024 |
0.1.0 | Jun 29, 2024 |
#810 in Science
26 downloads per month
13MB
257K
SLoC
Contains (JAR file, 55KB) gradle-wrapper.jar, (obscure autoconf code, 1KB) configure.ac
seal
seal
is a Rust crate that wraps the Microsoft SEAL
library to enable us to perform arithimetic operations over encrypted data. It is a fork
of the Sunscreen's SEAL bindings that you can found here.
Architecture
All types in this crate implement Sync/Send. So long as you never dereference the internal handle on any type after it has been dropped, these traits should safely hold. The internal handles should be of little use to you anyways.
Schemes implemented:
- Brakerski/Fan-Vercauteren (BFV)
- Cheon-Kim-Kim-Song (CKKS)
lib.rs
:
Example
use sealy::{
BFVEncoder, BFVEvaluator, BfvEncryptionParametersBuilder, CoefficientModulus, Context,
Decryptor, DegreeType, Encoder, Encryptor, Evaluator, KeyGenerator, PlainModulus,
SecurityLevel,
};
fn main() -> anyhow::Result<()> {
let params = BfvEncryptionParametersBuilder::new()
.set_poly_modulus_degree(DegreeType::D8192)
.set_coefficient_modulus(
CoefficientModulus::create(DegreeType::D8192, &[50, 30, 30, 50, 50]).unwrap(),
)
.set_plain_modulus(PlainModulus::batching(DegreeType::D8192, 32)?)
.build()?;
let ctx = Context::new(¶ms, false, SecurityLevel::TC128)?;
let gen = KeyGenerator::new(&ctx)?;
let encoder = BFVEncoder::new(&ctx)?;
let public_key = gen.create_public_key();
let secret_key = gen.secret_key();
let encryptor = Encryptor::with_public_key(&ctx, &public_key)?;
let decryptor = Decryptor::new(&ctx, &secret_key)?;
let evaluator = BFVEvaluator::new(&ctx)?;
let plaintext: Vec<i64> = vec![1, 2, 3];
let factor = vec![2, 2, 2];
let encoded_plaintext = encoder.encode(&plaintext)?;
let encoded_factor = encoder.encode(&factor)?;
let ciphertext = encryptor.encrypt(&encoded_plaintext)?;
let ciphertext_result = evaluator.multiply_plain(&ciphertext, &encoded_factor)?;
let decrypted = decryptor.decrypt(&ciphertext_result)?;
let decoded = encoder.decode(&decrypted);
println!("{:?}", &decoded.into_iter().take(3).collect::<Vec<_>>()); // [2, 4, 6]
Ok(())
}