diff options
author | Richard Levitte <levitte@openssl.org> | 2018-10-24 20:20:00 +0200 |
---|---|---|
committer | Richard Levitte <levitte@openssl.org> | 2018-10-29 13:35:19 +0100 |
commit | f842b6b2a4d7cbb9d22e4605c502b73f25bb6a7b (patch) | |
tree | 4b2f85bbde14b8df330370bf43d5178529c36c5a /crypto/evp | |
parent | Adapt test/evp_test.c to deal with available EVP_MACs (diff) | |
download | openssl-f842b6b2a4d7cbb9d22e4605c502b73f25bb6a7b.tar.xz openssl-f842b6b2a4d7cbb9d22e4605c502b73f25bb6a7b.zip |
Add convenience functions EVP_str2ctrl() and EVP_hex2ctrl()
These functions are generalizations of EVP_PKEY_CTX_str2ctrl() and
EVP_PKEY_CTX_hex2ctrl(). They will parse the value, and then pass the
parsed result and length to a callback that knows exactly how to pass
them on to a main _ctrl function, along with a context structure
pointer.
Reviewed-by: Paul Dale <paul.dale@oracle.com>
(Merged from https://github.com/openssl/openssl/pull/7393)
Diffstat (limited to 'crypto/evp')
-rw-r--r-- | crypto/evp/evp_lib.c | 27 |
1 files changed, 27 insertions, 0 deletions
diff --git a/crypto/evp/evp_lib.c b/crypto/evp/evp_lib.c index 1b3c9840c6..01c8939973 100644 --- a/crypto/evp/evp_lib.c +++ b/crypto/evp/evp_lib.c @@ -526,3 +526,30 @@ int EVP_CIPHER_CTX_test_flags(const EVP_CIPHER_CTX *ctx, int flags) { return (ctx->flags & flags); } + +int EVP_str2ctrl(int (*cb)(void *ctx, int cmd, void *buf, size_t buflen), + void *ctx, int cmd, const char *value) +{ + size_t len; + + len = strlen(value); + if (len > INT_MAX) + return -1; + return cb(ctx, cmd, (void *)value, len); +} + +int EVP_hex2ctrl(int (*cb)(void *ctx, int cmd, void *buf, size_t buflen), + void *ctx, int cmd, const char *hex) +{ + unsigned char *bin; + long binlen; + int rv = -1; + + bin = OPENSSL_hexstr2buf(hex, &binlen); + if (bin == NULL) + return 0; + if (binlen <= INT_MAX) + rv = cb(ctx, cmd, bin, binlen); + OPENSSL_free(bin); + return rv; +} |