ibarrond / Pyfhel

PYthon For Homomorphic Encryption Libraries, perform encrypted computations such as sum, mult, scalar product or matrix multiplication in Python, with NumPy compatibility. Uses SEAL/PALISADE as backends, implemented using Cython.
https://pyfhel.readthedocs.io/
Apache License 2.0
484 stars 78 forks source link

Multiplying a BGV encrypted integer (array) by a cleartext integer results in an error #196

Closed meirgold closed 1 year ago

meirgold commented 1 year ago

Description I encrypted an integer and attempted to multiply it by a cleartext integer. This resulted in the following error: TypeError: multiplicand must be either PyCtxt, PyPtxt or numerical(is <class 'int'> instead)

This works well with the BFV scheme and the error message indicates that numerical values are supported, so I'm not sure why this fails.

Code To Reproduce Error def bgv_mult(): HE = Pyfhel() bgv_params = { 'scheme': 'BGV', 'n': 2 13, 't': 65537, 'sec': 128, } HE.contextGen(bgv_params) # Generate context for bgv scheme HE.keyGen() # Key Generation: generates a pair of public/secret keys HE.rotateKeyGen() # Rotate key generation --> Allows rotation/shifting HE.relinKeyGen() # Relinearization key generation integer1 = np.array([127], dtype=np.int64) ctxt1 = HE.encryptBGV(integer1) ctxtMul1 = ctxt1 * 2

Expected behavior an encrypted value of [254]

Setup:

AlexanderViand commented 1 year ago

np.int64 is not an instance of int (nor is np.array[np.int64]). You'll need to encode these values into PyPtxt first.