summaryrefslogtreecommitdiffstats
path: root/crypto
diff options
context:
space:
mode:
authorDr. Stephen Henson <steve@openssl.org>2006-04-09 12:42:09 +0000
committerDr. Stephen Henson <steve@openssl.org>2006-04-09 12:42:09 +0000
commit4a3dc3c0e34d44590b6565f8a8f5f4f5192df988 (patch)
tree8d2584d9ec28b5222f9f19359b49ecfa1d66569d /crypto
parenta2318e86bdb3dc5fc2d17a12d3875964eedef424 (diff)
Add RSA ctrl for padding mode, add ctrl support in pkeyutl.
Diffstat (limited to 'crypto')
-rw-r--r--crypto/evp/evp.h3
-rw-r--r--crypto/evp/pmeth_lib.c3
-rw-r--r--crypto/rsa/rsa.h6
-rw-r--r--crypto/rsa/rsa_pmeth.c49
4 files changed, 59 insertions, 2 deletions
diff --git a/crypto/evp/evp.h b/crypto/evp/evp.h
index 06535510ca..07bcb50ad0 100644
--- a/crypto/evp/evp.h
+++ b/crypto/evp/evp.h
@@ -917,8 +917,11 @@ void EVP_PKEY_asn1_set_ctrl(EVP_PKEY_ASN1_METHOD *ameth,
const EVP_PKEY_METHOD *EVP_PKEY_meth_find(int type, ENGINE *e);
EVP_PKEY_CTX *EVP_PKEY_CTX_new(EVP_PKEY *pkey);
void EVP_PKEY_CTX_free(EVP_PKEY_CTX *ctx);
+
int EVP_PKEY_CTX_ctrl(EVP_PKEY_CTX *ctx, int keytype, int optype,
int cmd, int p1, void *p2);
+int EVP_PKEY_CTX_ctrl_str(EVP_PKEY_CTX *ctx, const char *type,
+ const char *value);
int EVP_PKEY_sign_init(EVP_PKEY_CTX *ctx);
diff --git a/crypto/evp/pmeth_lib.c b/crypto/evp/pmeth_lib.c
index 9ca351a53e..7c36395696 100644
--- a/crypto/evp/pmeth_lib.c
+++ b/crypto/evp/pmeth_lib.c
@@ -171,7 +171,8 @@ int EVP_PKEY_CTX_ctrl(EVP_PKEY_CTX *ctx, int keytype, int optype,
}
-int EVP_PKEY_CTX_ctrl_str(EVP_PKEY_CTX *ctx, char *name, char *value)
+int EVP_PKEY_CTX_ctrl_str(EVP_PKEY_CTX *ctx,
+ const char *name, const char *value)
{
if (!ctx || !ctx->pmeth || !ctx->pmeth->ctrl)
{
diff --git a/crypto/rsa/rsa.h b/crypto/rsa/rsa.h
index 6a9062b27e..2b03ede5fd 100644
--- a/crypto/rsa/rsa.h
+++ b/crypto/rsa/rsa.h
@@ -192,6 +192,12 @@ struct rsa_st
* be used for all exponents.
*/
+#define EVP_PKEY_CTX_set_rsa_padding(ctx, pad) \
+ EVP_PKEY_CTX_ctrl(ctx, EVP_PKEY_RSA, EVP_PKEY_CTRL_RSA_PADDING, \
+ pad, NULL)
+
+#define EVP_PKEY_CTRL_RSA_PADDING 1
+
#define RSA_PKCS1_PADDING 1
#define RSA_SSLV23_PADDING 2
#define RSA_NO_PADDING 3
diff --git a/crypto/rsa/rsa_pmeth.c b/crypto/rsa/rsa_pmeth.c
index 7fe9e52a7d..5401b0544a 100644
--- a/crypto/rsa/rsa_pmeth.c
+++ b/crypto/rsa/rsa_pmeth.c
@@ -151,6 +151,52 @@ static int pkey_rsa_decrypt(EVP_PKEY_CTX *ctx, unsigned char *out, int *outlen,
return 1;
}
+static int pkey_rsa_ctrl(EVP_PKEY_CTX *ctx, int type, int p1, void *p2)
+ {
+ RSA_PKEY_CTX *rctx = ctx->data;
+ switch (type)
+ {
+
+ case EVP_PKEY_CTRL_RSA_PADDING:
+ /* TODO: add PSS support */
+ if ((p1 >= RSA_PKCS1_PADDING) && (p1 <= RSA_X931_PADDING))
+ {
+ rctx->pad_mode = p1;
+ return 1;
+ }
+ return 0;
+
+ default:
+ return -2;
+
+ }
+ }
+
+static int pkey_rsa_ctrl_str(EVP_PKEY_CTX *ctx,
+ const char *type, const char *value)
+ {
+ if (!strcmp(type, "rsa_padding_mode"))
+ {
+ int pm;
+ if (!value)
+ return 0;
+ if (!strcmp(value, "pkcs1"))
+ pm = RSA_PKCS1_PADDING;
+ else if (!strcmp(value, "sslv23"))
+ pm = RSA_SSLV23_PADDING;
+ else if (!strcmp(value, "none"))
+ pm = RSA_NO_PADDING;
+ else if (!strcmp(value, "oeap"))
+ pm = RSA_PKCS1_OAEP_PADDING;
+ else if (!strcmp(value, "x931"))
+ pm = RSA_X931_PADDING;
+ else
+ return -2;
+ return pkey_rsa_ctrl(ctx, EVP_PKEY_CTRL_RSA_PADDING, pm, NULL);
+ }
+ return -2;
+ }
+
const EVP_PKEY_METHOD rsa_pkey_meth =
{
EVP_PKEY_RSA,
@@ -179,7 +225,8 @@ const EVP_PKEY_METHOD rsa_pkey_meth =
0,
pkey_rsa_decrypt,
- 0,0
+ pkey_rsa_ctrl,
+ pkey_rsa_ctrl_str
};