homenc / HElib

HElib is an open-source software library that implements homomorphic encryption. It supports the BGV scheme with bootstrapping and the Approximate Number CKKS scheme. HElib also includes optimizations for efficient homomorphic evaluation, focusing on effective use of ciphertext packing techniques and on the Gentry-Halevi-Smart optimizations.
https://homenc.github.io/HElib
Other
3.11k stars 760 forks source link

Support saving only the secret key #442

Closed dubek closed 1 year ago

dubek commented 3 years ago

Add new API calls (writeOnlySecretKeyTo, readOnlySecretKeyFrom) to save/load just the secret key, resulting in a much smaller file.

Author: @HayimShaul cc: @aehud

faberga commented 3 years ago

Hi @dubek an @HayimShaul

Reading/Writing individual keys (public and secret) as well as individually reading/writing the context are already supported in HElib. Binary format has been supported for more than a year and JSON was added at end of last year.

Having said that, in HElib, the current support for writing/reading the secrete key(SK) to a file, does include the public key (PK) which can make the file bigger. We did that to guarantee that we always have the matching SK/PK pair. In HElib, for historic reasons, the secret key is implemented as a derived class from the public key class making them tightly coupled and separating them would incur a big refactoring of the codebase.

Separating the keys as you proposed would potentially lead to a mismatch between the SK and PK in an application that is reading in separate files for the SK and PK before reconstructing the SK. This would put the onus on the user to enforce/guarantee correctness.

With your proposed changes, one would have to read in the PK and the SK files to reconstruct the SK. SO, I don’t really see much benefit in the separation you proposed. We are reluctant to add the APIs proposed in this PR, as in its current state they can lead to errors.

faberga commented 1 year ago

@dubek and @HayimShaul. Closing this PR as the functionality for saving PK and SK keys individually has now been implemented by PR #493 which contains additional extensions.