There have been a few reports of failures in rsa_oaep_test that are
not actually related to OAEP. With this patch, the (old) PKCS#1 v1.5
encryption is tested as well as OAEP. The interoperation with RSAREF
is also improved.
Since it is no longer restricted to OAEP, I'd suggest to rename
rsa_oaep_test.c to rsatest.c.
Index: openssl/rsaref/rsaref.c
===================================================================
RCS file: /e/openssl/cvs/openssl/rsaref/rsaref.c,v
retrieving revision 1.3
diff -u -r1.3 rsaref.c
--- openssl/rsaref/rsaref.c 1999/03/25 07:49:33 1.3
+++ openssl/rsaref/rsaref.c 1999/04/08 13:48:27
@@ -283,6 +283,11 @@
int i,outlen= -1;
RSArefPrivateKey RSAkey;
+ if (padding != RSA_PKCS1_PADDING)
+ {
+ RSAREFerr(RSAREF_F_RSA_REF_PRIVATE_ENCRYPT,
+RSA_R_UNKNOWN_PADDING_TYPE);
+ goto err;
+ }
if (!RSAref_Private_eay2ref(rsa,&RSAkey))
goto err;
if ((i=RSAPrivateEncrypt(to,&outlen,from,len,&RSAkey)) != 0)
@@ -328,9 +333,12 @@
RSARandomState rnd;
unsigned char buf[16];
- if (padding == RSA_PKCS1_OAEP_PADDING)
+ if (padding != RSA_PKCS1_PADDING && padding != RSA_SSLV23_PADDING)
+ {
+ RSAREFerr(RSAREF_F_RSA_REF_PUBLIC_ENCRYPT, RSA_R_UNKNOWN_PADDING_TYPE);
goto err;
-
+ }
+
R_RandomInit(&rnd);
R_GetRandomBytesNeeded((unsigned int *)&i,&rnd);
while (i > 0)
Index: openssl/crypto/rsa/rsa_oaep_test.c
===================================================================
RCS file: /e/openssl/cvs/openssl/crypto/rsa/rsa_oaep_test.c,v
retrieving revision 1.5
diff -u -r1.5 rsa_oaep_test.c
--- openssl/crypto/rsa/rsa_oaep_test.c 1999/03/25 07:49:32 1.5
+++ openssl/crypto/rsa/rsa_oaep_test.c 1999/04/08 14:57:28
@@ -1,8 +1,10 @@
/* test vectors from p1ovect1.txt */
#include <stdio.h>
+#include <string.h>
#include "e_os.h"
#include "rsa.h"
+#include "err.h"
#define SetKey \
key->n = BN_bin2bn(n, sizeof(n)-1, key->n); \
@@ -182,6 +184,15 @@
SetKey;
}
+int pad_unknown()
+{
+ unsigned long l;
+ while ((l = ERR_get_error()) != 0)
+ if (ERR_GET_REASON(l) == RSA_R_UNKNOWN_PADDING_TYPE)
+ return(1);
+ return(0);
+}
+
int main()
{
int err=0;
@@ -195,11 +206,6 @@
int clen = 0;
int num;
-#ifdef RSAref
- printf("No OAEP support with RSAref - skipping test\n");
- return 0;
-#endif
-
plen = sizeof(ptext_ex) - 1;
for (v = 0; v < 3; v++)
@@ -218,10 +224,36 @@
}
num = RSA_public_encrypt(plen, ptext_ex, ctext, key,
+ RSA_PKCS1_PADDING);
+ if (num != clen)
+ {
+ printf("PKCS#1 v1.5 encryption failed!\n");
+ err=1;
+ goto oaep;
+ }
+
+ num = RSA_private_decrypt(num, ctext, ptext, key,
+ RSA_PKCS1_PADDING);
+ if (num != plen || memcmp(ptext, ptext_ex, num) != 0)
+ {
+ printf("PKCS#1 v1.5 decryption failed!\n");
+ err=1;
+ }
+ else
+ printf("PKCS #1 v1.5 encryption/decryption ok\n");
+
+ oaep:
+ ERR_clear_error();
+ num = RSA_public_encrypt(plen, ptext_ex, ctext, key,
RSA_PKCS1_OAEP_PADDING);
+ if (num == -1 && pad_unknown())
+ {
+ printf("No OAEP support\n");
+ goto next;
+ }
if (num != clen)
{
- printf("Encryption failed!\n");
+ printf("OAEP encryption failed!\n");
err=1;
goto next;
}
@@ -230,14 +262,14 @@
RSA_PKCS1_OAEP_PADDING);
if (num != plen || memcmp(ptext, ptext_ex, num) != 0)
{
- printf("Decryption failed!\n");
+ printf("OAEP decryption failed!\n");
err=1;
goto next;
}
if (memcmp(ctext, ctext_ex, num) == 0)
{
- printf("Vector %d passed!\n", v);
+ printf("OAEP test vector %d passed!\n", v);
goto next;
}
@@ -249,12 +281,11 @@
if (num != plen || memcmp(ptext, ptext_ex, num) != 0)
{
- printf("Decryption failed!\n");
+ printf("OAEP decryption (test vector data) failed!\n");
err=1;
}
else
- printf("Encryption/decryption successful!\n");
-
+ printf("OAEP encryption/decryption ok\n");
next:
RSA_free(key);
}
______________________________________________________________________
OpenSSL Project http://www.openssl.org
Development Mailing List [EMAIL PROTECTED]
Automated List Manager [EMAIL PROTECTED]