lundi 10 septembre 2018

C Warning when creating an RSA key pair - random: uninitialized urandom read (32 bytes read)

I am creating an RSA key pair with the following code (C):

void rsa_gen_keys_ca() {
    RSA *keypair = NULL;
    unsigned char *pub_key = NULL;
    BIGNUM *bne = NULL;
    unsigned long e = RSA_F4;
    int success = 0;

    bne = BN_new();
    success = BN_set_word(bne, e);
    if (!success) {
        errx(1, "\nrsa_gen_keys_ca failed at BN_set_word result.");
        goto free_all;
    }

    keypair = RSA_new();
    success = RSA_generate_key_ex(keypair, RSA_KEY_SIZE, bne, NULL);
    if (!success) {
        errx(1, "\nrsa_gen_keys_ca failed at RSA_generate_key_ex result.");
        goto free_all;
    }

    success = i2d_RSAPublicKey(keypair, &pub_key);
    if (success < 0) {
        errx(1, "\nrsa_gen_keys_ca failed at i2d_RSAPublicKey result.");
        goto free_all;
    }
    printf("==========RSA Public Key successfully extracted: %s", pub_key);

free_all:
    RSA_free(keypair);
    BN_free(bne);
}

When I run it, I am receiving the following warning:

random: uninitialized urandom read (32 bytes read)

I did not find this question here at Stack Overflow and I did not find a direct answer related to avoid this behavior. I think leave the code with this warning is a security concern, since in the past I already read something regarding the urandom generator. Can anyone explain this warning and how to avoid it?




Aucun commentaire:

Enregistrer un commentaire