Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Gemini BGV #283

Merged
merged 10 commits into from
Jun 23, 2021
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
92 changes: 92 additions & 0 deletions .vscode/settings.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,92 @@
{
"files.associations": {
"stdexcept": "cpp",
"__bit_reference": "cpp",
"__config": "cpp",
"__debug": "cpp",
"__errc": "cpp",
"__functional_base": "cpp",
"__hash_table": "cpp",
"__locale": "cpp",
"__mutex_base": "cpp",
"__node_handle": "cpp",
"__nullptr": "cpp",
"__split_buffer": "cpp",
"__string": "cpp",
"__threading_support": "cpp",
"__tree": "cpp",
"__tuple": "cpp",
"algorithm": "cpp",
"array": "cpp",
"atomic": "cpp",
"bit": "cpp",
"bitset": "cpp",
"cctype": "cpp",
"chrono": "cpp",
"cinttypes": "cpp",
"cmath": "cpp",
"complex": "cpp",
"condition_variable": "cpp",
"cstdarg": "cpp",
"cstddef": "cpp",
"cstdint": "cpp",
"cstdio": "cpp",
"cstdlib": "cpp",
"cstring": "cpp",
"ctime": "cpp",
"cwchar": "cpp",
"cwctype": "cpp",
"deque": "cpp",
"exception": "cpp",
"forward_list": "cpp",
"fstream": "cpp",
"functional": "cpp",
"initializer_list": "cpp",
"iomanip": "cpp",
"ios": "cpp",
"iosfwd": "cpp",
"iostream": "cpp",
"istream": "cpp",
"iterator": "cpp",
"limits": "cpp",
"list": "cpp",
"locale": "cpp",
"map": "cpp",
"memory": "cpp",
"mutex": "cpp",
"new": "cpp",
"numeric": "cpp",
"optional": "cpp",
"ostream": "cpp",
"queue": "cpp",
"random": "cpp",
"ratio": "cpp",
"regex": "cpp",
"set": "cpp",
"shared_mutex": "cpp",
"sstream": "cpp",
"stack": "cpp",
"streambuf": "cpp",
"string": "cpp",
"string_view": "cpp",
"system_error": "cpp",
"thread": "cpp",
"tuple": "cpp",
"type_traits": "cpp",
"typeinfo": "cpp",
"unordered_map": "cpp",
"unordered_set": "cpp",
"utility": "cpp",
"vector": "cpp",
"pointers": "cpp",
"__functional_03": "cpp",
"multi_span": "cpp",
"*.tcc": "cpp",
"clocale": "cpp",
"compare": "cpp",
"concepts": "cpp",
"memory_resource": "cpp",
"ranges": "cpp",
"stop_token": "cpp"
}
}
4 changes: 2 additions & 2 deletions dotnet/src/BatchEncoder.cs
Original file line number Diff line number Diff line change
Expand Up @@ -59,7 +59,7 @@ public class BatchEncoder : NativeObject
/// @param[in] context
/// <exception cref="ArgumentNullException">if context is null.</exception>
/// <exception cref="ArgumentException">if the encryption parameters are not valid for batching</exception>
/// <exception cref="ArgumentException">if scheme is not SchemeType.BFV</exception>
/// <exception cref="ArgumentException">if scheme is not SchemeType.BFV or SchemeType.BGV </exception>
public BatchEncoder(SEALContext context)
{
if (null == context)
Expand All @@ -68,7 +68,7 @@ public BatchEncoder(SEALContext context)
throw new ArgumentException("Encryption parameters are not set correctly");

SEALContext.ContextData contextData = context.FirstContextData;
if (contextData.Parms.Scheme != SchemeType.BFV)
if (contextData.Parms.Scheme != SchemeType.BFV && contextData.Parms.Scheme != SchemeType.BGV)
throw new ArgumentException("Unsupported scheme");
if (!contextData.Qualifiers.UsingBatching)
throw new ArgumentException("Encryption parameters are not valid for batching");
Expand Down
2 changes: 1 addition & 1 deletion dotnet/src/Decryptor.cs
Original file line number Diff line number Diff line change
Expand Up @@ -103,7 +103,7 @@ public void Decrypt(Ciphertext encrypted, Plaintext destination)
/// </remarks>
/// <param name="encrypted">The ciphertext</param>
/// <exception cref="ArgumentNullException">if encrypted is null</exception>
/// <exception cref="ArgumentException">if the scheme is not BFV</exception>
/// <exception cref="ArgumentException">if the scheme is not BFV or BGV</exception>
/// <exception cref="ArgumentException">if encrypted is not valid for the encryption parameters</exception>
/// <exception cref="ArgumentException">if encrypted is in NTT form</exception>
/// <exception cref="ArgumentException">if pool is uninitialized</exception>
Expand Down
11 changes: 9 additions & 2 deletions dotnet/src/EncryptionParameters.cs
Original file line number Diff line number Diff line change
Expand Up @@ -28,7 +28,14 @@ public enum SchemeType : byte
/// <summary>
/// Cheon-Kim-Kim-Song scheme
/// </summary>
CKKS = 0x2
CKKS = 0x2,

/// <summary>
/// Brakerski-Gentry-Vaikuntanathan
/// </summary>
BGV = 0x3


}

