SEAL icon indicating copy to clipboard operation
SEAL copied to clipboard

Create secret key from a seed

Open s0l0ist opened this issue 4 years ago • 3 comments

Is it possible to create an asymmetric secret key from a given seed and then re-use this seed to create the same secret key?

s0l0ist avatar Apr 03 '20 19:04 s0l0ist

Thanks for suggestion. We'll leave this issue open and will get back to it after the next release. One issue is that this kind of seeded secret key is not described in the HE.org security standard.

kimlaine avatar Apr 07 '20 21:04 kimlaine

There is already a pretty easy way to achieve this by using a PRNG seed as the key and then use that PRNG only for setting up the KeyGenerator as follows:

#include <seal/randomgen.h>
#include <seal/keygenerator.h>
#include <memory>

using namespace seal;

random_seed_type secret_key = {
    random_uint64(), random_uint64(), random_uint64(), random_uint64(),
    random_uint64(), random_uint64(), random_uint64(), random_uint64()
};

std::shared_ptr<UniformRandomGeneratorFactory> rg = make_shared<BlakePRNGFactory(secret_key);
EncryptionParameters parms_copy(<your encryption parameters here>);
parms_copy.set_random_generator(rg);
auto context_copy = SEALContext::Create(parms_copy, false);
KeyGenerator keygen_copy(context_copy);
SecretKey seal_secret_key = keygen_copy.secret_key();

// Now you have the short secret key seed in secret_key and the full key in seal_secret_key.
// Now you can set up the real context and use the SecretKey to initialize a new KeyGenerator that
// can be used for GaloisKeys etc.

kimlaine avatar May 12 '20 21:05 kimlaine

The security also relies on the seeded PRNG used to generate or expand the secret key. The encryption schemes remain secure as long as the uniform ternary distribution generated from a seeded PRNG is computationally indistinguishable from a uniform ternary distribution. Using a cryptographically secure PRNG is required, and Blake2 is one of them.

WeiDaiWD avatar May 15 '20 07:05 WeiDaiWD