Skip to content

Commit e460335

Browse files
committed
[pentest] Add crypto version
Add the version of the crypto library to the pentest framework's readout for the crypto related init functions. Signed-off-by: Siemen Dhooghe <[email protected]>
1 parent 49bf98e commit e460335

22 files changed

+574
-424
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: 13 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,17 @@ 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+
base_snprintf(cryptolib_version, sizeof(cryptolib_version),
522+
"CRYPTO version %d, released %s, hash %08x%08x", version,
523+
released ? "true" : "false", build_hash_high, build_hash_low);
524+
RESP_OK(ujson_serialize_string, uj, cryptolib_version);
513525
/////////////// STUB END ///////////////
514526

515527
return OK_STATUS();

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

Lines changed: 12 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,16 @@ 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+
base_snprintf(cryptolib_version, sizeof(cryptolib_version),
236+
"CRYPTO version %d, released %s, hash %08x%08x", version,
237+
released ? "true" : "false", build_hash_high, build_hash_low);
227238
/////////////// STUB END ///////////////
228239

229240
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: 13 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,17 @@ 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+
base_snprintf(cryptolib_version, sizeof(cryptolib_version),
878+
"CRYPTO version %d, released %s, hash %08x%08x", version,
879+
released ? "true" : "false", build_hash_high, build_hash_low);
880+
RESP_OK(ujson_serialize_string, uj, cryptolib_version);
869881
/////////////// STUB END ///////////////
870882

871883
return OK_STATUS();

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

Lines changed: 13 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,17 @@ 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+
base_snprintf(cryptolib_version, sizeof(cryptolib_version),
930+
"CRYPTO version %d, released %s, hash %08x%08x", version,
931+
released ? "true" : "false", build_hash_high, build_hash_low);
932+
RESP_OK(ujson_serialize_string, uj, cryptolib_version);
921933
/////////////// STUB END ///////////////
922934

923935
return OK_STATUS();

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

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -5,6 +5,7 @@
55
66
Communication with OpenTitan happens over the uJSON command interface.
77
"""
8+
89
import json
910
import time
1011
from sw.host.penetrationtests.python.util import common_library
@@ -51,6 +52,7 @@ def init(
5152
boot_log = self.target.read_response()
5253
boot_measurements = self.target.read_response()
5354
version = self.target.read_response()
55+
cryptolib_version = self.target.read_response()
5456
return (
5557
device_id,
5658
sensors,
@@ -59,6 +61,7 @@ def init(
5961
boot_log,
6062
boot_measurements,
6163
version,
64+
cryptolib_version,
6265
)
6366

6467
def handle_rsa_enc(

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

Lines changed: 7 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -5,6 +5,7 @@
55
66
Communication with OpenTitan happens over the uJSON command interface.
77
"""
8+
89
import json
910
import time
1011
from sw.host.penetrationtests.python.util import common_library
@@ -51,6 +52,7 @@ def init(
5152
boot_log = self.target.read_response()
5253
boot_measurements = self.target.read_response()
5354
version = self.target.read_response()
55+
cryptolib_version = self.target.read_response()
5456
return (
5557
device_id,
5658
sensors,
@@ -59,6 +61,7 @@ def init(
5961
boot_log,
6062
boot_measurements,
6163
version,
64+
cryptolib_version,
6265
)
6366

6467
def handle_aes(
@@ -94,9 +97,7 @@ def handle_aes(
9497
}
9598
self.target.write(json.dumps(input_data).encode("ascii"))
9699

97-
def handle_cmac(
98-
self, data, data_len, key, key_len, iv, cfg, trigger
99-
) -> None:
100+
def handle_cmac(self, data, data_len, key, key_len, iv, cfg, trigger) -> None:
100101
"""Call the cryptolib CMAC.
101102
102103
Args:
@@ -214,9 +215,7 @@ def handle_drbg_reseed(
214215
}
215216
self.target.write(json.dumps(input_data).encode("ascii"))
216217

217-
def handle_drbg_generate(
218-
self, nonce, nonce_len, data_len, mode, cfg, trigger
219-
) -> None:
218+
def handle_drbg_generate(self, nonce, nonce_len, data_len, mode, cfg, trigger) -> None:
220219
"""Call the cryptolib DRBG to generate randomness.
221220
222221
Args:
@@ -240,9 +239,7 @@ def handle_drbg_generate(
240239
}
241240
self.target.write(json.dumps(input_data).encode("ascii"))
242241

243-
def handle_trng_init(
244-
self, mode, cfg, trigger
245-
) -> None:
242+
def handle_trng_init(self, mode, cfg, trigger) -> None:
246243
"""Call the cryptolib TRNG to init.
247244
248245
Args:
@@ -259,9 +256,7 @@ def handle_trng_init(
259256
}
260257
self.target.write(json.dumps(input_data).encode("ascii"))
261258

262-
def handle_trng_generate(
263-
self, cfg, trigger
264-
) -> None:
259+
def handle_trng_generate(self, cfg, trigger) -> None:
265260
"""Call the cryptolib TRNG to generate randomness.
266261
267262
Args:

0 commit comments

Comments
 (0)