Files
concrete/docs/dev/api/concrete.fhe.compilation.keys.md
2024-12-24 14:08:39 +01:00

5.2 KiB

module concrete.fhe.compilation.keys

Declaration of Keys class.


class Keys

Keys class, to manage generate/reuse keys.

Includes encryption keys as well as evaluation keys. Be careful when serializing/saving keys!

method __init__

__init__(
    specs: Optional[ClientSpecs],
    cache_directory: Optional[Path, str] = None
)

property are_generated

Get if the keys are already generated.


property evaluation

Get only evaluation keys.


property specs

Return the associated client specs if any.


method deserialize

deserialize(serialized_keys: Union[Path, bytes])  Keys

Deserialize keys from file or buffer.

Prefer using a Path instead of bytes in case of big Keys. It reduces memory usage.

Args: serialized_keys (Union[Path, bytes]): previously serialized keys (either Path or buffer)

Returns: Keys: deserialized keys


method generate

generate(
    force: bool = False,
    secret_seed: Optional[int] = None,
    encryption_seed: Optional[int] = None,
    initial_keys: Optional[Dict[int, LweSecretKey]] = None
)

Generate new keys.

Args: force (bool, default = False): whether to generate new keys even if keys are already generated/loaded

secret_seed (Optional[int], default = None): seed for private keys randomness

encryption_seed (Optional[int], default = None): seed for encryption randomness

initial_keys (Optional[Dict[int, LweSecretKey]] = None): initial keys to set before keygen


method load

load(location: Union[str, Path])

Load keys from a location.

Args: location (Union[str, Path]): location to load from


method load_if_exists_generate_and_save_otherwise

load_if_exists_generate_and_save_otherwise(
    location: Union[str, Path],
    secret_seed: Optional[int] = None
)

Load keys from a location if they exist, else generate new keys and save to that location.

Args: location (Union[str, Path]): location to load from or save to

secret_seed (Optional[int], default = None): seed for randomness in case keys need to be generated


method save

save(location: Union[str, Path])

Save keys to a location.

Saved keys are not encrypted, so be careful how you store/transfer them!

Args: location (Union[str, Path]): location to save to


method serialize

serialize()  bytes

Serialize keys into bytes.

Serialized keys are not encrypted, so be careful how you store/transfer them! serialize_to_file is supposed to be more performant as it avoid copying the buffer between the Compiler and the Frontend.

Returns: bytes: serialized keys


method serialize_to_file

serialize_to_file(path: Path)

Serialize keys into a file.

Serialized keys are not encrypted, so be careful how you store/transfer them! This is supposed to be more performant than serialize as it avoid copying the buffer between the Compiler and the Frontend.

Args:

  • path (Path): where to save serialized keys