|
|
@@ -1,4 +1,5 @@
|
|
|
import logging
|
|
|
+import pytest
|
|
|
|
|
|
import openfhe as fhe
|
|
|
|
|
|
@@ -37,3 +38,35 @@ def test_serial_cryptocontext(tmp_path):
|
|
|
assert isinstance(ct1, fhe.Ciphertext)
|
|
|
LOGGER.debug("Cryptocontext deserializes to %s %s", success, ct1)
|
|
|
assert fhe.SerializeToFile(str(tmp_path / "ciphertext12.json"), ct1, fhe.JSON)
|
|
|
+
|
|
|
+
|
|
|
+@pytest.mark.parametrize("mode", [fhe.JSON, fhe.BINARY])
|
|
|
+def test_serial_cryptocontext_str(mode):
|
|
|
+ parameters = fhe.CCParamsBFVRNS()
|
|
|
+ parameters.SetPlaintextModulus(65537)
|
|
|
+ parameters.SetMultiplicativeDepth(2)
|
|
|
+
|
|
|
+ cryptoContext = fhe.GenCryptoContext(parameters)
|
|
|
+ cryptoContext.Enable(fhe.PKESchemeFeature.PKE)
|
|
|
+
|
|
|
+ keypair = cryptoContext.KeyGen()
|
|
|
+ vectorOfInts = list(range(12))
|
|
|
+ plaintext = cryptoContext.MakePackedPlaintext(vectorOfInts)
|
|
|
+ ciphertext = cryptoContext.Encrypt(keypair.publicKey, plaintext)
|
|
|
+
|
|
|
+ cryptoContext_ser = fhe.Serialize(cryptoContext, mode)
|
|
|
+ LOGGER.debug("The cryptocontext has been serialized.")
|
|
|
+ ciphertext_ser = fhe.Serialize(ciphertext, mode)
|
|
|
+ LOGGER.debug("The ciphertext has been serialized.")
|
|
|
+
|
|
|
+ cryptoContext.ClearEvalMultKeys()
|
|
|
+ cryptoContext.ClearEvalAutomorphismKeys()
|
|
|
+ fhe.ReleaseAllContexts()
|
|
|
+
|
|
|
+ cc = fhe.DeserializeCryptoContextString(cryptoContext_ser, mode)
|
|
|
+ assert isinstance(cc, fhe.CryptoContext)
|
|
|
+ LOGGER.debug("The cryptocontext has been deserialized.")
|
|
|
+
|
|
|
+ ct = fhe.DeserializeCiphertextString(ciphertext_ser, mode)
|
|
|
+ assert isinstance(ct, fhe.Ciphertext)
|
|
|
+ LOGGER.debug("The ciphertext has been reserialized.")
|