-
Notifications
You must be signed in to change notification settings - Fork 909
[fisim/crypto] Add instruction skip simulator #28549
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
base: master
Are you sure you want to change the base?
Changes from all commits
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -26,6 +26,9 @@ | |
|
|
||
| #define MODULE_ID MAKE_MODULE_ID('f', 'a', 'i') | ||
|
|
||
| // Markers in the dis file to be able to trace certain functions | ||
| #define PENTEST_MARKER_LABEL(name) asm volatile(#name ":" ::: "memory") | ||
|
|
||
| // OAEP label for testing. | ||
| static const unsigned char kTestLabel[] = "Test label."; | ||
| static const size_t kTestLabelLen = sizeof(kTestLabel) - 1; | ||
|
|
@@ -403,12 +406,14 @@ status_t cryptolib_fi_rsa_sign_impl( | |
|
|
||
| // Trigger window. | ||
| if (uj_input.trigger & kPentestTrigger3) { | ||
| PENTEST_MARKER_LABEL(PENTEST_MARKER_RSA_SIGN_START); | ||
|
Member
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Just to correctly understand, your git commit message says "These markers do influence influence the pentest code as they are function calls." Could you please elaborate on this?
Contributor
Author
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Looking at the assembly, these markers become functions, meaning that the trigger high and low together with the payload crypto function is now executed in the PENTEST_MARKER_RSA_SIGN_START function
Contributor
Author
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. A priori, I can not guarantee that the trigger high and low did not change
Member
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Ah got it. Instead of using those marker, would it be possible to use the trigger high / low as markers? Just to avoid that we are changing the code we know works quite well.
Contributor
Author
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Sadly no since those do not have unique names. Now I can parse for the unique names and ensure we are testing the correct function
Member
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Hm I see. And parsing for the asm instruction sequence that is responsible for setting the trigger to high / low is now not possible because parsing for that would be not so easy. So I am good with that change, thanks for explaining :)
Contributor
Author
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. An example of the new binary is
Contributor
Author
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. So it looks like trigger high to the function call should be the same, but maybe trigger low moved somewhat |
||
| pentest_set_trigger_high(); | ||
| } | ||
| TRY(otcrypto_rsa_sign(&private_key, msg_digest, padding_mode, sig_buf)); | ||
| // Trigger window. | ||
| if (uj_input.trigger & kPentestTrigger3) { | ||
| pentest_set_trigger_low(); | ||
| PENTEST_MARKER_LABEL(PENTEST_MARKER_RSA_SIGN_END); | ||
| } | ||
|
|
||
| // Return data back to host. | ||
|
|
@@ -561,13 +566,16 @@ status_t cryptolib_fi_rsa_verify_impl( | |
| hardened_bool_t verification_result; | ||
| // Trigger window. | ||
| if (uj_input.trigger & kPentestTrigger3) { | ||
| PENTEST_MARKER_LABEL(PENTEST_MARKER_RSA_VERIFY_START); | ||
| pentest_set_trigger_high(); | ||
| } | ||
| TRY(otcrypto_rsa_verify(&public_key, msg_digest, padding_mode, sig, | ||
| &verification_result)); | ||
| status_t status = otcrypto_rsa_verify(&public_key, msg_digest, padding_mode, | ||
| sig, &verification_result); | ||
| if (uj_input.trigger & kPentestTrigger3) { | ||
| pentest_set_trigger_low(); | ||
| PENTEST_MARKER_LABEL(PENTEST_MARKER_RSA_VERIFY_END); | ||
| } | ||
| TRY(status); | ||
|
|
||
| // Return data back to host. | ||
| uj_output->result = true; | ||
|
|
@@ -633,9 +641,11 @@ status_t cryptolib_fi_p256_ecdh_impl( | |
| .keyblob = shared_secretblob, | ||
| }; | ||
|
|
||
| PENTEST_MARKER_LABEL(PENTEST_MARKER_P256_ECDH_START); | ||
| pentest_set_trigger_high(); | ||
| TRY(otcrypto_ecdh_p256(&private_key, &public_key, &shared_secret)); | ||
| pentest_set_trigger_low(); | ||
| PENTEST_MARKER_LABEL(PENTEST_MARKER_P256_ECDH_END); | ||
|
|
||
| uint32_t share0[kPentestP256Words]; | ||
| uint32_t share1[kPentestP256Words]; | ||
|
|
@@ -726,13 +736,15 @@ status_t cryptolib_fi_p256_sign_impl( | |
|
|
||
| // Trigger window 1. | ||
| if (uj_input.trigger == 1) { | ||
| PENTEST_MARKER_LABEL(PENTEST_MARKER_P256_SIGN_START); | ||
| pentest_set_trigger_high(); | ||
| } | ||
| // Sign the message. | ||
| TRY(otcrypto_ecdsa_p256_sign_verify(&private_key, &public_key, message_digest, | ||
| signature_mut)); | ||
| if (uj_input.trigger == 1) { | ||
| pentest_set_trigger_low(); | ||
| PENTEST_MARKER_LABEL(PENTEST_MARKER_P256_SIGN_END); | ||
| } | ||
|
|
||
| // Return data back to host. | ||
|
|
@@ -790,10 +802,12 @@ status_t cryptolib_fi_p256_verify_impl( | |
|
|
||
| hardened_bool_t verification_result = kHardenedBoolFalse; | ||
|
|
||
| PENTEST_MARKER_LABEL(PENTEST_MARKER_P256_VERIFY_START); | ||
| pentest_set_trigger_high(); | ||
| TRY(otcrypto_ecdsa_p256_verify(&public_key, message_digest, signature, | ||
| &verification_result)); | ||
| pentest_set_trigger_low(); | ||
| PENTEST_MARKER_LABEL(PENTEST_MARKER_P256_VERIFY_END); | ||
|
|
||
| // Return data back to host. | ||
| uj_output->result = true; | ||
|
|
@@ -859,9 +873,11 @@ status_t cryptolib_fi_p384_ecdh_impl( | |
| .keyblob = shared_secretblob, | ||
| }; | ||
|
|
||
| PENTEST_MARKER_LABEL(PENTEST_MARKER_P384_ECDH_START); | ||
| pentest_set_trigger_high(); | ||
| TRY(otcrypto_ecdh_p384(&private_key, &public_key, &shared_secret)); | ||
| pentest_set_trigger_low(); | ||
| PENTEST_MARKER_LABEL(PENTEST_MARKER_P384_ECDH_END); | ||
|
|
||
| uint32_t share0[kPentestP384Words]; | ||
| uint32_t share1[kPentestP384Words]; | ||
|
|
@@ -952,12 +968,14 @@ status_t cryptolib_fi_p384_sign_impl( | |
|
|
||
| // Trigger window 1. | ||
| if (uj_input.trigger == 1) { | ||
| PENTEST_MARKER_LABEL(PENTEST_MARKER_P384_SIGN_START); | ||
| pentest_set_trigger_high(); | ||
| } | ||
| TRY(otcrypto_ecdsa_p384_sign_verify(&private_key, &public_key, message_digest, | ||
| signature_mut)); | ||
| if (uj_input.trigger == 1) { | ||
| pentest_set_trigger_low(); | ||
| PENTEST_MARKER_LABEL(PENTEST_MARKER_P384_SIGN_END); | ||
| } | ||
|
|
||
| // Return data back to host. | ||
|
|
@@ -1015,10 +1033,12 @@ status_t cryptolib_fi_p384_verify_impl( | |
|
|
||
| hardened_bool_t verification_result = kHardenedBoolFalse; | ||
|
|
||
| PENTEST_MARKER_LABEL(PENTEST_MARKER_P384_VERIFY_START); | ||
| pentest_set_trigger_high(); | ||
| TRY(otcrypto_ecdsa_p384_verify(&public_key, message_digest, signature, | ||
| &verification_result)); | ||
| pentest_set_trigger_low(); | ||
| PENTEST_MARKER_LABEL(PENTEST_MARKER_P384_VERIFY_END); | ||
|
|
||
| // Return data back to host. | ||
| uj_output->result = true; | ||
|
|
||
Uh oh!
There was an error while loading. Please reload this page.