Discussion:
RSA_generate_key
krishnamurthy santhanam
2010-08-02 19:29:12 UTC
Permalink
Hi,

i am new to OpenSSL..i have to use RSA_generate key function to generate
key..below is the program and outcome..is this the way to generate key?

#include<stdio.h>
#include<openssl/rsa.h>
#include<string.h>
int main()
{
char *plain="Sample text"; //Sample text (plain text) to Encrypt/Decrypt
char *ciphertext;
printf("%s\n",plain);
// Generate RSA key
RSA *rsa1= RSA_generate_key(1024,65537,NULL,NULL);
// RSA_size() will determine how much memory must be allocated for an
if(rsa1==NULL) {
printf("NO RSA!\n\n");
ERR_load_crypto_strings();
ERR_print_errors_fp(stdout);
}
else
{
printf("RSA OK!\n");
}
ciphertext = (char *)malloc(RSA_size(rsa1));
printf("rsa key = %d\n",rsa1);
printf("RSA size = %d\n",RSA_size(rsa1));
RSA_free(rsa1);
}

$ gcc -o rsa1 rsa1.c -lcrypto

Output
---------
$ ./rsa1
Sample text
RSA OK!
rsa key = 473608208
RSA size = 128

Please correct me if i am missing anything ..

kris
Michael S. Zick
2010-08-02 19:45:51 UTC
Permalink
Post by krishnamurthy santhanam
Hi,
i am new to OpenSSL..i have to use RSA_generate key function to generate
key..below is the program and outcome..is this the way to generate key?
#include<stdio.h>
#include<openssl/rsa.h>
#include<string.h>
int main()
{
char *plain="Sample text"; //Sample text (plain text) to Encrypt/Decrypt
char *ciphertext;
printf("%s\n",plain);
// Generate RSA key
RSA *rsa1= RSA_generate_key(1024,65537,NULL,NULL);
// RSA_size() will determine how much memory must be allocated for an
if(rsa1==NULL) {
printf("NO RSA!\n\n");
ERR_load_crypto_strings();
ERR_print_errors_fp(stdout);
}
else
{
printf("RSA OK!\n");
}
ciphertext = (char *)malloc(RSA_size(rsa1));
printf("rsa key = %d\n",rsa1);
printf("RSA size = %d\n",RSA_size(rsa1));
RSA_free(rsa1);
}
$ gcc -o rsa1 rsa1.c -lcrypto
Output
---------
$ ./rsa1
Sample text
RSA OK!
rsa key = 473608208
RSA size = 128
Times 8 bits per octet == 1024 bits as requested.
Post by krishnamurthy santhanam
Please correct me if i am missing anything ..
Does your %d recognize a number that is 128 bytes long?

Mike
Post by krishnamurthy santhanam
kris
______________________________________________________________________
OpenSSL Project http://www.openssl.org
User Support Mailing List openssl-users-MCmKBN63+***@public.gmane.org
Automated List Manager majordomo-MCmKBN63+***@public.gmane.org
krishnamurthy santhanam
2010-08-03 04:10:03 UTC
Permalink
yes ..i am not able to find the 128 byte RSA key.. how should get
those information?

kris
Post by Michael S. Zick
Post by krishnamurthy santhanam
Hi,
i am new to OpenSSL..i have to use RSA_generate key function to generate
key..below is the program and outcome..is this the way to generate key?
#include<stdio.h>
#include<openssl/rsa.h>
#include<string.h>
int main()
{
char *plain="Sample text"; //Sample text (plain text) to Encrypt/Decrypt
char *ciphertext;
printf("%s\n",plain);
// Generate RSA key
RSA *rsa1= RSA_generate_key(1024,65537,NULL,NULL);
// RSA_size() will determine how much memory must be allocated for an
if(rsa1==NULL) {
printf("NO RSA!\n\n");
ERR_load_crypto_strings();
ERR_print_errors_fp(stdout);
}
else
{
printf("RSA OK!\n");
}
ciphertext = (char *)malloc(RSA_size(rsa1));
printf("rsa key = %d\n",rsa1);
printf("RSA size = %d\n",RSA_size(rsa1));
RSA_free(rsa1);
}
$ gcc -o rsa1 rsa1.c -lcrypto
Output
---------
$ ./rsa1
Sample text
RSA OK!
rsa key = 473608208
RSA size = 128
Times 8 bits per octet == 1024 bits as requested.
Post by krishnamurthy santhanam
Please correct me if i am missing anything ..
Does your %d recognize a number that is 128 bytes long?
Mike
Post by krishnamurthy santhanam
kris
______________________________________________________________________
OpenSSL Project http://www.openssl.org
sandeep kiran p
2010-08-03 06:31:44 UTC
Permalink
RSA is a structure containing the public modulus, private modulus, exponent
etc. Your rsa1 variable is a pointer to this structure. Why would you want
to print an address using %d?

-Sandeep

