AssertionError for vector length when using py-fhe library for vector encryption

39 views Asked by At

I'm trying to use a ckks encryption example from this repo with my vectors, https://github.com/sarojaerabelli/py-fhe/blob/master/examples/ckks_mult_example.py

Problem is, each of my vectors have a length of 384, and am getting this AssertionError which tells me my vector input should be no longer than 4?

--------------------------------------------------------------------------
AssertionError                            Traceback (most recent call last)
Input In [109], in <cell line: 288>()
    286     print(decoded_prod)
    288 if __name__ == '__main__':
--> 289     main()

Input In [109], in main()
     20 message1 = [-3.79753560e-02, -6.30261227e-02,  2.69851647e-02,
     21     -3.47770355e-03,  9.56548937e-03,  3.48446481e-02,
     22     -7.05104098e-02,  9.73049253e-02, -6.37022555e-02,
   (...)
    146     -2.02675257e-02,  3.81615348e-02,  8.35148767e-02,
    147     -1.22976303e-01,  3.51145980e-03,  8.04288909e-02]
    148 message2 = [8.41763467e-02,  7.97715560e-02, -3.20573114e-02,
    149      6.55033067e-02,  7.97787756e-02,  7.77527317e-02,
    150      8.79104584e-02,  1.38479229e-02, -2.50950065e-02,
   (...)
    274      3.21132410e-03, -3.40829529e-02, -9.36536863e-02,
    275      5.24005406e-02, -2.34307665e-02, -7.30145816e-03]
--> 278 plain1 = encoder.encode(message1, scaling_factor)
    279 plain2 = encoder.encode(message2, scaling_factor)
    280 ciph1 = encryptor.encrypt(plain1)

File c:\users\...\py-fhe-master\ckks\ckks_encoder.py:42, in CKKSEncoder.encode(self, values, scaling_factor)
     39 plain_len = num_values << 1
     41 # Canonical embedding inverse variant.
---> 42 to_scale = self.fft.embedding_inv(values)
     44 # Multiply by scaling factor, and split up real and imaginary parts.
     45 message = [0] * plain_len

File c:\users\...\py-fhe-master\util\ntt.py:347, in FFTContext.embedding_inv(self, coeffs)
    338 def embedding_inv(self, coeffs):
    339     """Computes the inverse variant of the canonical embedding.
    340 
    341     Args:
   (...)
    345         List of transformed coefficients.
    346     """
--> 347     self.check_embedding_input(coeffs)
    348     num_coeffs = len(coeffs)
    349     result = coeffs.copy()

File c:\users\..\py-fhe-master\util\ntt.py:298, in FFTContext.check_embedding_input(self, values)
    289 def check_embedding_input(self, values):
    290     """Checks that the length of the input vector to embedding is the correct size.
    291 
    292     Throws an error if the length of the input vector to embedding is not 1/4 the size
   (...)
    296         values (list): Input vector of complex numbers.
    297     """
--> 298     assert len(values) <= self.fft_length / 4, "Input vector must have length at most " \
    299         + str(self.fft_length / 4) + " < " + str(len(values)) + " = len(values)"

AssertionError: Input vector must have length at most 4.0 < 384 = len(values)

I am looking for advice of what I could possibly change in this code for it to work with my vectors? I note the lines 290 to 298 which say '"""Checks that the length of the input vector to embedding is the correct size. Throws an error if the length of the input vector to embedding is not 1/4 the size of the FFT vector. Args: values (list): Input vector of complex numbers. """ in https://github.com/sarojaerabelli/py-fhe/blob/master/util/ntt.py.

This library seems to be one of the few homomorphic encryption libraries for Python that I was able to find. thank you.

0

There are 0 answers