// Copyright (c) Microsoft Corporation. All rights reserved. // Licensed under the MIT license. using System; using System.Text; using Microsoft.Research.SEAL.Tools; namespace Microsoft.Research.SEAL { /// /// Stores a set of attributes (qualifiers) of a set of encryption parameters. /// /// /// /// Stores a set of attributes (qualifiers) of a set of encryption parameters. /// These parameters are mainly used internally in various parts of the library, /// e.g., to determine which algorithmic optimizations the current support. /// The qualifiers are automatically created by the /// class, silently passed on to classes such as , /// , and , and the only way /// to change them is by changing the encryption parameters themselves. In /// other words, a user will never have to create their own instance of this /// class, and in most cases never have to worry about it at all. /// public class EncryptionParameterQualifiers : NativeObject { /// /// Create a copy of an existing instance of EncryptionParameterQualifiers /// /// Original object to copy public EncryptionParameterQualifiers(EncryptionParameterQualifiers copy) { if (null == copy) throw new ArgumentNullException(nameof(copy)); NativeMethods.EPQ_Create(copy.NativePtr, out IntPtr ptr); NativePtr = ptr; } /// /// Create an instance of EncryptionParameterQualifiers through a pointer to /// a native object. /// /// Pointer to native EncryptionParameterQualifiers. /// Whether this instance owns the native pointer. internal EncryptionParameterQualifiers(IntPtr ptr, bool owned = true) : base(ptr, owned) { } /// /// If the encryption parameters are set in a way that is considered valid by SEAL, /// the variable ParametersSet is set to true. /// public bool ParametersSet { get { NativeMethods.EPQ_ParametersSet(NativePtr, out bool result); return result; } } /// /// If the encryption parameters are set in a way that is considered valid by SEAL, return "success". /// If the encryption parameters are set but not validated yet, return "none". /// Otherwise, return a brief reason. /// public string ParametersErrorName() { NativeMethods.EPQ_ParameterErrorName(NativePtr, null, out ulong length); StringBuilder buffer = new StringBuilder(checked((int)length)); NativeMethods.EPQ_ParameterErrorName(NativePtr, buffer, out length); return buffer.ToString(); } /// /// If the encryption parameters are set in a way that is considered valid by SEAL, return "valid". /// Otherwise, return a comprehensive reason. /// public string ParametersErrorMessage() { NativeMethods.EPQ_ParameterErrorMessage(NativePtr, null, out ulong length); StringBuilder buffer = new StringBuilder(checked((int)length)); NativeMethods.EPQ_ParameterErrorMessage(NativePtr, buffer, out length); return buffer.ToString(); } /// /// Tells whether FFT can be used for polynomial multiplication. /// /// /// /// Tells whether FFT can be used for polynomial multiplication. If the polynomial modulus /// is of the form X^N+1, where N is a power of two, then FFT can be used for fast /// multiplication of polynomials modulo the polynomial modulus. In this case the /// variable UsingFFT will be set to true. However, currently Microsoft SEAL requires this /// to be the case for the parameters to be valid. Therefore, ParametersSet can only /// be true if UsingFFT is true. /// public bool UsingFFT { get { NativeMethods.EPQ_UsingFFT(NativePtr, out bool result); return result; } } /// /// Tells whether NTT can be used for polynomial multiplication. /// /// /// /// Tells whether NTT can be used for polynomial multiplication. If the primes in the /// coefficient modulus are congruent to 1 modulo 2N, where X^N+1 is the polynomial /// modulus and N is a power of two, then the number-theoretic transform (NTT) can be /// used for fast multiplications of polynomials modulo the polynomial modulus and /// coefficient modulus.In this case the variable UsingNTT will be set to true. However, /// currently Microsoft SEAL requires this to be the case for the parameters to be valid. /// Therefore, ParametersSet can only be true if UsingNTT is true. /// public bool UsingNTT { get { NativeMethods.EPQ_UsingNTT(NativePtr, out bool result); return result; } } /// /// Tells whether batching is supported by the encryption parameters. /// /// /// /// Tells whether batching is supported by the encryption parameters. If the plaintext /// modulus is congruent to 1 modulo 2N, where X^N+1 is the polynomial modulus and N is /// a power of two, then it is possible to use the BatchEncoder class to view plaintext /// elements as 2-by-(N/2) matrices of integers modulo the plaintext modulus.This is /// called batching, and allows the user to operate on the matrix elements(slots) in /// a SIMD fashion, and rotate the matrix rows and columns.When the computation is /// easily vectorizable, using batching can yield a huge performance boost.If the /// encryption parameters support batching, the variable UsingBatching is set to true. /// public bool UsingBatching { get { NativeMethods.EPQ_UsingBatching(NativePtr, out bool result); return result; } } /// /// Tells whether fast plain lift is supported by the encryption parameters. /// /// /// /// Tells whether fast plain lift is supported by the encryption parameters. A certain /// performance optimization in multiplication of a ciphertext by a plaintext /// (Evaluator.MultiplyPlain) and in transforming a plaintext element to NTT domain /// (Evaluator.TransformToNTT) can be used when the plaintext modulus is smaller than /// each prime in the coefficient modulus. In this case the variable UsingFastPlainLift /// is set to true. /// public bool UsingFastPlainLift { get { NativeMethods.EPQ_UsingFastPlainLift(NativePtr, out bool result); return result; } } /// /// Tells whether the coefficient modulus consists of a set of primes that are in /// decreasing order. /// /// /// /// Tells whether the coefficient modulus consists of a set of primes that are in /// decreasing order. If this is true, certain modular reductions in base conversion /// can be omitted, improving performance. /// public bool UsingDescendingModulusChain { get { NativeMethods.EPQ_UsingDescendingModulusChain(NativePtr, out bool result); return result; } } /// /// Tells whether the encryption parameters are secure based on the standard /// parameters from HomomorphicEncryption.org security standard. /// public SecLevelType SecLevel { get { NativeMethods.EPQ_SecLevel(NativePtr, out int result); return (SecLevelType)result; } } /// /// Destroy native object. /// protected override void DestroyNativeObject() { NativeMethods.EPQ_Destroy(NativePtr); } } }