Add test for RSA encryption.

git-svn-id: svn://svn.h5l.se/heimdal/trunk/heimdal@16491 ec53bebd-3082-4978-b11e-865c3cabbd6b
This commit is contained in:
Love Hörnquist Åstrand
2006-01-08 23:09:07 +00:00
parent e1c122af2b
commit f18d723991

View File

@@ -134,6 +134,10 @@ main(int argc, char **argv)
RSA_set_method(rsa, ENGINE_get_RSA(engine));
/*
* try rsa signing
*/
memcpy(buf, "hejsan", 7);
keylen = RSA_private_encrypt(7, buf, buf, rsa, RSA_PKCS1_PADDING);
if (keylen <= 0)
@@ -149,6 +153,25 @@ main(int argc, char **argv)
if (memcmp(buf, "hejsan", 7) != 0)
errx(1, "string not the same after decryption");
/*
* try rsa encryption
*/
memcpy(buf, "hejsan", 7);
keylen = RSA_public_encrypt(7, buf, buf, rsa, RSA_PKCS1_PADDING);
if (keylen <= 0)
errx(1, "failed to public encrypt");
keylen = RSA_private_decrypt(keylen, buf, buf, rsa, RSA_PKCS1_PADDING);
if (keylen <= 0)
errx(1, "failed to private decrypt");
if (keylen != 7)
errx(1, "output buffer not same length");
if (memcmp(buf, "hejsan", 7) != 0)
errx(1, "string not the same after decryption");
RSA_free(rsa);
printf("rsa test passed\n");