Performance issues with gcry_randomize

DeKaTaR The Serious dekatar at yahoo.de
Wed Oct 20 20:54:51 CEST 2010


Hi,
I just want to ask if its normal that gcry_randomize in combination with GCRY_VERY_STRONG_RANDOM is extreme slow or its just my fault?

#include <stdio.h>
#include <stdlib.h>
#include <gcrypt.h>

void init(){
     if (!gcry_check_version (GCRYPT_VERSION)){
        printf("libgcrypt version mismatch!!!\n");
        exit (1);
    }
    if (gcry_control(GCRYCTL_SELFTEST) != 0) {
        printf("libgrypt Selftest failed!!!\n");
        exit(1);
    }
    if (gcry_control(GCRYCTL_ENABLE_M_GUARD) != 0) {
        printf("Enable Memory Guard failed!!!\n");
        exit(1);
    }

    if( gcry_control (GCRYCTL_SUSPEND_SECMEM_WARN) !=0){
        printf("Suspending secure Memory Warnings failed!!!\n");
        exit(1);
    }
    if(gcry_control(GCRYCTL_USE_SECURE_RNDPOOL)!=0){
        printf("Option \"Use secure Randompool\" failed!!!\n");
        exit(1);
    }
    gcry_control (GCRYCTL_TERM_SECMEM);
    if(gcry_control(GCRYCTL_INIT_SECMEM,16384, 0)!=0){
        printf("Initialization of Secure Memory failed!!!\n");
        exit(1);
    }
    if(gcry_control(GCRYCTL_RESUME_SECMEM_WARN)!=0){
        printf("Resuming secure Memory Warning failed!!!\n");
        exit(1);
    }

    if(gcry_control (GCRYCTL_INITIALIZATION_FINISHED, 0) != 0 ){
        printf("Finishing the Initialization of libgrypt failed!");
        exit(1);
    }
}
void clean(){
        if(gcry_control (GCRYCTL_TERM_SECMEM) != 0 ){
        printf("Cleaning secure Memory of libgrypt failed!");
        exit(1);
    }
}



int main()
{
    init();
    unsigned char buffer[512];
    gcry_randomize (buffer,512,GCRY_VERY_STRONG_RANDOM);
    return 0;
} 

The runtime for this Code is between 3 and 5 Minutes, which looks like that something went terribly wrong. The CPU (Dual Core with 3.5 Ghz) idles ,except of some spikes, the whole time. 

What can I do Speed this up?

BTW Same issue with generating RSA-2048 Keys :/

MFG
Thomas





More information about the Gcrypt-devel mailing list