Creating openssl generates a deterministic key

I am trying to create openssl to generate a deterministic private and public RSA key pair. The idea is that I populate my seedbuf HASH with some device-specific data and use it as a seed. But sowing the RAND does not seem to work, the keys are still randomized.

For various reasons, I don’t want to just generate the key once, and then save it, I want only the private key to exist in memory.

RAND_seed(seedbuf, sizeof(seedbuf));

bne = BN_new();
if (1 != BN_set_word(bne,e)) {
    goto free_stuff;
}

keypair = RSA_new();
if(1 != RSA_generate_key_ex(keypair, KEY_LENGTH, bne, NULL)) {
    goto free_stuff;
}

So basically, I want the RSA_generate_key_ex function to return the same key pair every time it is seeded with the same input.

+4
source share
1 answer

Creating openssl generates a deterministic key ...

, . OpenSSL md_rand, . rand_seed rand_add, ( / ). md_rand crypto/rand/md_rand.c.

FIPS enabled, NIST SP 800-90. , , , md_rand. , . crypto/rand/rand_lib.c.

, . my_rand. . , .

, RSA_generate_key_ex PRNG, OpenSSL ENGINE. OpenSSL " 1" : Engine Engine 2: MD5 Engine OpenSSL.

, . , ENGINE_METHOD_RAND, .

ENGINE* eng = ENGINE_by_id("my_rand");
unsigned long err = ERR_get_error();

if(NULL == eng) {
    fprintf(stderr, "ENGINE_by_id failed, err = 0x%lx\n", err);
    abort(); /* failed */
}

int rc = ENGINE_init(eng);
err = ERR_get_error();

if(0 == rc) {
    fprintf(stderr, "ENGINE_init failed, err = 0x%lx\n", err);
    abort(); /* failed */
}

rc = ENGINE_set_default(eng, ENGINE_METHOD_RAND);
err = ERR_get_error();

if(0 == rc) {
    fprintf(stderr, "ENGINE_set_default failed, err = 0x%lx\n", err);
    abort(); /* failed */
}

ENGINE, rdrand crypto/engine/eng_rdrand.c. , /. Makefile crypto/engine/Makefile.

+4

Source: https://habr.com/ru/post/1534232/


All Articles