Add feature to run libspdm_fips_run_selftest at load time#1833
Conversation
f43e593 to
3d2c80f
Compare
|
@jyao1 @xiaoyuruan I don't think libspdm needs to support any of this. It should be left up to the Integrator when the self-tests are run. |
|
I think 99% of implementations would run self-tests for algorithms either 1. all at load or 2. individually before first use. |
|
|
|
Discussed in 3/27/2023.
Jiewen will talk to Xiaoyu on that. |
|
@Wenxing-hou , please split EC patch to a standalone PR. not merge in this one. |
|
Discussed with Jiewen. I suggest implementing, in the libspdm-crypto module, a "global crypto context" that covers all connection-based contexts. The "global crypto context" should save FIPS selftest status (run yet?; passed/failed) for every crypto algorithm, respectively. Whenever a crypto algorithm is called, libspdm-crypto should check that this algorithm has run and passed selftest; if not run, run it and update status in global context; if not passed, return error. |
|
@xiaoyuruan And the global crypto context is single context that is stack or heap allocated and provided by the Integrator? |
|
Yes. it is provided by the integrator. It could be stack, or heap, or writable global variable. The consumer needs to aware that, multiple SPDM contexts may access the global area at same time. That will add complexity to the implementation. |
3d2c80f to
4ba283f
Compare
Thanks. I have submitted a new PR: #1838. The CI will pass when the PR: #1838 is merged. |
4ba283f to
7761165
Compare
5006df7 to
eaf89fb
Compare
There was a problem hiding this comment.
Please remove bit enumeration here.
Just say "See LIBSPDM_FIPS_SELF_TEST_xxx".
There was a problem hiding this comment.
Thanks. I have changed the comments.
There was a problem hiding this comment.
I think we need size_t crypto_context_size
There was a problem hiding this comment.
Thanks. I have added the size parameter.
002ba2c to
1e3afed
Compare
There was a problem hiding this comment.
The name "libspdm_crypto_context" is kind of misleading - "crypto" is too big a scope, it's really just FIPS selftest status.
There was a problem hiding this comment.
Yes. I have changed the libspdm_crypto_context to libspdm_fips_selftest_context.
There was a problem hiding this comment.
I'm curious, why is parameter crypto_context_size needed here? If it's needed here for safety, for consistency, why not also have a parameter "spdm_context_size"?
There was a problem hiding this comment.
I'd define "MASK" for each algorithm, and use context->crypto_context.tested_algo & MASK. This would save the shift operation.
There was a problem hiding this comment.
right. Just define LIBSPDM_FIPS_SELF_TEST_HMAC_SHA256 as bit mask.
There was a problem hiding this comment.
Thanks. I have changed the SHIFT_BIT to MASK, which can save the shift operation.
There was a problem hiding this comment.
Why 0xFF? There are more than 8 algorithms. tested_algo is a uint32.
There was a problem hiding this comment.
Thanks. I have updated 0xFF -> 0xFFFF.
There was a problem hiding this comment.
Using 0xFFFF assumes the number of tests is 16. i.e., if we add or remove selftests later, it needs to change here, and it is easy to miss.
I'd suggest using OR result of all LIBSPDM_FIPS_SELF_TEST_XYZ instead of hardcoding to 0xFFFF.
There was a problem hiding this comment.
Thanks. I have changed the 0xFFFF by using OR result of all LIBSPDM_FIPS_SELF_TEST_XYZ.
There was a problem hiding this comment.
Is the following selftest code same as in libspdm_init_connection()? Why duplicate the code?
There was a problem hiding this comment.
I have added a api bool libspdm_update_fips_selftest_context(void *spdm_context), which can be called by requester and responder. Thanks.
There was a problem hiding this comment.
I think it's more logical to always run all selftests, even if one or more algorithms have failed. At the end, the function would have run all selftests and return overall failed/passed.
There was a problem hiding this comment.
Yes. In function bool libspdm_update_fips_selftest_context(void *spdm_context), all selftests will be run, even if one algo have failed.
24b7053 to
72ecdc0
Compare
There was a problem hiding this comment.
It'd need #if LIBSPDM_XYZ_SUPPORT qualifier before participating in the | operation.
e89fd81 to
bd2126f
Compare
There was a problem hiding this comment.
this line is missing "|", did it compile?
There was a problem hiding this comment.
Sorry. I forget to add the "|". The code has been added. Thanks.
bd2126f to
84f6eda
Compare
|
Please fix CI failure |
84f6eda to
fbd6625
Compare
yes. The CI passed. Thanks. |
Commit1: Add LIBSPDM_FIPS_TEST_AT_LOAD for FIPS
Commit2: Add feature to run libspdm_fips_run_selftest at load time
The PR: DMTF/spdm-emu#238 will pass, when this PR is merged.
The emu and libspdm tests have passed when
LIBSPDM_FIPS_TEST_AT_LOAD = 1andLIBSPDM_FIPS_MODE = 1.Refer: #1260