Hello,
> I am a novice OpenSSL library user. Currently I am implementing code
> to generate a RSA key pair. Here 
> is a part of my code: 
> 
>        _time_get(&tim); 
>        RAND_add(&tim,sizeof(tim),0);
You should get seed from some PRNG source, but on Linux/Unix if this is
not enough OpenSSL library will seed yourself
reading /dev/urandom,EGD, ...
If there will be not enough seed data (32 bytes) RSA_generate_key() will
return error (there is check for seeded PRNG).

>        pMiSslCtx = MiSslInitEx( TLSv1_method(), true ); 
>        
>        rsa=RSA_generate_key(key_len,RSA_F4,NULLcb,NULL);
> 
> 
> my key_len is 2048. 
> 
> The code crashes in RSA_generate_key() function call, more
> particularly in probable_prime(). I am not sure what 
> I am doign wrong here. Any help would be highly apprecaited.
Some simple example attached.

Best regards,
-- 
Marek Marcola <[EMAIL PROTECTED]>
#include <stdio.h>

#include <openssl/bn.h>
#include <openssl/rsa.h>

int main()
{
	RSA *r;

	r = RSA_generate_key(2048,RSA_F4,NULL,NULL);

	if( r==NULL ) { 
		printf("Key failed");
		exit(1);
	} else {
		printf("public modulus (n):\n");
		printf("   %s\n",BN_bn2hex(r->n));

		printf("public exponent (e):\n");
		printf("   %s\n",BN_bn2hex(r->e));

		printf("private exponent (d):\n");
		printf("   %s\n",BN_bn2hex(r->d));

		printf("secret prime factor (p):\n");
		printf("   %s\n",BN_bn2hex(r->p));
		printf("secret prime factor (q):\n");
		printf("   %s\n",BN_bn2hex(r->q));

		printf("dmp1 [ d mod (p-1) ]:\n");
		printf("   %s\n",BN_bn2hex(r->dmp1));
		printf("dmq1 [ d mod (q-1) ]:\n");
		printf("   %s\n",BN_bn2hex(r->dmq1));

		printf("iqmp [ q^-1 mod p ]:\n");
		printf("   %s\n",BN_bn2hex(r->iqmp));
	}	

	printf("RSA SIZE: %d\n", RSA_size(r));

	return(0);
}

Reply via email to