diff --git a/src/lib/bindings.cpp b/src/lib/bindings.cpp index 38905bf..e15e90e 100644 --- a/src/lib/bindings.cpp +++ b/src/lib/bindings.cpp @@ -1432,9 +1432,15 @@ void bind_encodings(py::module &m) { .def("GetScalingFactor", &PlaintextImpl::GetScalingFactor, ptx_GetScalingFactor_docs) .def("SetScalingFactor", &PlaintextImpl::SetScalingFactor, py::arg("sf"), - py::doc(ptx_SetScalingFactor_docs)) - .def("GetSchemeID", &PlaintextImpl::GetSchemeID, ptx_GetSchemeID_docs) - .def("GetLength", &PlaintextImpl::GetLength, ptx_GetLength_docs) + py::doc(ptx_SetScalingFactor_docs) + .def("GetSchemeID", &PlaintextImpl::GetSchemeID, + ptx_GetSchemeID_docs) + .def("__len__", &PlaintextImpl::GetLength, + ptx_GetLength_docs) + .def("GetLength", &PlaintextImpl::GetLength, + ptx_GetLength_docs) + .def("GetSchemeID", &PlaintextImpl::GetSchemeID, + ptx_GetSchemeID_docs) .def("SetLength", &PlaintextImpl::SetLength, py::arg("newSize"), py::doc(ptx_SetLength_docs)) diff --git a/tests/test_boolean.py b/tests/test_boolean.py index a69b9f6..df5f0b1 100644 --- a/tests/test_boolean.py +++ b/tests/test_boolean.py @@ -3,9 +3,10 @@ ## Sample Program: Step 1: Set CryptoContext +@pytest.mark.parametrize("context",[TOY,MEDIUM,STD128]) @pytest.mark.parametrize("a", [0, 1]) @pytest.mark.parametrize("b", [0, 1]) -def test_boolean_AND(a, b): +def test_boolean_AND(context,a, b): cc = BinFHEContext() """ @@ -14,13 +15,13 @@ def test_boolean_AND(a, b): MEDIUM corresponds to the level of more than 100 bits for both quantum and classical computer attacks """ - cc.GenerateBinFHEContext(STD128, GINX) + cc.GenerateBinFHEContext(context, GINX) ## Sample Program: Step 2: Key Generation # Generate the secret key sk = cc.KeyGen() - + assert sk.GetLength() == len(sk) print("Generating the bootstrapping keys...\n") # Generate the bootstrapping keys (refresh and switching keys) @@ -37,6 +38,8 @@ def test_boolean_AND(a, b): ct1 = cc.Encrypt(sk, a) ct2 = cc.Encrypt(sk, b) + assert ct1.GetLength() == len(ct1) + # Sample Program: Step 4: Evaluation # Compute (1 AND 1) = 1; Other binary gate options are OR, NAND, and NOR diff --git a/tests/test_cryptocontext.py b/tests/test_cryptocontext.py index a104c85..0a9b4df 100644 --- a/tests/test_cryptocontext.py +++ b/tests/test_cryptocontext.py @@ -1,14 +1,26 @@ import pytest import openfhe as fhe -pytestmark = pytest.mark.skipif(fhe.get_native_int() != 128, reason="Only for NATIVE_INT=128") +@pytest.mark.skipif(fhe.get_native_int() != 128, reason="Only for NATIVE_INT=128") +@pytest.mark.parametrize("scaling", [fhe.FIXEDAUTO, fhe.FIXEDMANUAL]) +def test_ckks_context_nativeint128(scaling): + batch_size = 8 + parameters = fhe.CCParamsCKKSRNS() + parameters.SetMultiplicativeDepth(5) + parameters.SetScalingModSize(78) + parameters.SetBatchSize(batch_size) + parameters.SetScalingTechnique(scaling) + parameters.SetNumLargeDigits(2) + cc = fhe.GenCryptoContext(parameters) + assert isinstance(cc, fhe.CryptoContext) + @pytest.mark.parametrize("scaling", [fhe.FIXEDAUTO, fhe.FIXEDMANUAL]) def test_ckks_context(scaling): batch_size = 8 parameters = fhe.CCParamsCKKSRNS() parameters.SetMultiplicativeDepth(5) - parameters.SetScalingModSize(78) + parameters.SetScalingModSize(60-1) parameters.SetBatchSize(batch_size) parameters.SetScalingTechnique(scaling) parameters.SetNumLargeDigits(2) diff --git a/tests/test_serial_cc.py b/tests/test_serial_cc.py index 5a1acf2..d376946 100644 --- a/tests/test_serial_cc.py +++ b/tests/test_serial_cc.py @@ -64,7 +64,9 @@ def test_serial_cryptocontext_str(mode): # First plaintext vector is encoded vectorOfInts1 = [1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11, 12] plaintext1 = cryptoContext.MakePackedPlaintext(vectorOfInts1) - + assert len(plaintext1) == plaintext1.GetLength() + assert len(plaintext1) == 12 + # Second plaintext vector is encoded vectorOfInts2 = [3, 2, 1, 4, 5, 6, 7, 8, 9, 10, 11, 12] plaintext2 = cryptoContext.MakePackedPlaintext(vectorOfInts2)