Implement encrypt/decrypt using RSA.
authorDr. Stephen Henson <steve@openssl.org>
Sat, 8 Apr 2006 13:02:04 +0000 (13:02 +0000)
committerDr. Stephen Henson <steve@openssl.org>
Sat, 8 Apr 2006 13:02:04 +0000 (13:02 +0000)
apps/pkeyutl.c
crypto/rsa/rsa_pmeth.c

index 0c61867..5db0a36 100644 (file)
@@ -163,8 +163,8 @@ int MAIN(int argc, char **argv)
                        hexdump = 1;
                else if(!strcmp(*argv, "-sign"))
                        pkey_op = EVP_PKEY_OP_SIGN;
-               else if(!strcmp(*argv, "-verify"))
-                       pkey_op = EVP_PKEY_OP_VERIFY;
+               else if(!strcmp(*argv, "-verifyrecover"))
+                       pkey_op = EVP_PKEY_OP_VERIFYRECOVER;
                else if(!strcmp(*argv, "-rev"))
                        rev = 1;
                else if(!strcmp(*argv, "-encrypt"))
index 78143a6..7fe9e52 100644 (file)
@@ -125,6 +125,31 @@ static int pkey_rsa_verifyrecover(EVP_PKEY_CTX *ctx,
        return 1;
        }
 
+static int pkey_rsa_encrypt(EVP_PKEY_CTX *ctx, unsigned char *out, int *outlen,
+                                        unsigned char *in, int inlen)
+       {
+       int ret;
+       RSA_PKEY_CTX *rctx = ctx->data;
+       ret = RSA_public_encrypt(inlen, in, out, ctx->pkey->pkey.rsa,
+                                                       rctx->pad_mode);
+       if (ret < 0)
+               return ret;
+       *outlen = ret;
+       return 1;
+       }
+
+static int pkey_rsa_decrypt(EVP_PKEY_CTX *ctx, unsigned char *out, int *outlen,
+                                        unsigned char *in, int inlen)
+       {
+       int ret;
+       RSA_PKEY_CTX *rctx = ctx->data;
+       ret = RSA_private_decrypt(inlen, in, out, ctx->pkey->pkey.rsa,
+                                                       rctx->pad_mode);
+       if (ret < 0)
+               return ret;
+       *outlen = ret;
+       return 1;
+       }
 
 const EVP_PKEY_METHOD rsa_pkey_meth = 
        {
@@ -143,6 +168,18 @@ const EVP_PKEY_METHOD rsa_pkey_meth =
        0,0,
 
        0,
-       pkey_rsa_verifyrecover
+       pkey_rsa_verifyrecover,
+
+
+       0,0,0,0,
+
+       0,
+       pkey_rsa_encrypt,
+
+       0,
+       pkey_rsa_decrypt,
+
+       0,0
+
 
        };