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 = OPENSSL_zalloc(sizeof(EVP_KDF_CTX));
27 if (ctx == NULL || (ctx->impl = kdf->new()) == NULL) {
28 EVPerr(EVP_F_EVP_KDF_CTX_NEW, ERR_R_MALLOC_FAILURE);
37 EVP_KDF_CTX *EVP_KDF_CTX_new_id(int id)
39 const EVP_KDF *kdf = EVP_get_kdfbynid(id);
43 return EVP_KDF_CTX_new(kdf);
46 int EVP_KDF_nid(const EVP_KDF *kdf)
51 const EVP_KDF *EVP_KDF_CTX_kdf(EVP_KDF_CTX *ctx)
56 void EVP_KDF_CTX_free(EVP_KDF_CTX *ctx)
61 ctx->meth->free(ctx->impl);
65 void EVP_KDF_reset(EVP_KDF_CTX *ctx)
70 if (ctx->meth->reset != NULL)
71 ctx->meth->reset(ctx->impl);
74 int EVP_KDF_ctrl(EVP_KDF_CTX *ctx, int cmd, ...)
80 ret = EVP_KDF_vctrl(ctx, cmd, args);
84 EVPerr(EVP_F_EVP_KDF_CTRL, EVP_R_COMMAND_NOT_SUPPORTED);
89 int EVP_KDF_vctrl(EVP_KDF_CTX *ctx, int cmd, va_list args)
94 return ctx->meth->ctrl(ctx->impl, cmd, args);
97 int EVP_KDF_ctrl_str(EVP_KDF_CTX *ctx, const char *type, const char *value)
104 if (ctx->meth->ctrl_str == NULL) {
105 EVPerr(EVP_F_EVP_KDF_CTRL_STR, EVP_R_COMMAND_NOT_SUPPORTED);
109 ret = ctx->meth->ctrl_str(ctx->impl, type, value);
111 EVPerr(EVP_F_EVP_KDF_CTRL_STR, EVP_R_COMMAND_NOT_SUPPORTED);
116 size_t EVP_KDF_size(EVP_KDF_CTX *ctx)
121 if (ctx->meth->size == NULL)
124 return ctx->meth->size(ctx->impl);
127 int EVP_KDF_derive(EVP_KDF_CTX *ctx, unsigned char *key, size_t keylen)
132 return ctx->meth->derive(ctx->impl, key, keylen);