On Tue, Aug 3, 2010 at 9:40 AM, krishnamurthy santhanam <
Post by krishnamurthy santhanam
yes ..i am not able to find the 128 byte RSA key.. how should get
those information?
kris
Post by Michael S. Zick
Post by krishnamurthy santhanam
Hi,
i am new to OpenSSL..i have to use RSA_generate key function to generate
key..below is the program and outcome..is this the way to generate key?
#include<stdio.h>
#include<openssl/rsa.h>
#include<string.h>
int main()
{
char *plain="Sample text"; //Sample text (plain text) to Encrypt/Decrypt
char *ciphertext;
printf("%s\n",plain);
// Generate RSA key
RSA *rsa1= RSA_generate_key(1024,65537,NULL,NULL);
// RSA_size() will determine how much memory must be allocated for an
if(rsa1==NULL) {
printf("NO RSA!\n\n");
ERR_load_crypto_strings();
ERR_print_errors_fp(stdout);
}
else
{
printf("RSA OK!\n");
}
ciphertext = (char *)malloc(RSA_size(rsa1));
printf("rsa key = %d\n",rsa1);
printf("RSA size = %d\n",RSA_size(rsa1));
RSA_free(rsa1);
}
$ gcc -o rsa1 rsa1.c -lcrypto
Output
---------
$ ./rsa1
Sample text
RSA OK!
rsa key = 473608208
RSA size = 128
Times 8 bits per octet == 1024 bits as requested.
Post by krishnamurthy santhanam
Please correct me if i am missing anything ..
Does your %d recognize a number that is 128 bytes long?
Mike
Post by krishnamurthy santhanam
kris
______________________________________________________________________
OpenSSL Project http://www.openssl.org
Mounir IDRASSI
2010-08-03 07:33:27 UTC
Permalink
Hi,

I think you are confusing RSA with some sort of symmetric algorithm. RSA
is a public key algorithm that involves two parts : a public part
represented by the modulus and the public exponents, and the private part
which has two possible representations (one is modulus+private exponent
and the other is called CRT). The RSA size is actually the size of the
modulus.

I encourage you to read more about RSA before trying to use OpenSSL
resources for this.

Cheers,
--
Mounir IDRASSI
IDRIX
http://www.idrix.fr
Post by krishnamurthy santhanam
yes ..i am not able to find the 128 byte RSA key.. how should get
those information?
kris
On Tue, Aug 3, 2010 at 1:15 AM, Michael S. Zick
Post by krishnamurthy santhanam
Post by krishnamurthy santhanam
Hi,
i am new to OpenSSL..i have to use RSA_generate key function to
generate
Post by krishnamurthy santhanam
key..below is the program and outcome..is this the way to generate
key?
Post by krishnamurthy santhanam
#include<stdio.h>
#include<openssl/rsa.h>
#include<string.h>
int main()
{
char *plain="Sample text"; //Sample text (plain text) to
Encrypt/Decrypt
Post by krishnamurthy santhanam
char *ciphertext;
printf("%s\n",plain);
// Generate RSA key
RSA *rsa1= RSA_generate_key(1024,65537,NULL,NULL);
// RSA_size() will determine how much memory must be allocated for an
if(rsa1==NULL) {
printf("NO RSA!\n\n");
ERR_load_crypto_strings();
ERR_print_errors_fp(stdout);
}
else
{
printf("RSA OK!\n");
}
ciphertext = (char *)malloc(RSA_size(rsa1));
printf("rsa key = %d\n",rsa1);
printf("RSA size = %d\n",RSA_size(rsa1));
RSA_free(rsa1);
}
$ gcc -o rsa1 rsa1.c -lcrypto
Output
---------
$ ./rsa1
Sample text
RSA OK!
rsa key = 473608208
RSA size = 128
Times 8 bits per octet == 1024 bits as requested.
Post by krishnamurthy santhanam
Please correct me if i am missing anything ..
Does your %d recognize a number that is 128 bytes long?
Mike
Post by krishnamurthy santhanam
kris
______________________________________________________________________
OpenSSL Project http://www.openssl.org
______________________________________________________________________
OpenSSL Project http://www.openssl.org
User Support Mailing List openssl-users-MCmKBN63+***@public.gmane.org
Automated List Manager majordomo-MCmKBN63+***@public.gmane.org
krishnamurthy santhanam
2010-08-10 18:34:27 UTC
Permalink
Hi,



I am able to generate key. how to do seed PRNG before generating key?

is it enough to add rand_load_file("dev/random",1024) before generating key?
it would be helpful if u explain with one example?

#include<stdio.h>

#include<openssl/rsa.h>

#include<string.h>

int main()

{

char *plain="Sample text"; //Sample text (plain text) to Encrypt/Decrypt

char *ciphertext;

printf("%s\n",plain);

// Generate RSA key

RSA *rsa1= RSA_generate_key(1024,65537,NULL,NULL);

// RSA_size() will determine how much memory must be allocated for an

if(rsa1==NULL) {

printf("NO RSA!\n\n");

ERR_load_crypto_strings();

ERR_print_errors_fp(stdout);

}

else

{

printf("RSA OK!\n");

}

ciphertext = (char *)malloc(RSA_size(rsa1));

printf("rsa key = %d\n",rsa1);

printf("RSA size = %d\n",RSA_size(rsa1));

RSA_free(rsa1);

}



Thanks

Kris
Dr. Stephen Henson
2010-08-10 21:31:49 UTC
Permalink
Post by krishnamurthy santhanam
I am able to generate key. how to do seed PRNG before generating key?
The PRNG is seeded automatically using platform specific entropy. If it wasn't
they key would not be generated and you'd get a PRNG not seeded error.

Steve.
--
Dr Stephen N. Henson. OpenSSL project core developer.
Commercial tech support now available see: http://www.openssl.org
______________________________________________________________________
OpenSSL Project http://www.openssl.org
User Support Mailing List openssl-users-MCmKBN63+***@public.gmane.org
Automated List Manager majordomo-MCmKBN63+***@public.gmane.org
Loading...