Hemant Jain schrieb:
>
> Holger,
> Here is the stack trace, if that helps:
> error:0407106B::lib(4) : func(113) : reason(107)
> error:04065072::lib(4) : func(101) : reason(114)
This means padding check failed (reason 107) in function
private decrypt (func 101) because of wrong block type
(reason 107) in function padding check (func 113).
I can't guess what went wrong, it would be necessary to
examine the key itsself. Try to test the key with the
little test program in the appendix. (Wouldn't it be a
good idea to include it as "openssl rsa -verify"?)
BTW at least during debugging you should load the
erro srtings to make this error messages easier to
understand. You can do this with ERR_load_crypto_strings();
Holger
-----snip----------------
#include <stdio.h>
#include <stdlib.h>
#include <string.h>
#include <limits.h>
#include <ctype.h>
#include "/usr/local/ssl/include/err.h"
#include "/usr/local/ssl/include/rsa.h"
#include "/usr/local/ssl/include/bn.h"
#ifdef min
#undef min
#endif
#define min(a,b) ((a) < (b)? (a) : (b))
int BN_write(FILE *fp, BIGNUM *a);
int
main(int argc, char **argv)
{
char *filename;
FILE *f;
char b1[1024], b2[1024], b3[1024];
int b1len, b2len, b3len;
RSA *rsa;
unsigned long ERR_no;
BIGNUM *bn;
char *pcTemp;
memset(b1, 0, sizeof(b1));
memset(b2, 0, sizeof(b2));
memset(b3, 0, sizeof(b3));
if (argc != 2)
{
printf("usage: %s filename\n", argv[0]);
exit(-1);
}
filename = argv[1];
ERR_load_crypto_strings();
if (!(rsa = RSA_new()))
{
printf("RSA_new rsa failed\n");
while ((ERR_no = ERR_get_error()))
printf("%s\n", ERR_error_string(ERR_no, NULL));
return(-1);
}
if (!(bn = BN_new()))
{
printf("BN_new bn failed\n");
while ((ERR_no = ERR_get_error()))
printf("%s\n", ERR_error_string(ERR_no, NULL));
return(-1);
}
f = fopen(filename, "r");
if (f == NULL)
{
perror("fopen:");
return(-1);
}
/* insert here your code to read the key from a file */
printf("RSA Key (%i Bits)\n", BN_num_bits(rsa->n));
printf("MODULUS\n");
pcTemp = BN_bn2hex(rsa->n);
printf("%s\n", pcTemp);
free(pcTemp);
printf("PRIVATE EXPONENT\n");
pcTemp = BN_bn2hex(rsa->d);
printf("%s\n", pcTemp);
free(pcTemp);
printf("PUBLIC EXPONENT\n");
pcTemp = BN_bn2hex(rsa->e);
printf("%s\n", pcTemp);
free(pcTemp);
/* generate test value */
if (BN_rshift(bn, rsa->n, 8) != 1)
{
printf("BN_rshift1 rsa failed\n");
while ((ERR_no = ERR_get_error()))
printf("%s\n", ERR_error_string(ERR_no, NULL));
return(-1);
}
b1len = BN_bn2bin(bn, b1);
/* make the padding with leading zero */
memmove(b1+1, b1, b1len);
b1[0] = 0;
b1len++;
/* compute signature */
b2len = RSA_private_encrypt(b1len, b1, b2, rsa, RSA_NO_PADDING);
if (b2len == -1)
{
printf("RSA_private_encrypt failed\n");
while ((ERR_no = ERR_get_error()))
printf("%s\n", ERR_error_string(ERR_no, NULL));
return(-1);
}
/* check signature */
if ((b3len = RSA_public_decrypt(b2len, b2, b3, rsa, RSA_NO_PADDING))
== -1)
{
printf("RSA_public_decrypt failed\n");
while ((ERR_no = ERR_get_error()))
printf("%s\n", ERR_error_string(ERR_no, NULL));
return(-1);
}
if (!(bn = BN_bin2bn((unsigned char*) b3, b3len, NULL)))
{
printf("BN_bin2bn failed\n");
while ((ERR_no = ERR_get_error()))
printf("%s\n", ERR_error_string(ERR_no, NULL));
return(-1);
}
/* verify the result */
if (BN_rshift(rsa->n, rsa->n, 8) != 1)
{
printf("BN_rshift1 rsa failed\n");
while ((ERR_no = ERR_get_error()))
printf("%s\n", ERR_error_string(ERR_no, NULL));
return(-1);
}
if (BN_cmp(rsa->n, bn) == 0)
{
printf("Test passed\n");
}
else
{
printf("Test not passed\n");
}
return(0);
}
-------snip-----------------
> Hemant
>
> -----Original Message-----
> From: [EMAIL PROTECTED]
> [mailto:[EMAIL PROTECTED]]On Behalf Of Holger Reif
> Sent: Wednesday, June 23, 1999 11:48 PM
> To: [EMAIL PROTECTED]
> Subject: Re: rsa_oaep_test
>
> Which error occured? I suppose you read all the erros from
> the error stack and know what exactly happend.
>
> Hemant Jain schrieb:
> >
> > Hi All,
> >
> > I read the private key/public key from my store and copied its contents
> > to variables n,e,d,etc. in the rsa_oaep_test.c as another key (key4).
> > While the test program works fine for encryption and
> > decryption for key1, key2 and key3, I get an error while
> > decrypting with my private key.
--
Holger Reif Tel.: +49 361 74707-0
SmartRing GmbH Fax.: +49 361 7470720
Europaplatz 5 [EMAIL PROTECTED]
D-99091 Erfurt WWW.SmartRing.de
______________________________________________________________________
OpenSSL Project http://www.openssl.org
User Support Mailing List [EMAIL PROTECTED]
Automated List Manager [EMAIL PROTECTED]