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:
@@ -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");
|
||||
|
Reference in New Issue
Block a user