Crate sealy

Source
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(&params, 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 returns Ok(()), otherwise it returns Err(Error::from(err)).

Structs§

Asym
Asymmetric encryptions marker
AsymmetricComponents
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.
BFVEncryptionParametersBuilder
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.
CKKSEncoder
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.
CKKSEncryptionParametersBuilder
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.
CKKSEvaluator
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.
CoefficientModulusFactory
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.
EncryptionParameters
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.
GaloisKey
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.
MemoryPool
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.
PlainModulusFactory
Similar to CoefficientModulusFactory, this struct contains static methods for building Modulus 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.
PolynomialArray
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.
PublicKey
Class to store a public key.
RelinearizationKey
Class to store relinearization keys.
SecretKey
Class to store a secret key.
Sym
Symmetric encryptions marker
SymAsym
Both symmetric and asymmetric encryptions marker
SymmetricComponents
The components to a symmetric encryption.
Tensor
Struct to store a tensor of elements of the same type.
TensorDecryptor
Decrypts batches of ciphertexts.
TensorEncoder
An encoder that encodes data in tensors.
TensorEncryptor
Encryptor that can encrypt multiple messages at once.
TensorEvaluator
An evaluator that evaluates a tensor of data.

Enums§

CoefficientModulusType
The coefficient modulus is a list of distinct Modulus instances.
DegreeType
The available degree sizes for the polynomial modulus.
Error
A type representing all errors that can occur in SEAL.
PlainModulusType
The plain modulus is either a constant or a Modulus instance.
SchemeType
The FHE scheme supported by SEAL.
SecurityLevel
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.
FromBytes
A trait for converting data from a byte slice under a given SEAL context.
FromChunk
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§

AsymmetricEncryptor
An encryptor capable of asymmetric encryptions.
Result
The result type for SEAL operations.
SymmetricEncryptor
An encryptor capable of symmetric encryptions.