Expand description
§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(())
}
Modules§
- component_
marker - Marker traits to signify what types of enryptions are supported
Macros§
- try_
seal - A macro that receives a c_long error code and returns a
Result
error. If the c_long corresponds to E_OK, it returnsOk(())
, otherwise it returnsErr(Error::from(err))
.
Structs§
- Asym
- Asymmetric encryptions marker
- Asymmetric
Components - The components to an asymmetric encryption.
- BFVEncoder
- Provides functionality for CRT batching. If the polynomial modulus degree is N, and the plaintext modulus is a prime number T such that T is congruent to 1 modulo 2N, then BatchEncoder allows the plaintext elements to be viewed as 2-by-(N/2) matrices of integers modulo T. Homomorphic operations performed on such encrypted matrices are applied coefficient (slot) wise, enabling powerful Batched functionality for computations that are vectorizable. This functionality is often called “batching” in the homomorphic encryption literature.
- BFVEncryption
Parameters Builder - Represents a builder that sets up and creates encryption scheme parameters. The parameters (most importantly PolyModulus, CoeffModulus, PlainModulus) significantly affect the performance, capabilities, and security of the encryption scheme.
- BFVEvaluator
- An evaluator that contains additional operations specific to the BFV scheme.
- CKKS
Encoder - To create CKKS plaintexts we need a special encoder: there is no other way to create them. The BatchEncoder cannot be used with the CKKS scheme. The CKKSEncoder encodes vectors of real or complex numbers into Plaintext objects, which can subsequently be encrypted. At a high level this looks a lot like what BatchEncoder does for the BFV scheme, but the theory behind it is completely different.
- CKKS
Encryption Parameters Builder - Represents a builder that sets up and creates encryption scheme parameters. The parameters (most importantly PolyModulus, CoeffModulus) significantly affect the performance, capabilities, and security of the encryption scheme.
- CKKS
Evaluator - An evaluator that contains additional operations specific to the CKKS scheme.
- Ciphertext
- Class to store a ciphertext element. The data for a ciphertext consists of two or more polynomials, which are in Microsoft SEAL stored in a CRT form with respect to the factors of the coefficient modulus. This data itself is not meant to be modified directly by the user, but is instead operated on by functions in the Evaluator class. The size of the backing array of a ciphertext depends on the encryption parameters and the size of the ciphertext (at least 2). If the PolyModulusDegree encryption parameter is N, and the number of primes in the CoeffModulus encryption parameter is K, then the ciphertext backing array requires precisely 8NK*size bytes of memory. A ciphertext also carries with it the parmsId of its associated encryption parameters, which is used to check the validity of the ciphertext for homomorphic operations and decryption.
- Coefficient
Modulus Factory - This struct contains static methods for creating a coefficient modulus easily. Note that while these functions take a SecLevelType argument, all security guarantees are lost if the output is used with encryption parameters with a mismatching value for the PolyModulusDegree.
- Context
- Performs sanity checks (validation) and pre-computations for a given set of encryption parameters. While the EncryptionParameters class is intended to be a light-weight class to store the encryption parameters, the SEALContext class is a heavy-weight class that is constructed from a given set of encryption parameters. It validates the parameters for correctness, evaluates their properties, and performs and stores the results of several costly pre-computations.
- Decryptor
- Decrypts Ciphertext objects into Plaintext objects. Constructing a Decryptor requires a SEALContext with valid encryption parameters, and the secret key. The Decryptor is also used to compute the invariant noise budget in a given ciphertext.
- Encryption
Parameters - An immutable collection of parameters that defines an encryption scheme. Use either the CKKSBuilder or BFVBuilder to create one of these. Once created, these objects are effectively immutable.
- Encryptor
- Encrypts Plaintext objects into Ciphertext objects.
- Galois
Key - Class to store Galois keys.
- KeyGenerator
- Generates matching secret key and public key. An existing KeyGenerator can also at any time be used to generate relinearization keys and Galois keys. Constructing a KeyGenerator requires only a SEALContext.
- Memory
Pool - Memory pool handle for SEAL.
- Modulus
- Represent an integer modulus of up to 61 bits. An instance of the Modulus struct represents a non-negative integer modulus up to 61 bits. In particular, the encryption parameter PlainModulus, and the primes in CoeffModulus, are represented by instances of Modulus. The purpose of this class is to perform and store the pre-computation required by Barrett reduction.
- Plain
Modulus Factory - Similar to
CoefficientModulusFactory
, this struct contains static methods for buildingModulus
instances. In this case, the modulus is used as the plaintext modulus used in some FHE schemes. - Plaintext
- Class to store a plaintext encoded items. The data encoded for the plaintext is a polynomial with coefficients modulo the plaintext modulus. The degree of the plaintext polynomial must be one less than the degree of the polynomial modulus. The backing array always allocates one 64-bit word per each coefficient of the polynomial.
- Polynomial
Array - A SEAL array storing a number of polynomials. In particular, type implements methods that can convert from other types (like public keys) and converts them into the same non-NTT RNS format. Enables conversion of RNS format to multiprecision and back losslessly.
- Public
Key - Class to store a public key.
- Relinearization
Key - Class to store relinearization keys.
- Secret
Key - Class to store a secret key.
- Sym
- Symmetric encryptions marker
- SymAsym
- Both symmetric and asymmetric encryptions marker
- Symmetric
Components - The components to a symmetric encryption.
- Tensor
- Struct to store a tensor of elements of the same type.
- Tensor
Decryptor - Decrypts batches of ciphertexts.
- Tensor
Encoder - An encoder that encodes data in tensors.
- Tensor
Encryptor - Encryptor that can encrypt multiple messages at once.
- Tensor
Evaluator - An evaluator that evaluates a tensor of data.
Enums§
- Coefficient
Modulus Type - The coefficient modulus is a list of distinct
Modulus
instances. - Degree
Type - The available degree sizes for the polynomial modulus.
- Error
- A type representing all errors that can occur in SEAL.
- Plain
Modulus Type - The plain modulus is either a constant or a
Modulus
instance. - Scheme
Type - The FHE scheme supported by SEAL.
- Security
Level - Represents a standard security level according to the HomomorphicEncryption.org security standard. The value SecLevelType.None signals that no standard security level should be imposed. The value SecLevelType.TC128 provides a very high level of security and is the default security level enforced by Microsoft SEAL when constructing a SEALContext object. Normal users should not have to specify the security level explicitly anywhere.
Traits§
- Evaluator
- An interface for an evaluator.
- From
Bytes - A trait for converting data from a byte slice under a given SEAL context.
- From
Chunk - A trait for converting data from a byte slice under a given SEAL context.
- ToBytes
- A trait for converting objects into byte arrays.
- ToChunk
- A trait for converting chunk of objects into a list of byte arrays.
Type Aliases§
- Asymmetric
Encryptor - An encryptor capable of asymmetric encryptions.
- Result
- The result type for SEAL operations.
- Symmetric
Encryptor - An encryptor capable of symmetric encryptions.