tags:

views:

39

answers:

1

Hi I'm trying to use libssl to get some EMSA_PSS_ENCODING through the function RSA_padding_add_PKCS1_type1 in libssl, but I can't find nor docs nor solutions, so this is the example code I've written:

#include <stdio.h>
#include <stdlib.h>
#include <string.h>
#include <openssl/rsa.h>
#include <openssl/err.h>

FILE *error_file;

int main()
{
int lSize;
const unsigned char *string1= (unsigned char *)"The pen is on the table"; 
unsigned char *stringa=NULL;
int num = 64;
if ((stringa = (unsigned char *)OPENSSL_malloc(num)) == NULL)
fprintf(stderr,"OPENSSL_malloc error\n");
    lSize = strlen((char *)string1);

fprintf(stdout,"string1 len is %u\n",lSize);
if(RSA_padding_add_PKCS1_type_1(stringa,num,string1,lSize) != 1)
    fprintf(stderr,"Error: RSA_PADDING error\n");

error_file = fopen("libssl.log", "w");
ERR_print_errors_fp(error_file);
fclose(error_file);
fprintf(stdout,(char *)stringa);
fprintf(stdout,"\n");

}

The problem is that I get no output in stringa, I think the function RSA_padding_add.. should be initialized, but I can't find how to do it in the few doc at the openssl site.

Thanks

A: 

See http://www.openssl.org/docs/crypto/RSA_padding_add_PKCS1_type_1.html . Try defining lSize to (int)strlen(string1) after string1 is set.

EDIT:

Allocate stringa.

unsigned char *stringa=malloc(num);

Yktula
Well actually I've yet read it, but it's of no help, it gives the way to use padding function but not how to initialize it, I keep getting my stringa void...
luiss
the malloc(num) doesn't help...but thanks anyway
luiss