Skip to content

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

Merged
jyao1 merged 3 commits into
DMTF:mainfrom
jyao1:fips_update2
Nov 11, 2026
Merged

jyao1 merged 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 Resolved
Comment thread os_stub/cryptlib_openssl/pk/dh.c Resolved
* @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.

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 understand your comment.

What is the problem of the original code? Could you please be specific?

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.

I reviewed this function libspdm_dh_set_priv_key several times.
Currently libspdm_dh_set_priv_key implemented in MbedTLS does not check private key as it claimed.
I can imagine the libspdm users probably utilize this API in their Known Answer Test (KAT) with given invalid private key even worst reuse this API in production codes instead of unit tests.

I found it is not easy to implement key validation by MbedTLS like EVP_PKEY_private_check() in OpenSSL.

Quoted from https://docs.openssl.org/3.0/man3/EVP_PKEY_check/#description
Refer to SP800-56A and SP800-56B for rules relating to when these functions should be called during key establishment. It is not necessary to call these functions after locally calling an approved key generation method, but may be required for assurance purposes when receiving keys from a third party.

But incomplete implementation by MbedTLS is worst than no implementation to me.

In this PR, there are still many benefits from the FIPS self-test in different perspectives.

  • Evaluate any change from relying third-party cryptographic library does not break the expected behavior.
  • Ensure any change to libspdm API doest not break the expected behavior.

In summary it is good to me.

@jyao1 jyao1 Nov 2, 2026 •

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.

Currently libspdm_dh_set_priv_key implemented in MbedTLS does not check private key as it claimed.

Yes, that is because mbedtls does not provide.
I do not expect this API will be used in production code except FIPS test.
Anyway, I think there is no harm to mirror what OpenSSL does for the check.

* @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.

I reviewed this function libspdm_dh_set_priv_key several times.
Currently libspdm_dh_set_priv_key implemented in MbedTLS does not check private key as it claimed.
I can imagine the libspdm users probably utilize this API in their Known Answer Test (KAT) with given invalid private key even worst reuse this API in production codes instead of unit tests.

I found it is not easy to implement key validation by MbedTLS like EVP_PKEY_private_check() in OpenSSL.

Quoted from https://docs.openssl.org/3.0/man3/EVP_PKEY_check/#description
Refer to SP800-56A and SP800-56B for rules relating to when these functions should be called during key establishment. It is not necessary to call these functions after locally calling an approved key generation method, but may be required for assurance purposes when receiving keys from a third party.

But incomplete implementation by MbedTLS is worst than no implementation to me.

In this PR, there are still many benefits from the FIPS self-test in different perspectives.

  • Evaluate any change from relying third-party cryptographic library does not break the expected behavior.
  • Ensure any change to libspdm API doest not break the expected behavior.

In summary it is good to me.

* (domainParameterGenerationMode = ffdhe2048, scheme = dhEphem), tcId 1.
* The ffdhe2048 domain parameters are from RFC 7919.
* https://github.com/usnistgov/ACVP-Server/tree/master/gen-val/json-files/KAS-FFC-SSC-Sp800-56Ar3
*/

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.

Note:
RELEASE/v1.1.0.41
commit hash b121fee031dc65d32c96f4109a42a10dacbe2076

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
Assisted-by: Claude Code:claude-sonnet-5-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
@jyao1
jyao1 merged commit 5476356 into DMTF:main Nov 11, 2026
55 checks passed
@jyao1
jyao1 deleted the fips_update2 branch November 11, 2026 03:36
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.

3 participants