Skip to content

Use NIST vector for FFDH FIPS self-test - #4261

Open
jyao1 wants to merge 3 commits into
DMTF:mainfrom
jyao1:fips_update2
Open

jyao1 wants to merge 3 commits into
DMTF:mainfrom
jyao1:fips_update2

Conversation

@jyao1

@jyao1 jyao1 commented Oct 28, 2026

Copy link
Copy Markdown
Member

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

@jyao1
jyao1 requested a review from steven-bellock as a code owner October 28, 2026 13:46
@jyao1 jyao1 added the 4.0 Issues and features slated for the next major revision of libspdm. label Oct 28, 2026
Comment thread os_stub/cryptlib_openssl/pk/dh.c Outdated
EVP_PKEY_free(new_key);
OSSL_PARAM_BLD_free(param_bld);
OSSL_PARAM_free(ossl_params);
BN_free(bn_priv);

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

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

Copy link
Copy Markdown
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

fixed

update:
/* mark it as tested*/
context->tested_algo |= LIBSPDM_FIPS_SELF_TEST_FFDH;

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

[optional] Consider key-zeroization and put libspdm_zero_mem(ff_key1, sizeof(ff_key1)); here.

Copy link
Copy Markdown
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I do not think there is need. All keys are pre-known. No value to zero.

jyao1 added 3 commits October 29, 2026 23:16
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;
}

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

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.

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

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.

This branch has not been deployed

No deployments
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

4.0 Issues and features slated for the next major revision of libspdm.

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants