Save Ciphertext and Keys

Hello,

I would like to know if there is a way to know the size of the encrypted ciphertext and of the keys in concrete-numpy ? Also, is it possible to save them yet ?
I have tried to use the sys.getsizeof(ciphertext) which returned 48 bytes, which made me think that it should be pointers if I understand the structure correctly.

Thanks in advance

Hi @tricycl3,

Here is how to do most of what you’re asking:

import concrete.numpy as cnp
import numpy as np

configuration = cnp.Configuration(
    enable_unsafe_features=True,
    use_insecure_key_cache=True,
    insecure_key_cache_location=".keys",
)

@cnp.compiler({"x": "encrypted"})
def f(x):
    return x ** 2

inputset = range(10)
circuit = f.compile(inputset, configuration, verbose=True)

print(f"Encryption keys: {circuit.size_of_secret_keys} bytes")
print(f"Evaluation keys: {circuit.size_of_bootstrap_keys + circuit.size_of_keyswitch_keys} bytes")
print(f"Inputs: {circuit.size_of_inputs} bytes")
print(f"Outputs: {circuit.size_of_outputs} bytes")

ciphertext = circuit.encrypt(5)
ciphertext_bytes = ciphertext.serialize()
# you can save ciphertext bytes to a file

evaluation_keys = circuit.client.evaluation_keys
evaluation_keys_bytes = evaluation_keys.serialize()
# you can save evaluation keys bytes to a file

It just lacks saving encryption keys, and we’re working on bringing a better API for it :slight_smile:

You might want to check https://docs.zama.ai/concrete-numpy/how-to/deploy to see a full deployment example.

Let me know if this helps!

1 Like

Thank you it is exactly what I was looking for !

1 Like

Glad to help!

Let me know if you have more questions :slight_smile: