Repository navigation
Conversation
| EVP_PKEY_free(new_key); | ||
| OSSL_PARAM_BLD_free(param_bld); | ||
| OSSL_PARAM_free(ossl_params); | ||
| BN_free(bn_priv); |
There was a problem hiding this comment.
Probably here could consider key-zeroization to use BN_clear_free(bn_priv) in best practice.
https://github.com/DMTF/libspdm/blob/main/doc/fips.md#key-zeroization
| update: | ||
| /* mark it as tested*/ | ||
| context->tested_algo |= LIBSPDM_FIPS_SELF_TEST_FFDH; | ||
|
|
There was a problem hiding this comment.
[optional] Consider key-zeroization and put libspdm_zero_mem(ff_key1, sizeof(ff_key1)); here.
There was a problem hiding this comment.
I do not think there is need. All keys are pre-known. No value to zero.
Add libspdm_dh_set_priv_key() to allow a fixed-key KAT (previously a pairwise-consistency test only). Vector from NIST ACVP-Server: KAS-FFC-SSC-Sp800-56Ar3 (ffdhe2048 domain parameters, RFC 7919). Signed-off-by: Jiewen Yao <jiewen.yao@intel.com> Assisted-by: GitHub Copilot:Claude Sonnet 5
Signed-off-by: Jiewen Yao <jiewen.yao@intel.com> Assisted-by: GitHub Copilot:Claude Sonnet 5
Document the FFDHE known-answer test and the new libspdm_dh_set_priv_key() HAL function. Signed-off-by: Jiewen Yao <jiewen.yao@intel.com> Assisted-by: GitHub Copilot:Claude Sonnet 5
| if (EVP_PKEY_fromdata(ctx, &new_key, EVP_PKEY_KEYPAIR, ossl_params) <= 0) { | ||
| goto cleanup; | ||
| } | ||
|
|
There was a problem hiding this comment.
As the function comment mentioned that it would return false when Invalid DH private key component.
Reference:
https://docs.openssl.org/3.0/man3/EVP_PKEY_check/#notes
https://nvlpubs.nist.gov/nistpubs/SpecialPublications/NIST.SP.800-56Ar3.pdf
I thought probably it is proper to put on key validation here.
EVP_PKEY_CTX_free(ctx);
ctx = EVP_PKEY_CTX_new_from_pkey(NULL, new_key, NULL);
if (ctx == NULL || EVP_PKEY_private_check(ctx) <= 0) {
goto cleanup;
}
| * @param[in] priv_key_size The size of private key buffer in bytes. | ||
| * | ||
| * @retval true DH private key component was set successfully. | ||
| * @retval false Invalid DH private key component. |
There was a problem hiding this comment.
As the function comment and reference links mentioned above.
Actually I have no actual idea how to use Mbed-TLS to do key validation in proper way like OpenSSL in detail.
Sample code generated from my agent.
assisted-by: GitHub Copilot:Claude OPUS 5.5
mbedtls_mpi q;
bool ok;
ctx = dh_context;
mbedtls_mpi_init(&q);
ok = mbedtls_mpi_read_binary(&ctx->MBEDTLS_PRIVATE(X), priv_key, priv_key_size) == 0 &&
mbedtls_mpi_sub_int(&q, &ctx->MBEDTLS_PRIVATE(P), 1) == 0 &&
mbedtls_mpi_shift_r(&q, 1) == 0 &&
mbedtls_mpi_cmp_int(&ctx->MBEDTLS_PRIVATE(X), 1) >= 0 &&
mbedtls_mpi_cmp_mpi(&ctx->MBEDTLS_PRIVATE(X), &q) < 0;
mbedtls_mpi_free(&q);
if (!ok) {
mbedtls_mpi_free(&ctx->MBEDTLS_PRIVATE(X));
mbedtls_mpi_init(&ctx->MBEDTLS_PRIVATE(X));
}
return ok;
FYI.
Add libspdm_dh_set_priv_key() to allow a fixed-key KAT (previously a
pairwise-consistency test only). Vector from NIST ACVP-Server:
KAS-FFC-SSC-Sp800-56Ar3 (ffdhe2048 domain parameters, RFC 7919).
ref: #4198