Skip to content

Commit d4df30f

Browse files
siemen11nasahlpa
authored andcommitted
[pentest] Add crypto version
Add the version of the crypto library to the pentest framework's readout for the crypto related init functions. In order to have the latest git hash be printed as the version, all commands or tests should be run with the --stamp flag in the Bazel command. Signed-off-by: Siemen Dhooghe <[email protected]>
1 parent f80d21f commit d4df30f

22 files changed

+519
-100
lines changed

sw/device/tests/penetrationtests/firmware/fi/BUILD

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -76,6 +76,7 @@ cc_library(
7676
"//sw/device/lib/base:math",
7777
"//sw/device/lib/base:memory",
7878
"//sw/device/lib/base:status",
79+
"//sw/device/lib/crypto/impl:cryptolib_build_info",
7980
"//sw/device/lib/crypto/impl:ecc_p256",
8081
"//sw/device/lib/crypto/impl:ecc_p384",
8182
"//sw/device/lib/crypto/impl:integrity",
@@ -105,6 +106,7 @@ cc_library(
105106
"//sw/device/lib/base:status",
106107
"//sw/device/lib/crypto/impl:aes",
107108
"//sw/device/lib/crypto/impl:aes_gcm",
109+
"//sw/device/lib/crypto/impl:cryptolib_build_info",
108110
"//sw/device/lib/crypto/impl:drbg",
109111
"//sw/device/lib/crypto/impl:hmac",
110112
"//sw/device/lib/crypto/impl:integrity",

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

Lines changed: 14 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -6,6 +6,8 @@
66

77
#include "sw/device/lib/base/memory.h"
88
#include "sw/device/lib/base/status.h"
9+
#include "sw/device/lib/crypto/drivers/cryptolib_build_info.h"
10+
#include "sw/device/lib/crypto/include/cryptolib_build_info.h"
911
#include "sw/device/lib/runtime/log.h"
1012
#include "sw/device/lib/testing/test_framework/ottf_test_config.h"
1113
#include "sw/device/lib/testing/test_framework/ujson_ottf.h"
@@ -509,7 +511,18 @@ status_t handle_cryptolib_fi_asym_init(ujson_t *uj) {
509511
TRY(pentest_send_sku_config(uj));
510512

511513
/////////////// STUB START ///////////////
512-
// Add things like versioning.
514+
uint32_t version;
515+
bool released;
516+
uint32_t build_hash_low;
517+
uint32_t build_hash_high;
518+
TRY(otcrypto_build_info(&version, &released, &build_hash_low,
519+
&build_hash_high));
520+
char cryptolib_version[150];
521+
memset(cryptolib_version, '\0', sizeof(cryptolib_version));
522+
base_snprintf(cryptolib_version, sizeof(cryptolib_version),
523+
"CRYPTO version %08x, released %s, hash %08x%08x", version,
524+
released ? "true" : "false", build_hash_high, build_hash_low);
525+
RESP_OK(ujson_serialize_string, uj, cryptolib_version);
513526
/////////////// STUB END ///////////////
514527

515528
return OK_STATUS();

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

Lines changed: 14 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -6,6 +6,8 @@
66

77
#include "sw/device/lib/base/memory.h"
88
#include "sw/device/lib/base/status.h"
9+
#include "sw/device/lib/crypto/drivers/cryptolib_build_info.h"
10+
#include "sw/device/lib/crypto/include/cryptolib_build_info.h"
911
#include "sw/device/lib/runtime/log.h"
1012
#include "sw/device/lib/testing/test_framework/ottf_test_config.h"
1113
#include "sw/device/lib/testing/test_framework/ujson_ottf.h"
@@ -223,7 +225,18 @@ status_t handle_cryptolib_fi_sym_init(ujson_t *uj) {
223225
TRY(pentest_send_sku_config(uj));
224226

225227
/////////////// STUB START ///////////////
226-
// Add things like versioning.
228+
uint32_t version;
229+
bool released;
230+
uint32_t build_hash_low;
231+
uint32_t build_hash_high;
232+
TRY(otcrypto_build_info(&version, &released, &build_hash_low,
233+
&build_hash_high));
234+
char cryptolib_version[150];
235+
memset(cryptolib_version, '\0', sizeof(cryptolib_version));
236+
base_snprintf(cryptolib_version, sizeof(cryptolib_version),
237+
"CRYPTO version %08x, released %s, hash %08x%08x", version,
238+
released ? "true" : "false", build_hash_high, build_hash_low);
239+
RESP_OK(ujson_serialize_string, uj, cryptolib_version);
227240
/////////////// STUB END ///////////////
228241

229242
return OK_STATUS();

sw/device/tests/penetrationtests/firmware/sca/BUILD

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -73,6 +73,7 @@ cc_library(
7373
"//sw/device/lib/base:math",
7474
"//sw/device/lib/base:memory",
7575
"//sw/device/lib/base:status",
76+
"//sw/device/lib/crypto/impl:cryptolib_build_info",
7677
"//sw/device/lib/crypto/impl:ecc_p256",
7778
"//sw/device/lib/crypto/impl:ecc_p384",
7879
"//sw/device/lib/crypto/impl:integrity",
@@ -102,6 +103,7 @@ cc_library(
102103
"//sw/device/lib/base:status",
103104
"//sw/device/lib/crypto/impl:aes",
104105
"//sw/device/lib/crypto/impl:aes_gcm",
106+
"//sw/device/lib/crypto/impl:cryptolib_build_info",
105107
"//sw/device/lib/crypto/impl:drbg",
106108
"//sw/device/lib/crypto/impl:hmac",
107109
"//sw/device/lib/crypto/impl:integrity",

sw/device/tests/penetrationtests/firmware/sca/cryptolib_sca_asym.c

Lines changed: 14 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -6,6 +6,8 @@
66

77
#include "sw/device/lib/base/memory.h"
88
#include "sw/device/lib/base/status.h"
9+
#include "sw/device/lib/crypto/drivers/cryptolib_build_info.h"
10+
#include "sw/device/lib/crypto/include/cryptolib_build_info.h"
911
#include "sw/device/lib/runtime/log.h"
1012
#include "sw/device/lib/testing/test_framework/ottf_test_config.h"
1113
#include "sw/device/lib/testing/test_framework/ujson_ottf.h"
@@ -865,7 +867,18 @@ status_t handle_cryptolib_sca_asym_init(ujson_t *uj) {
865867
TRY(pentest_send_sku_config(uj));
866868

867869
/////////////// STUB START ///////////////
868-
// Add things like versioning.
870+
uint32_t version;
871+
bool released;
872+
uint32_t build_hash_low;
873+
uint32_t build_hash_high;
874+
TRY(otcrypto_build_info(&version, &released, &build_hash_low,
875+
&build_hash_high));
876+
char cryptolib_version[150];
877+
memset(cryptolib_version, '\0', sizeof(cryptolib_version));
878+
base_snprintf(cryptolib_version, sizeof(cryptolib_version),
879+
"CRYPTO version %08x, released %s, hash %08x%08x", version,
880+
released ? "true" : "false", build_hash_high, build_hash_low);
881+
RESP_OK(ujson_serialize_string, uj, cryptolib_version);
869882
/////////////// STUB END ///////////////
870883

871884
return OK_STATUS();

sw/device/tests/penetrationtests/firmware/sca/cryptolib_sca_sym.c

Lines changed: 14 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -6,6 +6,8 @@
66

77
#include "sw/device/lib/base/memory.h"
88
#include "sw/device/lib/base/status.h"
9+
#include "sw/device/lib/crypto/drivers/cryptolib_build_info.h"
10+
#include "sw/device/lib/crypto/include/cryptolib_build_info.h"
911
#include "sw/device/lib/runtime/log.h"
1012
#include "sw/device/lib/testing/test_framework/ottf_test_config.h"
1113
#include "sw/device/lib/testing/test_framework/ujson_ottf.h"
@@ -917,7 +919,18 @@ status_t handle_cryptolib_sca_sym_init(ujson_t *uj) {
917919
TRY(pentest_send_sku_config(uj));
918920

919921
/////////////// STUB START ///////////////
920-
// Add things like versioning.
922+
uint32_t version;
923+
bool released;
924+
uint32_t build_hash_low;
925+
uint32_t build_hash_high;
926+
TRY(otcrypto_build_info(&version, &released, &build_hash_low,
927+
&build_hash_high));
928+
char cryptolib_version[150];
929+
memset(cryptolib_version, '\0', sizeof(cryptolib_version));
930+
base_snprintf(cryptolib_version, sizeof(cryptolib_version),
931+
"CRYPTO version %08x, released %s, hash %08x%08x", version,
932+
released ? "true" : "false", build_hash_high, build_hash_low);
933+
RESP_OK(ujson_serialize_string, uj, cryptolib_version);
921934
/////////////// STUB END ///////////////
922935

923936
return OK_STATUS();

sw/host/penetrationtests/python/fi/communication/fi_asym_cryptolib_commands.py

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -52,6 +52,7 @@ def init(
5252
boot_log = self.target.read_response()
5353
boot_measurements = self.target.read_response()
5454
version = self.target.read_response()
55+
cryptolib_version = self.target.read_response()
5556
return (
5657
device_id,
5758
sensors,
@@ -60,6 +61,7 @@ def init(
6061
boot_log,
6162
boot_measurements,
6263
version,
64+
cryptolib_version,
6365
)
6466

6567
def handle_rsa_enc(

sw/host/penetrationtests/python/fi/communication/fi_sym_cryptolib_commands.py

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -52,6 +52,7 @@ def init(
5252
boot_log = self.target.read_response()
5353
boot_measurements = self.target.read_response()
5454
version = self.target.read_response()
55+
cryptolib_version = self.target.read_response()
5556
return (
5657
device_id,
5758
sensors,
@@ -60,6 +61,7 @@ def init(
6061
boot_log,
6162
boot_measurements,
6263
version,
64+
cryptolib_version,
6365
)
6466

6567
def handle_aes(

0 commit comments

Comments
 (0)