Huelse / SEAL-Python

Microsoft SEAL 4.X For Python
MIT License
324 stars 65 forks source link

Size of ciphertext in bytes #53

Closed pandasamanvaya closed 3 years ago

pandasamanvaya commented 3 years ago

Type To find the size of ciphertext in bytes

Describe I want to compute the size of ciphertext in bytes. Using sys.getsizeof() on a ciphertext object gives output as 56 bytes which doesn't seem to be the actual size of the ciphertext containing the coefficients of the polynomial. A function for this is available in Microsoft seal library as mentioned in this issue https://github.com/microsoft/SEAL/issues/88. I am wondering if the same is also in this library but seem have had no luck in finding any such method.

Huelse commented 3 years ago

Sorry for reply late, you can get the size of a ciphertext like this:

cipher = Ciphertext()
...
cipher_size = cipher.size()
# or
ciipher_sizec = cipher.size_capacity()

And for more, if you want the size in bytes, add a new code to the wrapper file, which point to Ciphertext::save_size, and no compression.

pandasamanvaya commented 3 years ago

So, cipher.size() outputs 2 whereas seal.Ciphertext class doesn't have any attribute "size_capacity()".

Huelse commented 3 years ago

I see, we will commit new attribute for this later.

Huelse commented 3 years ago

Now you could try to use save_size to get the size of ciphertext or plaintext in bytes.

pandasamanvaya commented 3 years ago

I recompiled all the files but it says seal.Ciphertext object has no attribute 'save_size'. However, I was able to perform cipher.save() and cipher.load() without any errors.

Huelse commented 3 years ago

It's not an attribute, you should call it as a method, and work well in my environment: print(cipher.save_size()) Can you find the save_size in src/wrapper.cpp line 216 or src/wrapper_with_pickle.cpp line 278? https://github.com/Huelse/SEAL-Python/blob/c66cef35eb4d2a766521a62e032a6a364d05b742/src/wrapper.cpp#L216 https://github.com/Huelse/SEAL-Python/blob/c66cef35eb4d2a766521a62e032a6a364d05b742/src/wrapper_with_pickle.cpp#L278

pandasamanvaya commented 3 years ago

image I did the same but it didn't work. I am using Ubuntu 20.04.2 LTS. I also can find save_size() method both in src/wrapper.cpp and src/wrapper_with_pickle.cpp.

Huelse commented 3 years ago

What about remove the build folder and .so files and recompile, or just clone a new repo.