summaryrefslogtreecommitdiffstats
path: root/crypto/evp/pmeth_lib.c
diff options
context:
space:
mode:
authorDr. Stephen Henson <steve@openssl.org>2016-03-01 14:47:15 +0000
committerDr. Stephen Henson <steve@openssl.org>2016-03-02 20:57:32 +0000
commit99119000add47e4d1d9241f4e76f57d98439a766 (patch)
tree03cebabb43a2985c6ea65a16055a0e0a99a866dd /crypto/evp/pmeth_lib.c
parente9b1c42f753fcb90eee70a12b0ac832951d7ac0b (diff)
EVP_PKEY_CTX utility functions.
Utility functions to pass a string or hex string to EVP_PKEY_CTX_ctrl(). Reviewed-by: Rich Salz <rsalz@openssl.org>
Diffstat (limited to 'crypto/evp/pmeth_lib.c')
-rw-r--r--crypto/evp/pmeth_lib.c29
1 files changed, 29 insertions, 0 deletions
diff --git a/crypto/evp/pmeth_lib.c b/crypto/evp/pmeth_lib.c
index 72baaa988d..44a6a05249 100644
--- a/crypto/evp/pmeth_lib.c
+++ b/crypto/evp/pmeth_lib.c
@@ -63,8 +63,10 @@
# include <openssl/engine.h>
#endif
#include <openssl/evp.h>
+#include <openssl/x509v3.h>
#include "internal/asn1_int.h"
#include "internal/evp_int.h"
+#include "internal/numbers.h"
typedef int sk_cmp_fn_type(const char *const *a, const char *const *b);
@@ -381,6 +383,33 @@ int EVP_PKEY_CTX_ctrl_str(EVP_PKEY_CTX *ctx,
return ctx->pmeth->ctrl_str(ctx, name, value);
}
+/* Utility functions to send a string of hex string to a ctrl */
+
+int EVP_PKEY_CTX_str2ctrl(EVP_PKEY_CTX *ctx, int cmd, const char *str)
+{
+ size_t len;
+
+ len = strlen(str);
+ if (len > INT_MAX)
+ return -1;
+ return ctx->pmeth->ctrl(ctx, cmd, len, (void *)str);
+}
+
+int EVP_PKEY_CTX_hex2ctrl(EVP_PKEY_CTX *ctx, int cmd, const char *hex)
+{
+ unsigned char *bin;
+ long binlen;
+ int rv = -1;
+
+ bin = string_to_hex(hex, &binlen);
+ if (bin == NULL)
+ return 0;
+ if (binlen <= INT_MAX)
+ rv = ctx->pmeth->ctrl(ctx, cmd, binlen, bin);
+ OPENSSL_free(bin);
+ return rv;
+}
+
int EVP_PKEY_CTX_get_operation(EVP_PKEY_CTX *ctx)
{
return ctx->operation;