1212#include "sw/device/lib/runtime/log.h"
1313#include "sw/device/lib/testing/test_framework/check.h"
1414#include "sw/device/lib/testing/test_framework/ottf_main.h"
15+ #include "sw/device/tests/crypto/lib/crypto_test_lib.h"
1516
1617enum {
1718 /**
@@ -43,6 +44,9 @@ static const uint32_t kTestMask[ARRAYSIZE(kLongTestKey)] = {
4344 0xa7ebc3e3 , 0x04b2a1b9 , 0x764a9630 , 0x78b8f9c5 , 0x3f2a1d8e ,
4445};
4546
47+ static otcrypto_key_security_level_t current_sec_level =
48+ kOtcryptoKeySecurityLevelLow ;
49+
4650/**
4751 * Call the `otcrypto_mac` API and check the resulting tag.
4852 *
@@ -62,7 +66,7 @@ static status_t run_test(const uint32_t *key, size_t key_len,
6266 .key_length = key_len ,
6367 .hw_backed = kHardenedBoolFalse ,
6468 .exportable = kHardenedBoolFalse ,
65- .security_level = kOtcryptoKeySecurityLevelLow ,
69+ .security_level = current_sec_level ,
6670 };
6771
6872 uint32_t keyblob [keyblob_num_words (config )];
@@ -159,7 +163,7 @@ static status_t streaming_test(void) {
159163 .key_length = sizeof (kBasicTestKey ),
160164 .hw_backed = kHardenedBoolFalse ,
161165 .exportable = kHardenedBoolFalse ,
162- .security_level = kOtcryptoKeySecurityLevelLow ,
166+ .security_level = current_sec_level ,
163167 };
164168
165169 uint32_t keyblob [keyblob_num_words (config )];
@@ -214,10 +218,27 @@ static volatile status_t test_result;
214218
215219bool test_main (void ) {
216220 test_result = OK_STATUS ();
221+
222+ // Testing overall cryptolib low security, i.e., no jittery clock or dummy
223+ // instructions
217224 CHECK_STATUS_OK (otcrypto_init (kOtcryptoKeySecurityLevelLow ));
218- EXECUTE_TEST ( test_result , simple_test );
219- EXECUTE_TEST ( test_result , empty_test );
220- EXECUTE_TEST ( test_result , long_key_test ) ;
225+
226+ // Streaming test only works on low security
227+ current_sec_level = kOtcryptoKeySecurityLevelLow ;
221228 EXECUTE_TEST (test_result , streaming_test );
229+
230+ for (size_t i = 0 ; i < ARRAYSIZE (available_security_levels ); ++ i ) {
231+ current_sec_level = available_security_levels [i ];
232+ LOG_INFO ("Running HMAC tests with security level: %d" , current_sec_level );
233+
234+ EXECUTE_TEST (test_result , simple_test );
235+ EXECUTE_TEST (test_result , empty_test );
236+ EXECUTE_TEST (test_result , long_key_test );
237+
238+ if (status_err (test_result )) {
239+ break ;
240+ }
241+ }
242+
222243 return status_ok (test_result );
223244}
0 commit comments