2 * Copyright 2018-2019 The OpenSSL Project Authors. All Rights Reserved.
3 * Copyright (c) 2018-2019, Oracle and/or its affiliates. All rights reserved.
5 * Licensed under the Apache License 2.0 (the "License"). You may not use
6 * this file except in compliance with the License. You can obtain a copy
7 * in the file LICENSE in the source distribution or at
8 * https://www.openssl.org/source/license.html
13 #include "internal/cryptlib.h"
14 #include <openssl/engine.h>
15 #include <openssl/evp.h>
16 #include <openssl/x509v3.h>
17 #include <openssl/kdf.h>
18 #include "internal/asn1_int.h"
19 #include "internal/evp_int.h"
20 #include "internal/numbers.h"
23 EVP_KDF_CTX *EVP_KDF_CTX_new(const EVP_KDF *kdf)
25 EVP_KDF_CTX *ctx = NULL;
30 ctx = OPENSSL_zalloc(sizeof(EVP_KDF_CTX));
31 if (ctx == NULL || (ctx->impl = kdf->new()) == NULL) {
32 EVPerr(EVP_F_EVP_KDF_CTX_NEW, ERR_R_MALLOC_FAILURE);
41 EVP_KDF_CTX *EVP_KDF_CTX_new_id(int id)
43 const EVP_KDF *kdf = EVP_get_kdfbynid(id);
45 return EVP_KDF_CTX_new(kdf);
48 int EVP_KDF_nid(const EVP_KDF *kdf)
53 const EVP_KDF *EVP_KDF_CTX_kdf(EVP_KDF_CTX *ctx)
58 void EVP_KDF_CTX_free(EVP_KDF_CTX *ctx)
63 ctx->meth->free(ctx->impl);
67 void EVP_KDF_reset(EVP_KDF_CTX *ctx)
72 if (ctx->meth->reset != NULL)
73 ctx->meth->reset(ctx->impl);
76 int EVP_KDF_ctrl(EVP_KDF_CTX *ctx, int cmd, ...)
82 ret = EVP_KDF_vctrl(ctx, cmd, args);
86 EVPerr(EVP_F_EVP_KDF_CTRL, EVP_R_COMMAND_NOT_SUPPORTED);
91 int EVP_KDF_vctrl(EVP_KDF_CTX *ctx, int cmd, va_list args)
96 return ctx->meth->ctrl(ctx->impl, cmd, args);
99 int EVP_KDF_ctrl_str(EVP_KDF_CTX *ctx, const char *type, const char *value)
106 if (ctx->meth->ctrl_str == NULL) {
107 EVPerr(EVP_F_EVP_KDF_CTRL_STR, EVP_R_COMMAND_NOT_SUPPORTED);
111 ret = ctx->meth->ctrl_str(ctx->impl, type, value);
113 EVPerr(EVP_F_EVP_KDF_CTRL_STR, EVP_R_COMMAND_NOT_SUPPORTED);
118 size_t EVP_KDF_size(EVP_KDF_CTX *ctx)
123 if (ctx->meth->size == NULL)
126 return ctx->meth->size(ctx->impl);
129 int EVP_KDF_derive(EVP_KDF_CTX *ctx, unsigned char *key, size_t keylen)
134 return ctx->meth->derive(ctx->impl, key, keylen);