Skip to content

Commit 9acd1eb

Browse files
authored
Clear HKDF info when set from params (#160)
* Only concatenate info from same set_params call * Export HKDF size parameter
1 parent 855de79 commit 9acd1eb

1 file changed

Lines changed: 16 additions & 12 deletions

File tree

SymCryptProvider/src/kdf/p_scossl_hkdf.c

Lines changed: 16 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -25,6 +25,7 @@ extern "C" {
2525

2626
static const OSSL_PARAM p_scossl_hkdf_gettable_ctx_param_types[] = {
2727
HKDF_COMMON_SETTABLES,
28+
OSSL_PARAM_size_t(OSSL_KDF_PARAM_SIZE, NULL),
2829
OSSL_PARAM_END};
2930

3031
static const OSSL_PARAM p_scossl_hkdf_settable_ctx_param_types[] = {
@@ -301,21 +302,24 @@ SCOSSL_STATUS p_scossl_hkdf_set_ctx_params(_Inout_ SCOSSL_PROV_HKDF_CTX *ctx, co
301302
}
302303

303304
// Parameters may contain multiple info params that must all be processed
304-
for (p = OSSL_PARAM_locate_const(params, OSSL_KDF_PARAM_INFO);
305-
p != NULL;
306-
p = OSSL_PARAM_locate_const(p + 1, OSSL_KDF_PARAM_INFO))
305+
if ((p = OSSL_PARAM_locate_const(params, OSSL_KDF_PARAM_INFO)) != NULL)
307306
{
308-
if (!OSSL_PARAM_get_octet_string_ptr(p, (const void **)&pbInfo, &cbInfo))
309-
{
310-
ERR_raise(ERR_LIB_PROV, PROV_R_FAILED_TO_GET_PARAMETER);
311-
return SCOSSL_FAILURE;
312-
}
307+
ctx->hkdfCtx->cbInfo = 0;
313308

314-
if (!scossl_hkdf_append_info(ctx->hkdfCtx, pbInfo, cbInfo))
309+
do
315310
{
316-
ERR_raise(ERR_LIB_PROV, PROV_R_LENGTH_TOO_LARGE);
317-
return SCOSSL_FAILURE;
318-
}
311+
if (!OSSL_PARAM_get_octet_string_ptr(p, (const void **)&pbInfo, &cbInfo))
312+
{
313+
ERR_raise(ERR_LIB_PROV, PROV_R_FAILED_TO_GET_PARAMETER);
314+
return SCOSSL_FAILURE;
315+
}
316+
317+
if (!scossl_hkdf_append_info(ctx->hkdfCtx, pbInfo, cbInfo))
318+
{
319+
ERR_raise(ERR_LIB_PROV, PROV_R_LENGTH_TOO_LARGE);
320+
return SCOSSL_FAILURE;
321+
}
322+
} while ((p = OSSL_PARAM_locate_const(p + 1, OSSL_KDF_PARAM_INFO)) != NULL);
319323
}
320324

321325
return SCOSSL_SUCCESS;

0 commit comments

Comments
 (0)