diff options
author | Pauli <paul.dale@oracle.com> | 2019-08-21 10:53:45 +0200 |
---|---|---|
committer | Pauli <paul.dale@oracle.com> | 2019-09-06 11:27:57 +0200 |
commit | 55accfd2f11d02cf4cfdc6077216ae59f1748f6a (patch) | |
tree | 918118d475bffc53361c07b689b068a24fc9e7d0 /apps/kdf.c | |
parent | KDF provider conversion error updates - generated (diff) | |
download | openssl-55accfd2f11d02cf4cfdc6077216ae59f1748f6a.tar.xz openssl-55accfd2f11d02cf4cfdc6077216ae59f1748f6a.zip |
App updates for KDF provider conversion.
Reviewed-by: Richard Levitte <levitte@openssl.org>
(Merged from https://github.com/openssl/openssl/pull/9662)
Diffstat (limited to 'apps/kdf.c')
-rw-r--r-- | apps/kdf.c | 49 |
1 files changed, 20 insertions, 29 deletions
diff --git a/apps/kdf.c b/apps/kdf.c index 684fd44cc0..c230430697 100644 --- a/apps/kdf.c +++ b/apps/kdf.c @@ -15,6 +15,7 @@ #include <openssl/err.h> #include <openssl/evp.h> #include <openssl/kdf.h> +#include <openssl/params.h> typedef enum OPTION_choice { OPT_ERR = -1, OPT_EOF = 0, OPT_HELP, @@ -34,27 +35,9 @@ const OPTIONS kdf_options[] = { {NULL} }; -static int kdf_ctrl_string(EVP_KDF_CTX *ctx, const char *value) -{ - int rv; - char *stmp, *vtmp = NULL; - - stmp = OPENSSL_strdup(value); - if (stmp == NULL) - return -1; - vtmp = strchr(stmp, ':'); - if (vtmp != NULL) { - *vtmp = 0; - vtmp++; - } - rv = EVP_KDF_ctrl_str(ctx, stmp, vtmp); - OPENSSL_free(stmp); - return rv; -} - int kdf_main(int argc, char **argv) { - int ret = 1, i, id, out_bin = 0; + int ret = 1, out_bin = 0; OPTION_CHOICE o; STACK_OF(OPENSSL_STRING) *opts = NULL; char *prog, *hexout = NULL; @@ -62,6 +45,7 @@ int kdf_main(int argc, char **argv) unsigned char *dkm_bytes = NULL; size_t dkm_len = 0; BIO *out = NULL; + EVP_KDF *kdf = NULL; EVP_KDF_CTX *ctx = NULL; prog = opt_init(argc, argv, kdf_options); @@ -100,25 +84,31 @@ opthelp: goto opthelp; } - id = OBJ_sn2nid(argv[0]); - if (id == NID_undef) { + if ((kdf = EVP_KDF_fetch(NULL, argv[0], NULL)) == NULL) { BIO_printf(bio_err, "Invalid KDF name %s\n", argv[0]); goto opthelp; } - ctx = EVP_KDF_CTX_new_id(id); + ctx = EVP_KDF_CTX_new(kdf); if (ctx == NULL) goto err; if (opts != NULL) { - for (i = 0; i < sk_OPENSSL_STRING_num(opts); i++) { - char *opt = sk_OPENSSL_STRING_value(opts, i); - if (kdf_ctrl_string(ctx, opt) <= 0) { - BIO_printf(bio_err, "KDF parameter error '%s'\n", opt); - ERR_print_errors(bio_err); - goto err; - } + int ok = 1; + OSSL_PARAM *params = + app_params_new_from_opts(opts, EVP_KDF_CTX_settable_params(kdf)); + + if (params == NULL) + goto err; + + if (!EVP_KDF_CTX_set_params(ctx, params)) { + BIO_printf(bio_err, "KDF parameter error\n"); + ERR_print_errors(bio_err); + ok = 0; } + app_params_free(params); + if (!ok) + goto err; } out = bio_open_default(outfile, 'w', out_bin ? FORMAT_BINARY : FORMAT_TEXT); @@ -151,6 +141,7 @@ err: ERR_print_errors(bio_err); OPENSSL_clear_free(dkm_bytes, dkm_len); sk_OPENSSL_STRING_free(opts); + EVP_KDF_free(kdf); EVP_KDF_CTX_free(ctx); BIO_free(out); OPENSSL_free(hexout); |