Hi,

I'm having problems RSA-signing a previously-digested
message.

I'm trying to RSA-encrypt (with my RSA private key) a
very short binary string. (The plaintext binary string
is actually an MD5 hash, but previously stored, not
generated on-the-fly, so the hashing-context has not
been preserved.)

I read through the OpenSSL-dev list discussions on
this topic. I tried using RSA_sign() but that resulted
in a segmentation fault. Then I tried using
RSA_private_encrypt(), but that too gave the same
segmentation fault.

My modulus is 1024-bit, my plaintext is 128-bit. I
want to use raw RSA, hence pad = RSA_NO_PADDING.
I don't want to use EVP at all if I can help it. Nor
BIO.
I don't want to preserve any Algorithm Identifier
information, neither for the hashing nor for the
encryption (because I know they are MD5 and
RSA-1024-bit, respectively).

I've appended my code to this email. Could you please
tell me where I'm making my mistakes? Could you please
point me to working code for RSA-signing an
already-stored digest?  And also for verifying that
signature?

Thanks very much, in advance.

Amodhini U

[EMAIL PROTECTED]


/* The code: */
#include <stdio.h>
#include <string.h>
#include <openssl/rsa.h>
#include <openssl/evp.h>
#include <openssl/objects.h>
#include <openssl/x509.h>
#include <openssl/err.h>
#include <openssl/pem.h>

int main(int argc, char **argv)
{
   FILE *fp;
   EVP_PKEY   *privatekey;

   unsigned char *rsa_in = "0123456789abcdef";
   int rsa_inlen = 17;
   unsigned char pad = RSA_NO_PADDING;
   unsigned char *rsa_out = NULL;
   int rsa_outlen = 0;
   RSA   *rsa;
   rsa = RSA_new();
        
   /* Read the private key */
   fp = fopen("/path/to/my/privatekey.pem", "r");
   if (fp == NULL)
      printf("Error opening privatekey.pem file!\n");
        
   privatekey = PEM_read_RSAPrivateKey(fp, &rsa, NULL,
NULL);
   fclose(fp);

   if (privatekey == NULL)
      printf("Error reading private key!\n");

   rsa_outlen  = RSA_private_encrypt(rsa_inlen,
rsa_in, rsa_out, privatekey, pad);
   if (rsa_outlen == -1)
      ERR_print_errors_fp(stderr);
                
   RSA_free(rsa);
   return 0;
}


__________________________________________________
Do You Yahoo!?
Yahoo! GeoCities - quick and easy web site hosting, just $8.95/month.
http://geocities.yahoo.com/ps/info1
______________________________________________________________________
OpenSSL Project                                 http://www.openssl.org
Development Mailing List                       [EMAIL PROTECTED]
Automated List Manager                           [EMAIL PROTECTED]

Reply via email to