/*
- * 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
#include <openssl/evp.h>
#include <openssl/kdf.h>
#include <openssl/core_names.h>
+#include <openssl/proverr.h>
#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"
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);
{
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;
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),
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),
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 },