i2d_RSAPublicKey( RSA, NULL ) is to be used to get the size of an RSA
structure.
The following code shows that it does not return the correct value.
#define _GNU_SOURCE
#include <string.h>
#include <stdio.h>
#include <stdlib.h>
#include <openssl/rsa.h>
#define RSA_KEY_LENGTH 1024
RSA *My_RSA;
RSA *Pri_RSA;
RSA *Pub_RSA;
int RC, Size, Len, Run;
unsigned char *Key, *Ptr;
int
main( ) {
My_RSA = RSA_generate_key( 1024, 65537, NULL, NULL );
RSA_blinding_on( My_RSA, NULL );
Size = RSA_KEY_LENGTH;
Key = Ptr = malloc( Size );
Len = i2d_RSAPublicKey( My_RSA, NULL );
Pri_RSA = d2i_RSAPrivateKey( NULL, (const unsigned char **)
&Key, Len );
printf("Size: %d, Len: %d, RSA: %d\n", Size, Len, Pri_RSA );
RC = i2d_RSAPrivateKey( My_RSA, &Ptr );
Pri_RSA = d2i_RSAPrivateKey( NULL, (const unsigned char **)
&Key, RC );
printf("Size: %d, Len: %d, RSA: %d\n", Size, RC, Pri_RSA );
return 1; }
This is the output:
rsakey
Size: 1024, Len: 140, RSA: 0
Size: 1024, Len: 608, RSA: 154555560
If you use the value returned by the call for the malloc, it will seg fault.
--
William Estrada
[EMAIL PROTECTED]
Mt-Umunhum-Wireless.net ( http://Mt-Umunhum-Wireless.net )
Ymessenger: MrUmunhum
______________________________________________________________________
OpenSSL Project http://www.openssl.org
Development Mailing List openssl-dev@openssl.org
Automated List Manager [EMAIL PROTECTED]