/// <summary>
Expand Down Expand Up @@ -223,7 +230,7 @@ public IEnumerable<Modulus> CoeffModulus
/// of a particular form.
/// </remarks>
/// <exception cref="ArgumentNullException">if the value being set is null</exception>
/// <exception cref="InvalidOperationException">if scheme is not SchemeType.BFV</exception>
/// <exception cref="InvalidOperationException">if scheme is not SchemeType.BFV or SchemeType.BGV</exception>
public Modulus PlainModulus
{
get
Expand Down
8 changes: 4 additions & 4 deletions dotnet/src/Encryptor.cs
Original file line number Diff line number Diff line change
Expand Up @@ -129,7 +129,7 @@ public void SetSecretKey(SecretKey secretKey)
/// </para>
/// <para>
/// The encryption parameters for the resulting ciphertext correspond to:
/// 1) in BFV, the highest (data) level in the modulus switching chain,
/// 1) in BFV or BGV, the highest (data) level in the modulus switching chain,
/// 2) in CKKS, the encryption parameters of the plaintext.
/// Dynamic memory allocations in the process are allocated from the memory
/// pool pointed to by the given MemoryPoolHandle.
Expand Down Expand Up @@ -173,7 +173,7 @@ public void SetSecretKey(SecretKey secretKey)
/// </para>
/// <para>
/// The encryption parameters for the resulting ciphertext correspond to:
/// 1) in BFV, the highest (data) level in the modulus switching chain,
/// 1) in BFV or BGV, the highest (data) level in the modulus switching chain,
/// 2) in CKKS, the encryption parameters of the plaintext.
/// Dynamic memory allocations in the process are allocated from the memory
/// pool pointed to by the given MemoryPoolHandle.
Expand Down Expand Up @@ -337,7 +337,7 @@ public Serializable<Ciphertext> EncryptZero(MemoryPoolHandle pool = null)
/// </para>
/// <para>
/// The encryption parameters for the resulting ciphertext correspond to:
/// 1) in BFV, the highest (data) level in the modulus switching chain,
/// 1) in BFV or BGV, the highest (data) level in the modulus switching chain,
/// 2) in CKKS, the encryption parameters of the plaintext.
/// Dynamic memory allocations in the process are allocated from the memory
/// pool pointed to by the given MemoryPoolHandle.
Expand Down Expand Up @@ -385,7 +385,7 @@ public Serializable<Ciphertext> EncryptZero(MemoryPoolHandle pool = null)
/// </para>
/// <para>
/// The encryption parameters for the resulting ciphertext correspond to:
/// 1) in BFV, the highest (data) level in the modulus switching chain,
/// 1) in BFV or BGV, the highest (data) level in the modulus switching chain,
/// 2) in CKKS, the encryption parameters of the plaintext.
/// Dynamic memory allocations in the process are allocated from the memory
/// pool pointed to by the given MemoryPoolHandle.
Expand Down
28 changes: 14 additions & 14 deletions dotnet/src/Evaluator.cs
Original file line number Diff line number Diff line change
Expand Up @@ -58,7 +58,7 @@ namespace Microsoft.Research.SEAL
/// </para>
/// <para>
/// NTT form
/// When using the BFV scheme (SchemeType.BFV), all plaintexts and ciphertexts should remain by default in the usual
/// When using the BFV or BGV scheme (SchemeType.BFV or SchemeType.BGV), all plaintexts and ciphertexts should remain by default in the usual
/// coefficient representation, i.e., not in NTT form. When using the CKKS scheme (SchemeType.CKKS), all plaintexts
/// and ciphertexts should remain by default in NTT form. We call these scheme-specific NTT states the "default NTT
/// form". Some functions, such as add, work even if the inputs are not in the default state, but others, such as
Expand Down Expand Up @@ -740,7 +740,7 @@ public void RescaleTo(Ciphertext encrypted, ParmsId parmsId, Ciphertext destinat
/// <param name="destination">The ciphertext to overwrite with the multiplication result</param>
/// <param name="pool">The MemoryPoolHandle pointing to a valid memory pool</param>
/// <exception cref="ArgumentNullException">if encrypteds, relinKeys, or destination is null</exception>
/// <exception cref="InvalidOperationException">if scheme is not SchemeType.BFV</exception>
/// <exception cref="InvalidOperationException">if scheme is not SchemeType.BFV or SchemeType.BGV</exception>
/// <exception cref="ArgumentException">if encrypteds is empty</exception>
/// <exception cref="ArgumentException">if encrypteds or relinKeys are not valid for the encryption
/// parameters</exception>
Expand Down Expand Up @@ -784,7 +784,7 @@ public void RescaleTo(Ciphertext encrypted, ParmsId parmsId, Ciphertext destinat
/// <param name="relinKeys">The relinearization keys</param>
/// <param name="pool">The MemoryPoolHandle pointing to a valid memory pool</param>
/// <exception cref="ArgumentNullException">if encrypted or relinKeys is null</exception>
/// <exception cref="InvalidOperationException">if scheme is not SchemeType.BFV</exception>
/// <exception cref="InvalidOperationException">if scheme is not SchemeType.BFV or SchemeType.BGV</exception>
/// <exception cref="ArgumentException">if encrypted or relinKeys is not valid for the encryption
/// parameters</exception>
/// <exception cref="ArgumentException">if encrypted is not in the default NTT form</exception>
Expand Down Expand Up @@ -816,7 +816,7 @@ public void RescaleTo(Ciphertext encrypted, ParmsId parmsId, Ciphertext destinat
/// <param name="relinKeys">The relinearization keys</param>
/// <param name="destination">The ciphertext to overwrite with the power</param>
/// <param name="pool">The MemoryPoolHandle pointing to a valid memory pool</param>
/// <exception cref="InvalidOperationException">if scheme is not SchemeType.BFV</exception>
/// <exception cref="InvalidOperationException">if scheme is not SchemeType.BFV or SchemeType.BGV</exception>
/// <exception cref="ArgumentException">if encrypted or relinKeys is not valid for the encryption
/// parameters</exception>
/// <exception cref="ArgumentException">if encrypted is not in the default NTT form</exception>
Expand Down Expand Up @@ -1148,7 +1148,7 @@ public void TransformFromNTT(Ciphertext encryptedNTT, Ciphertext destination)
/// The desired Galois automorphism is given as a Galois element, and must be an odd integer in the interval
/// [1, M-1], where M = 2*N, and N = PolyModulusDegree. Used with batching, a Galois element 3^i % M corresponds
/// to a cyclic row rotation i steps to the left, and a Galois element 3^(N/2-i) % M corresponds to a cyclic row
/// rotation i steps to the right. The Galois element M-1 corresponds to a column rotation (row swap) in BFV,
/// rotation i steps to the right. The Galois element M-1 corresponds to a column rotation (row swap) in BFV or BGV,
/// and complex conjugation in CKKS. In the polynomial view (not batching), a Galois automorphism by a Galois
/// element p changes Enc(plain(x)) to Enc(plain(x^p)).
/// </para>
Expand Down Expand Up @@ -1188,7 +1188,7 @@ public void TransformFromNTT(Ciphertext encryptedNTT, Ciphertext destination)
/// The desired Galois automorphism is given as a Galois element, and must be an odd integer in the interval
/// [1, M-1], where M = 2*N, and N = PolyModulusDegree. Used with batching, a Galois element 3^i % M corresponds
/// to a cyclic row rotation i steps to the left, and a Galois element 3^(N/2-i) % M corresponds to a cyclic row
/// rotation i steps to the right. The Galois element M-1 corresponds to a column rotation (row swap) in BFV,
/// rotation i steps to the right. The Galois element M-1 corresponds to a column rotation (row swap) in BFV or BGV,
/// and complex conjugation in CKKS. In the polynomial view (not batching), a Galois automorphism by a Galois
/// element p changes Enc(plain(x)) to Enc(plain(x^p)).
/// </para>
Expand Down Expand Up @@ -1232,7 +1232,7 @@ public void TransformFromNTT(Ciphertext encryptedNTT, Ciphertext destination)
/// Rotates plaintext matrix rows cyclically.
/// </summary>
/// <remarks>
/// When batching is used with the BFV scheme, this function rotates the encrypted plaintext matrix rows
/// When batching is used with the BFV or BGV scheme, this function rotates the encrypted plaintext matrix rows
/// cyclically to the left (steps &gt; 0) or to the right (steps &lt; 0). Since the size of the batched matrix
/// is 2-by-(N/2), where N is the degree of the polynomial modulus, the number of steps to rotate must have
/// absolute value at most N/2-1. Dynamic memory allocations in the process are allocated from the memory pool
Expand All @@ -1244,7 +1244,7 @@ public void TransformFromNTT(Ciphertext encryptedNTT, Ciphertext destination)
/// <param name="pool">The MemoryPoolHandle pointing to a valid memory pool</param>
/// <exception cref="ArgumentNullException">if encrypted or galoisKeys is null</exception>
/// <exception cref="InvalidOperationException">if the encryption parameters do not support batching</exception>
/// <exception cref="InvalidOperationException">if scheme is not SchemeType.BFV</exception>
/// <exception cref="InvalidOperationException">if scheme is not SchemeType.BFV or SchemeType.BGV</exception>
/// <exception cref="ArgumentException">if encrypted or galoisKeys is not valid for the encryption
/// parameters</exception>
/// <exception cref="ArgumentException">if galoisKeys do not correspond to the top level parameters in the
Expand All @@ -1266,7 +1266,7 @@ public void TransformFromNTT(Ciphertext encryptedNTT, Ciphertext destination)
/// Rotates plaintext matrix rows cyclically.
/// </summary>
/// <remarks>
/// When batching is used with the BFV scheme, this function rotates the encrypted plaintext matrix rows
/// When batching is used with the BFV or BGV scheme, this function rotates the encrypted plaintext matrix rows
/// cyclically to the left (steps &gt; 0) or to the right (steps &lt; 0) and writes the result to the
/// destination parameter. Since the size of the batched matrix is 2-by-(N/2), where N is the degree of the
/// polynomial modulus, the number of steps to rotate must have absolute value at most N/2-1. Dynamic memory
Expand All @@ -1279,7 +1279,7 @@ public void TransformFromNTT(Ciphertext encryptedNTT, Ciphertext destination)
/// <param name="pool">The MemoryPoolHandle pointing to a valid memory pool</param>
/// <exception cref="ArgumentNullException">if encrypted, galoisKeys, or destination is null</exception>
/// <exception cref="InvalidOperationException">if the encryption parameters do not support batching</exception>
/// <exception cref="InvalidOperationException">if scheme is not SchemeType.BFV</exception>
/// <exception cref="InvalidOperationException">if scheme is not SchemeType.BFV or SchemeType.BGV</exception>
/// <exception cref="ArgumentException">if encrypted or galoisKeys is not valid for the encryption
/// parameters</exception>
/// <exception cref="ArgumentException">if galoisKeys do not correspond to the top level parameters in the
Expand Down Expand Up @@ -1313,7 +1313,7 @@ public void TransformFromNTT(Ciphertext encryptedNTT, Ciphertext destination)
/// Rotates plaintext matrix columns cyclically.
/// </summary>
/// <remarks>
/// When batching is used with the BFV scheme, this function rotates the encrypted plaintext matrix columns
/// When batching is used with the BFV or BGV scheme, this function rotates the encrypted plaintext matrix columns
/// cyclically. Since the size of the batched matrix is 2-by-(N/2), where N is the degree of the polynomial
/// modulus, this means simply swapping the two rows. Dynamic memory allocations in the process are allocated
/// from the memory pool pointed to by the given MemoryPoolHandle.
Expand All @@ -1323,7 +1323,7 @@ public void TransformFromNTT(Ciphertext encryptedNTT, Ciphertext destination)
/// <param name="pool">The MemoryPoolHandle pointing to a valid memory pool</param>
/// <exception cref="ArgumentNullException">if encrypted or galoisKeys is null</exception>
/// <exception cref="InvalidOperationException">if the encryption parameters do not support batching</exception>
/// <exception cref="InvalidOperationException">if scheme is not SchemeType.BFV</exception>
/// <exception cref="InvalidOperationException">if scheme is not SchemeType.BFV or SchemeType.BGV</exception>
/// <exception cref="ArgumentException">if encrypted or galoisKeys is not valid for the encryption
/// parameters</exception>
/// <exception cref="ArgumentException">if galoisKeys do not correspond to the top level parameters in the
Expand All @@ -1343,7 +1343,7 @@ public void RotateColumnsInplace(Ciphertext encrypted, GaloisKeys galoisKeys, Me
/// Rotates plaintext matrix columns cyclically.
/// </summary>
/// <remarks>
/// When batching is used with the BFV scheme, this function rotates the encrypted plaintext matrix columns
/// When batching is used with the BFV or BGV scheme, this function rotates the encrypted plaintext matrix columns
/// cyclically, and writes the result to the destination parameter. Since the size of the batched matrix is
/// 2-by-(N/2), where N is the degree of the polynomial modulus, this means simply swapping the two rows.
/// Dynamic memory allocations in the process are allocated from the memory pool pointed to by the given
Expand All @@ -1355,7 +1355,7 @@ public void RotateColumnsInplace(Ciphertext encrypted, GaloisKeys galoisKeys, Me
/// <param name="pool">The MemoryPoolHandle pointing to a valid memory pool</param>
/// <exception cref="ArgumentNullException">if encrypted, galoisKeys, or destination is null</exception>
/// <exception cref="InvalidOperationException">if the encryption parameters do not support batching</exception>
/// <exception cref="InvalidOperationException">if scheme is not SchemeType.BFV</exception>
/// <exception cref="InvalidOperationException">if scheme is not SchemeType.BFV or SchemeType.BGV</exception>
/// <exception cref="ArgumentException">if encrypted or galoisKeys is not valid for the encryption
/// parameters</exception>
/// <exception cref="ArgumentException">if galoisKeys do not correspond to the top level parameters in the
Expand Down