提交 8cd44e36 编写于 作者: D Dr. Stephen Henson

Implement encrypt/decrypt using RSA.

上级 07e970c7
......@@ -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"))
......
......@@ -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
};
Markdown is supported
0% .
You are about to add 0 people to the discussion. Proceed with caution.
先完成此消息的编辑!
想要评论请 注册