[gcrypt-devel] gcry_pk_genkey function is extremely slow in libgcrypt

Shuai Wang wangshuai901 at gmail.com
Mon Sep 5 19:32:10 CEST 2016


I am a newbie to libgcrypt(version 1.6.1), and right now I am trying to
produce a public/private key pair for rsa algorithm.

I list the code I am using below. What I am trapped into is the
gcry_pk_genkey function, in which it can take over 1.5 hours but never
return.

int main(int argc, char** argv)
{
if (argc != 2) {
    fprintf(stderr, "Usage: %s <rsa-keypair.sp>\n", argv[0]);
    xerr1("Invalid arguments.");
}

gcrypt_init();

gcry_error_t err = 0;
gcry_sexp_t rsa_parms;
gcry_sexp_t rsa_keypair;

err &= gcry_sexp_build(&rsa_parms, NULL, "(genkey (rsa (nbits 4:2048)))");
if (err) {
    xerr1("gcrypt: failed to create rsa params");
}

err &= gcry_pk_genkey(&rsa_keypair, rsa_parms); <------- This function call
if (err) {
    xerr1("gcrypt: failed to create rsa key pair");
}

char* fname = argv[1];
err = gcrypt_sexp_to_file(fname, rsa_keypair, 1 << 16);

    printf("i am here3\n");
gcry_sexp_release(rsa_keypair);
gcry_sexp_release(rsa_parms);

return err;
}

I am aware that this function can take a few minutes. Your computer needs
to gather random entropy.. However, I can hardly believe it could take
almost 2 hours without return/throw exception...

I am using a 32-bit Ubuntu 14.04, inside a virtualbox VM instance. Am I
doing anything wrong here?
-------------- next part --------------
An HTML attachment was scrubbed...
URL: </pipermail/attachments/20160905/e56b7bd3/attachment.html>


More information about the Gcrypt-devel mailing list