hkdf: implement ctx dup operation
#define HKDF_MAXBUF 2048
static OSSL_FUNC_kdf_newctx_fn kdf_hkdf_new;
+static OSSL_FUNC_kdf_dupctx_fn kdf_hkdf_dup;
static OSSL_FUNC_kdf_freectx_fn kdf_hkdf_free;
static OSSL_FUNC_kdf_reset_fn kdf_hkdf_reset;
static OSSL_FUNC_kdf_derive_fn kdf_hkdf_derive;
@@ -126,6 +127,36 @@ static void kdf_hkdf_reset(void *vctx)
ctx->provctx = provctx;
}
+static void *kdf_hkdf_dup(void *vctx)
+{
+ const KDF_HKDF *src = (const KDF_HKDF *)vctx;
+ KDF_HKDF *dest;
+
+ dest = kdf_hkdf_new(src->provctx);
+ if (dest != NULL) {
+ if (!ossl_prov_memdup(src->salt, src->salt_len, &dest->salt,
+ &dest->salt_len)
+ || !ossl_prov_memdup(src->key, src->key_len,
+ &dest->key , &dest->key_len)
+ || !ossl_prov_memdup(src->prefix, src->prefix_len,
+ &dest->prefix, &dest->prefix_len)
+ || !ossl_prov_memdup(src->label, src->label_len,
+ &dest->label, &dest->label_len)
+ || !ossl_prov_memdup(src->data, src->data_len,
+ &dest->data, &dest->data_len)
+ || !ossl_prov_digest_copy(&dest->digest, &src->digest))
+ goto err;
+ memcpy(dest->info, src->info, sizeof(dest->info));
+ dest->info_len = src->info_len;
+ dest->mode = src->mode;
+ }
+ return dest;
+
+ err:
+ kdf_hkdf_free(dest);
+ return NULL;
+}
+
static size_t kdf_hkdf_size(KDF_HKDF *ctx)
{
int sz;
@@ -313,6 +344,7 @@ static const OSSL_PARAM *kdf_hkdf_gettable_ctx_params(ossl_unused void *ctx,
const OSSL_DISPATCH ossl_kdf_hkdf_functions[] = {
{ OSSL_FUNC_KDF_NEWCTX, (void(*)(void))kdf_hkdf_new },
+ { OSSL_FUNC_KDF_DUPCTX, (void(*)(void))kdf_hkdf_dup },
{ OSSL_FUNC_KDF_FREECTX, (void(*)(void))kdf_hkdf_free },
{ OSSL_FUNC_KDF_RESET, (void(*)(void))kdf_hkdf_reset },
{ OSSL_FUNC_KDF_DERIVE, (void(*)(void))kdf_hkdf_derive },
@@ -728,6 +760,7 @@ static const OSSL_PARAM *kdf_tls1_3_settable_ctx_params(ossl_unused void *ctx,
const OSSL_DISPATCH ossl_kdf_tls1_3_kdf_functions[] = {
{ OSSL_FUNC_KDF_NEWCTX, (void(*)(void))kdf_hkdf_new },
+ { OSSL_FUNC_KDF_DUPCTX, (void(*)(void))kdf_hkdf_dup },
{ OSSL_FUNC_KDF_FREECTX, (void(*)(void))kdf_hkdf_free },
{ OSSL_FUNC_KDF_RESET, (void(*)(void))kdf_hkdf_reset },
{ OSSL_FUNC_KDF_DERIVE, (void(*)(void))kdf_tls1_3_derive },
