From 8cd44e3630d2b02e2e29f15e152131c770c165a9 Mon Sep 17 00:00:00 2001 From: "Dr. Stephen Henson" Date: Sat, 8 Apr 2006 13:02:04 +0000 Subject: [PATCH] Implement encrypt/decrypt using RSA. --- apps/pkeyutl.c | 4 ++-- crypto/rsa/rsa_pmeth.c | 39 ++++++++++++++++++++++++++++++++++++++- 2 files changed, 40 insertions(+), 3 deletions(-) diff --git a/apps/pkeyutl.c b/apps/pkeyutl.c index 0c6186791e..5db0a362d1 100644 --- a/apps/pkeyutl.c +++ b/apps/pkeyutl.c @@ -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")) diff --git a/crypto/rsa/rsa_pmeth.c b/crypto/rsa/rsa_pmeth.c index 78143a6ee3..7fe9e52a7d 100644 --- a/crypto/rsa/rsa_pmeth.c +++ b/crypto/rsa/rsa_pmeth.c @@ -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 + }; -- 2.25.1