Skip to content

Conversation

@nasahlpa
Copy link
Member

@nasahlpa nasahlpa commented Dec 5, 2025

security_config_check() checks, whether certain countermeasure are enabled to ensure a secure execution of the cryptolib. Until now, this check was conducted within the cryptolib itself.

However, as this function accesses the cpuctrlsts register, which is only accessible in the M privilege mode, this restricted CL to only be executable in M mode.

To increase the usage of the CL, this PR moves the security_config_check() function to the public CL API. Hence, now it is the responsibility of the caller of the CL to ensure that this check is first conducted.

This commit moves the `security_config_check()` function
to the cryptolib public API. With this, callers of the CL also can
make sure that the device is in a state allowing a secure execution
of CL.

Signed-off-by: Pascal Nasahl <[email protected]>
As it should be possible to execute the CL in the `U` privilege mode,
remote the `otcrypto_security_config_check()` call as this function
reads from the Ibex `cpuctrlsts` register that is only accessible
in the `M` privilege mode.

Signed-off-by: Pascal Nasahl <[email protected]>
Copy link
Contributor

@siemen11 siemen11 left a comment

Choose a reason for hiding this comment

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

Thank you Pascal! Good catch to move this to the user space, and thank you for implementing the new check in the pentest interface as well!

One question, would it be enough that the user calls this only once at the initialization of the library or is it needed for each crypto call?

@nasahlpa
Copy link
Member Author

nasahlpa commented Dec 5, 2025

Thank you Pascal! Good catch to move this to the user space, and thank you for implementing the new check in the pentest interface as well!

One question, would it be enough that the user calls this only once at the initialization of the library or is it needed for each crypto call?

Thanks for the review & suggestion.

Currently I've placed the check into each pentest subfunction that uses the CL. However, if a pentest subfunction has multiple calls into the CL, the check is only placed at the very beginning. E.g., in the cryptolib_fi_rsa_sign_impl function.

Would it make sense to move the check into the init function, e.g. into here?

status_t handle_cryptolib_fi_asym_init(ujson_t *uj) {

@siemen11
Copy link
Contributor

siemen11 commented Dec 5, 2025

Thank you Pascal! Good catch to move this to the user space, and thank you for implementing the new check in the pentest interface as well!
One question, would it be enough that the user calls this only once at the initialization of the library or is it needed for each crypto call?

Thanks for the review & suggestion.

Currently I've placed the check into each pentest subfunction that uses the CL. However, if a pentest subfunction has multiple calls into the CL, the check is only placed at the very beginning. E.g., in the cryptolib_fi_rsa_sign_impl function.

Would it make sense to move the check into the init function, e.g. into here?

status_t handle_cryptolib_fi_asym_init(ujson_t *uj) {

Yeah that would be great! We have space for it in

@nasahlpa
Copy link
Member Author

nasahlpa commented Dec 5, 2025

Thank you Pascal! Good catch to move this to the user space, and thank you for implementing the new check in the pentest interface as well!
One question, would it be enough that the user calls this only once at the initialization of the library or is it needed for each crypto call?

Thanks for the review & suggestion.
Currently I've placed the check into each pentest subfunction that uses the CL. However, if a pentest subfunction has multiple calls into the CL, the check is only placed at the very beginning. E.g., in the cryptolib_fi_rsa_sign_impl function.
Would it make sense to move the check into the init function, e.g. into here?

status_t handle_cryptolib_fi_asym_init(ujson_t *uj) {

Yeah that would be great! We have space for it in

Makes sense - I've moved it to the init function that we always call before a pentest run.

For security testing, make sure that the device is in a secure configuration
before entering the cryptolib.

Signed-off-by: Pascal Nasahl <[email protected]>
Copy link
Contributor

@johannheyszl johannheyszl left a comment

Choose a reason for hiding this comment

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

Thanks @nasahlpa

@nasahlpa nasahlpa marked this pull request as ready for review December 8, 2025 08:19
@nasahlpa nasahlpa requested a review from a team as a code owner December 8, 2025 08:19
@nasahlpa nasahlpa requested review from h-filali and moidx and removed request for a team December 8, 2025 08:19
@nasahlpa nasahlpa added the CherryPick:earlgrey_1.0.0 This PR should be cherry-picked to earlgrey_1.0.0 label Dec 9, 2025
Copy link
Contributor

@h-filali h-filali left a comment

Choose a reason for hiding this comment

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

Thanks @nasahlpa for adding this.
I checked the following:

  • The first commit only moves the check ✔
  • The second commit only removes the function calls inside CL ✔
  • The third commit only switches the security level ✔
  • The last commit adds calls to the relevant locations ✔

For the last commit I have a small addendum. For cryptolib users it might not be clear that they have to call the security config check. A user will probably base their code off of what they can find in the cryptotests or in the pentests library. This makes incorrect use in this specific case pretty likely. I will start a document that captures any such cases from now on.

@nasahlpa nasahlpa added this pull request to the merge queue Dec 9, 2025
Merged via the queue into lowRISC:master with commit 42dbfeb Dec 9, 2025
49 checks passed
@lowrisc-ci
Copy link

lowrisc-ci bot commented Dec 9, 2025

Backport failed for earlgrey_1.0.0, because it was unable to cherry-pick the commit(s).

Please cherry-pick the changes locally and resolve any conflicts.

git fetch origin earlgrey_1.0.0
git worktree add -d .worktree/backport-28882-to-earlgrey_1.0.0 origin/earlgrey_1.0.0
cd .worktree/backport-28882-to-earlgrey_1.0.0
git switch --create backport-28882-to-earlgrey_1.0.0
git cherry-pick -x 86bbee37acc5f3989edf65aa995e9678af695b84 94e3de705d69ce5d9b6250421ac12a687240d4ab 24bc1b2cb33bb5d9d45d8acf0bb82e91b95e9534 a9afc85d6c36c2ab521c65ffcadc965dbd6ced12

@lowrisc-ci lowrisc-ci bot added the Manually CherryPick This PR should be manually cherry picked. label Dec 9, 2025
@lowrisc-ci
Copy link

lowrisc-ci bot commented Dec 9, 2025

Backport failed for earlgrey_1.0.0, because it was unable to cherry-pick the commit(s).

Please cherry-pick the changes locally and resolve any conflicts.

git fetch origin earlgrey_1.0.0
git worktree add -d .worktree/backport-28882-to-earlgrey_1.0.0 origin/earlgrey_1.0.0
cd .worktree/backport-28882-to-earlgrey_1.0.0
git switch --create backport-28882-to-earlgrey_1.0.0
git cherry-pick -x 86bbee37acc5f3989edf65aa995e9678af695b84 94e3de705d69ce5d9b6250421ac12a687240d4ab 24bc1b2cb33bb5d9d45d8acf0bb82e91b95e9534 a9afc85d6c36c2ab521c65ffcadc965dbd6ced12

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

Labels

CherryPick:earlgrey_1.0.0 This PR should be cherry-picked to earlgrey_1.0.0 Manually CherryPick This PR should be manually cherry picked.

Projects

None yet

Development

Successfully merging this pull request may close these issues.

4 participants