/// <summary> /// Creates an instance of SEALContext and performs several pre-computations /// on the given EncryptionParameters. /// </summary> /// <param name="parms">The encryption parameters.</param> /// <param name="expandModChain">Determines whether the modulus switching chain /// should be created</param> /// <param name="secLevel">Determines whether a specific security level should be /// enforced according to HomomorphicEncryption.org security standard</param> /// <exception cref="ArgumentNullException">if parms is null</exception> public SEALContext(EncryptionParameters parms, bool expandModChain = true, SecLevelType secLevel = SecLevelType.TC128) { if (null == parms) { throw new ArgumentNullException(nameof(parms)); } NativeMethods.SEALContext_Create(parms.NativePtr, expandModChain, (int)secLevel, out IntPtr context); NativePtr = context; }
/// <summary> /// Returns a default coefficient modulus for the BFV scheme that guarantees /// a given security level when using a given PolyModulusDegree, according /// to the HomomorphicEncryption.org security standard. /// </summary> /// <remarks> /// <para> /// Returns a default coefficient modulus for the BFV scheme that guarantees /// a given security level when using a given PolyModulusDegree, according /// to the HomomorphicEncryption.org security standard. Note that all security /// guarantees are lost if the output is used with encryption parameters with /// a mismatching value for the PolyModulusDegree. /// </para> /// <para> /// The coefficient modulus returned by this function will not perform well /// if used with the CKKS scheme. /// </para> /// </remarks> /// <param name="polyModulusDegree">The value of the PolyModulusDegree /// encryption parameter</param> /// <param name="secLevel">The desired standard security level</param> /// <exception cref="ArgumentException">if polyModulusDegree is not /// a power-of-two or is too large</exception> /// <exception cref="ArgumentException">if secLevel is SecLevelType.None</exception> static public IEnumerable <Modulus> BFVDefault( ulong polyModulusDegree, SecLevelType secLevel = SecLevelType.TC128) { List <Modulus> result = null; ulong length = 0; NativeMethods.CoeffModulus_BFVDefault(polyModulusDegree, (int)secLevel, ref length, null); IntPtr[] coeffArray = new IntPtr[length]; NativeMethods.CoeffModulus_BFVDefault(polyModulusDegree, (int)secLevel, ref length, coeffArray); result = new List <Modulus>(checked ((int)length)); foreach (IntPtr sm in coeffArray) { result.Add(new Modulus(sm)); } return(result); }
/// <summary> /// Returns the largest bit-length of the coefficient modulus, i.e., bit-length /// of the product of the primes in the coefficient modulus, that guarantees /// a given security level when using a given PolyModulusDegree, according /// to the HomomorphicEncryption.org security standard. /// </summary> /// <param name="polyModulusDegree">The value of the PolyModulusDegree /// encryption parameter</param> /// <param name="secLevel">The desired standard security level</param> static public int MaxBitCount(ulong polyModulusDegree, SecLevelType secLevel = SecLevelType.TC128) { NativeMethods.CoeffModulus_MaxBitCount(polyModulusDegree, (int)secLevel, out int result); return(result); }