Skip to content

Commit b89e954

Browse files
committed
[pentest] Add markers in pentest framework
In order to reliably find the calls of certain functions for GDB testing, we add markers around them which can be found in the dis file. These markers do influence the pentest code as they are function calls. Signed-off-by: Siemen Dhooghe <[email protected]>
1 parent ebee85f commit b89e954

File tree

5 files changed

+764
-906
lines changed

5 files changed

+764
-906
lines changed

sw/device/tests/penetrationtests/firmware/fi/cryptolib_fi_asym_impl.c

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -26,6 +26,9 @@
2626

2727
#define MODULE_ID MAKE_MODULE_ID('f', 'a', 'i')
2828

29+
// Markers in the dis file to be able to trace certain functions
30+
#define PENTEST_MARKER_LABEL(name) asm volatile(#name ":" ::: "memory")
31+
2932
// OAEP label for testing.
3033
static const unsigned char kTestLabel[] = "Test label.";
3134
static const size_t kTestLabelLen = sizeof(kTestLabel) - 1;
@@ -561,12 +564,14 @@ status_t cryptolib_fi_rsa_verify_impl(
561564
hardened_bool_t verification_result;
562565
// Trigger window.
563566
if (uj_input.trigger & kPentestTrigger3) {
567+
PENTEST_MARKER_LABEL(PENTEST_MARKER_RSA_VERIFY_START);
564568
pentest_set_trigger_high();
565569
}
566570
TRY(otcrypto_rsa_verify(&public_key, msg_digest, padding_mode, sig,
567571
&verification_result));
568572
if (uj_input.trigger & kPentestTrigger3) {
569573
pentest_set_trigger_low();
574+
PENTEST_MARKER_LABEL(PENTEST_MARKER_RSA_VERIFY_END);
570575
}
571576

572577
// Return data back to host.
@@ -790,10 +795,12 @@ status_t cryptolib_fi_p256_verify_impl(
790795

791796
hardened_bool_t verification_result = kHardenedBoolFalse;
792797

798+
PENTEST_MARKER_LABEL(PENTEST_MARKER_P256_VERIFY_START);
793799
pentest_set_trigger_high();
794800
TRY(otcrypto_ecdsa_p256_verify(&public_key, message_digest, signature,
795801
&verification_result));
796802
pentest_set_trigger_low();
803+
PENTEST_MARKER_LABEL(PENTEST_MARKER_P256_VERIFY_END);
797804

798805
// Return data back to host.
799806
uj_output->result = true;
@@ -1015,10 +1022,12 @@ status_t cryptolib_fi_p384_verify_impl(
10151022

10161023
hardened_bool_t verification_result = kHardenedBoolFalse;
10171024

1025+
PENTEST_MARKER_LABEL(PENTEST_MARKER_P384_VERIFY_START);
10181026
pentest_set_trigger_high();
10191027
TRY(otcrypto_ecdsa_p384_verify(&public_key, message_digest, signature,
10201028
&verification_result));
10211029
pentest_set_trigger_low();
1030+
PENTEST_MARKER_LABEL(PENTEST_MARKER_P384_VERIFY_END);
10221031

10231032
// Return data back to host.
10241033
uj_output->result = true;

sw/device/tests/penetrationtests/firmware/fi/cryptolib_fi_sym_impl.c

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -22,6 +22,9 @@
2222

2323
#define MODULE_ID MAKE_MODULE_ID('c', 'f', 's')
2424

25+
// Markers in the dis file to be able to trace certain functions
26+
#define PENTEST_MARKER_LABEL(name) asm volatile(#name ":" ::: "memory")
27+
2528
status_t cryptolib_fi_aes_impl(cryptolib_fi_sym_aes_in_t uj_input,
2629
cryptolib_fi_sym_aes_out_t *uj_output) {
2730
// Set the AES mode.
@@ -298,10 +301,12 @@ status_t cryptolib_fi_gcm_impl(cryptolib_fi_sym_gcm_in_t uj_input,
298301
}
299302

300303
// Trigger window.
304+
PENTEST_MARKER_LABEL(PENTEST_MARKER_GCM_ENCRYPT_START);
301305
pentest_set_trigger_high();
302306
TRY(otcrypto_aes_gcm_encrypt(&key, plaintext, iv, aad, tag_len,
303307
actual_ciphertext, actual_tag));
304308
pentest_set_trigger_low();
309+
PENTEST_MARKER_LABEL(PENTEST_MARKER_GCM_ENCRYPT_END);
305310

306311
// Return data back to host.
307312
uj_output->cfg = 0;
@@ -385,9 +390,11 @@ status_t cryptolib_fi_hmac_impl(cryptolib_fi_sym_hmac_in_t uj_input,
385390
};
386391

387392
// Trigger window.
393+
PENTEST_MARKER_LABEL(PENTEST_MARKER_HMAC_START);
388394
pentest_set_trigger_high();
389395
TRY(otcrypto_hmac(&key, input_message, tag));
390396
pentest_set_trigger_low();
397+
PENTEST_MARKER_LABEL(PENTEST_MARKER_HMAC_END);
391398

392399
// Return data back to host.
393400
uj_output->data_len = tag_bytes;

0 commit comments

Comments
 (0)