X-Git-Url: https://git.openssl.org/gitweb/?p=openssl.git;a=blobdiff_plain;f=providers%2Fimplementations%2Fkdfs%2Fsshkdf.c;h=f99a6a74135dea1352f47754e530abe314aa6722;hp=aa3b6030b9abddce32d2d8aedbe73d0354ccaf08;hb=3469b388164775546022635d6695cae17104faa6;hpb=2b9e4e956b37ee49b29a73c7782f525ac8c58cc5 diff --git a/providers/implementations/kdfs/sshkdf.c b/providers/implementations/kdfs/sshkdf.c index aa3b6030b9..f99a6a7413 100644 --- a/providers/implementations/kdfs/sshkdf.c +++ b/providers/implementations/kdfs/sshkdf.c @@ -1,5 +1,5 @@ /* - * Copyright 2018-2020 The OpenSSL Project Authors. All Rights Reserved. + * Copyright 2018-2021 The OpenSSL Project Authors. All Rights Reserved. * * Licensed under the Apache License 2.0 (the "License"). You may not use * this file except in compliance with the License. You can obtain a copy @@ -13,12 +13,12 @@ #include #include #include +#include #include "internal/cryptlib.h" #include "internal/numbers.h" #include "crypto/evp.h" #include "prov/provider_ctx.h" #include "prov/providercommon.h" -#include "prov/providercommonerr.h" #include "prov/implementations.h" #include "prov/provider_util.h" @@ -94,13 +94,13 @@ static int sshkdf_set_membuf(unsigned char **dst, size_t *dst_len, return OSSL_PARAM_get_octet_string(p, (void **)dst, 0, dst_len); } -static int kdf_sshkdf_derive(void *vctx, unsigned char *key, - size_t keylen) +static int kdf_sshkdf_derive(void *vctx, unsigned char *key, size_t keylen, + const OSSL_PARAM params[]) { KDF_SSHKDF *ctx = (KDF_SSHKDF *)vctx; const EVP_MD *md; - if (!ossl_prov_is_running()) + if (!ossl_prov_is_running() || !kdf_sshkdf_set_ctx_params(ctx, params)) return 0; md = ossl_prov_digest_md(&ctx->digest); @@ -134,8 +134,7 @@ static int kdf_sshkdf_set_ctx_params(void *vctx, const OSSL_PARAM params[]) { const OSSL_PARAM *p; KDF_SSHKDF *ctx = vctx; - OPENSSL_CTX *provctx = PROV_LIBRARY_CONTEXT_OF(ctx->provctx); - int t; + OSSL_LIB_CTX *provctx = PROV_LIBCTX_OF(ctx->provctx); if (!ossl_prov_digest_load_from_params(&ctx->digest, params, provctx)) return 0; @@ -156,19 +155,24 @@ static int kdf_sshkdf_set_ctx_params(void *vctx, const OSSL_PARAM params[]) if ((p = OSSL_PARAM_locate_const(params, OSSL_KDF_PARAM_SSHKDF_TYPE)) != NULL) { - if (p->data == NULL || p->data_size == 0) + const char *kdftype; + + if (!OSSL_PARAM_get_utf8_string_ptr(p, &kdftype)) + return 0; + /* Expect one character (byte in this case) */ + if (kdftype == NULL || p->data_size != 1) return 0; - t = *(unsigned char *)p->data; - if (t < 65 || t > 70) { + if (kdftype[0] < 65 || kdftype[0] > 70) { ERR_raise(ERR_LIB_PROV, PROV_R_VALUE_ERROR); return 0; } - ctx->type = (char)t; + ctx->type = kdftype[0]; } return 1; } -static const OSSL_PARAM *kdf_sshkdf_settable_ctx_params(ossl_unused void *p_ctx) +static const OSSL_PARAM *kdf_sshkdf_settable_ctx_params(ossl_unused void *ctx, + ossl_unused void *p_ctx) { static const OSSL_PARAM known_settable_ctx_params[] = { OSSL_PARAM_utf8_string(OSSL_KDF_PARAM_PROPERTIES, NULL, 0), @@ -191,7 +195,8 @@ static int kdf_sshkdf_get_ctx_params(void *vctx, OSSL_PARAM params[]) return -2; } -static const OSSL_PARAM *kdf_sshkdf_gettable_ctx_params(ossl_unused void *p_ctx) +static const OSSL_PARAM *kdf_sshkdf_gettable_ctx_params(ossl_unused void *ctx, + ossl_unused void *p_ctx) { static const OSSL_PARAM known_gettable_ctx_params[] = { OSSL_PARAM_size_t(OSSL_KDF_PARAM_SIZE, NULL), @@ -200,7 +205,7 @@ static const OSSL_PARAM *kdf_sshkdf_gettable_ctx_params(ossl_unused void *p_ctx) return known_gettable_ctx_params; } -const OSSL_DISPATCH kdf_sshkdf_functions[] = { +const OSSL_DISPATCH ossl_kdf_sshkdf_functions[] = { { OSSL_FUNC_KDF_NEWCTX, (void(*)(void))kdf_sshkdf_new }, { OSSL_FUNC_KDF_FREECTX, (void(*)(void))kdf_sshkdf_free }, { OSSL_FUNC_KDF_RESET, (void(*)(void))kdf_sshkdf_reset },