pbkdf1: implement ctx dup operation
#include "prov/provider_util.h"
static OSSL_FUNC_kdf_newctx_fn kdf_pbkdf1_new;
+static OSSL_FUNC_kdf_dupctx_fn kdf_pbkdf1_dup;
static OSSL_FUNC_kdf_freectx_fn kdf_pbkdf1_free;
static OSSL_FUNC_kdf_reset_fn kdf_pbkdf1_reset;
static OSSL_FUNC_kdf_derive_fn kdf_pbkdf1_derive;
@@ -130,6 +131,28 @@ static void kdf_pbkdf1_reset(void *vctx)
ctx->provctx = provctx;
}
+static void *kdf_pbkdf1_dup(void *vctx)
+{
+ const KDF_PBKDF1 *src = (const KDF_PBKDF1 *)vctx;
+ KDF_PBKDF1 *dest;
+
+ dest = kdf_pbkdf1_new(src->provctx);
+ if (dest != NULL) {
+ if (!ossl_prov_memdup(src->salt, src->salt_len,
+ &dest->salt, &dest->salt_len)
+ || !ossl_prov_memdup(src->pass, src->pass_len,
+ &dest->pass , &dest->pass_len)
+ || !ossl_prov_digest_copy(&dest->digest, &src->digest))
+ goto err;
+ dest->iter = src->iter;
+ }
+ return dest;
+
+ err:
+ kdf_pbkdf1_free(dest);
+ return NULL;
+}
+
static int kdf_pbkdf1_set_membuf(unsigned char **buffer, size_t *buflen,
const OSSL_PARAM *p)
{
@@ -231,6 +254,7 @@ static const OSSL_PARAM *kdf_pbkdf1_gettable_ctx_params(ossl_unused void *ctx,
const OSSL_DISPATCH ossl_kdf_pbkdf1_functions[] = {
{ OSSL_FUNC_KDF_NEWCTX, (void(*)(void))kdf_pbkdf1_new },
+ { OSSL_FUNC_KDF_DUPCTX, (void(*)(void))kdf_pbkdf1_dup },
{ OSSL_FUNC_KDF_FREECTX, (void(*)(void))kdf_pbkdf1_free },
{ OSSL_FUNC_KDF_RESET, (void(*)(void))kdf_pbkdf1_reset },
{ OSSL_FUNC_KDF_DERIVE, (void(*)(void))kdf_pbkdf1_derive },
