Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 2 additions & 0 deletions src/lib/bindings.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -1041,6 +1041,8 @@ void bind_encodings(py::module &m)
py::arg("sf"))
.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,
Expand Down
2 changes: 2 additions & 0 deletions src/lib/binfhe_bindings.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -140,6 +140,7 @@ void bind_binfhe_keys(py::module &m) {
py::class_<LWEPrivateKeyImpl, std::shared_ptr<LWEPrivateKeyImpl>>(
m, "LWEPrivateKey")
.def(py::init<>())
.def("__len__", &LWEPrivateKeyImpl::GetLength)
.def("GetLength", &LWEPrivateKeyImpl::GetLength)
.def(py::self == py::self)
.def(py::self != py::self);
Expand All @@ -148,6 +149,7 @@ void bind_binfhe_ciphertext(py::module &m) {
py::class_<LWECiphertextImpl, std::shared_ptr<LWECiphertextImpl>>(
m, "LWECiphertext")
.def(py::init<>())
.def("__len__", &LWECiphertextImpl::GetLength)
.def("GetLength", &LWECiphertextImpl::GetLength)
.def("GetModulus", &GetLWECiphertextModulusWrapper)
.def(py::self == py::self)
Expand Down
9 changes: 6 additions & 3 deletions tests/test_boolean.py
Original file line number Diff line number Diff line change
Expand Up @@ -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()

"""
Expand All @@ -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)
Expand All @@ -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
Expand Down
16 changes: 14 additions & 2 deletions tests/test_cryptocontext.py
Original file line number Diff line number Diff line change
@@ -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)
Expand Down
4 changes: 3 additions & 1 deletion tests/test_serial_cc.py
Original file line number Diff line number Diff line change
Expand Up @@ -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)
Expand Down