microsoft / SEAL

Microsoft SEAL is an easy-to-use and powerful homomorphic encryption library.
https://www.microsoft.com/en-us/research/group/cryptography-research/
MIT License
3.53k stars 703 forks source link

Create secret key from a seed #151

Open s0l0ist opened 4 years ago

s0l0ist commented 4 years ago

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?

kimlaine commented 4 years ago

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 commented 4 years ago

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.
WeiDaiWD commented 4 years ago

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.