Skip to content

Commit e0bb188

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 e0bb188

20 files changed

+566
-424
lines changed

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

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

77
#include "sw/device/lib/base/memory.h"
88
#include "sw/device/lib/base/status.h"
9+
#include "sw/device/lib/crypto/include/cryptolib_build_info.h"
910
#include "sw/device/lib/runtime/log.h"
1011
#include "sw/device/lib/testing/test_framework/ottf_test_config.h"
1112
#include "sw/device/lib/testing/test_framework/ujson_ottf.h"
@@ -509,7 +510,17 @@ status_t handle_cryptolib_fi_asym_init(ujson_t *uj) {
509510
TRY(pentest_send_sku_config(uj));
510511

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

515526
return OK_STATUS();

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

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

77
#include "sw/device/lib/base/memory.h"
88
#include "sw/device/lib/base/status.h"
9+
#include "sw/device/lib/crypto/include/cryptolib_build_info.h"
910
#include "sw/device/lib/runtime/log.h"
1011
#include "sw/device/lib/testing/test_framework/ottf_test_config.h"
1112
#include "sw/device/lib/testing/test_framework/ujson_ottf.h"
@@ -223,7 +224,16 @@ status_t handle_cryptolib_fi_sym_init(ujson_t *uj) {
223224
TRY(pentest_send_sku_config(uj));
224225

225226
/////////////// STUB START ///////////////
226-
// Add things like versioning.
227+
uint32_t version;
228+
bool released;
229+
uint32_t build_hash_low;
230+
uint32_t build_hash_high;
231+
TRY(otcrypto_build_info(&version, &released, &build_hash_low,
232+
&build_hash_high));
233+
char cryptolib_version[150];
234+
base_snprintf(cryptolib_version, sizeof(cryptolib_version),
235+
"CRYPTO version %d, released %s, hash %08x%08x", version,
236+
released ? "true" : "false", build_hash_high, build_hash_low);
227237
/////////////// STUB END ///////////////
228238

229239
return OK_STATUS();

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

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

77
#include "sw/device/lib/base/memory.h"
88
#include "sw/device/lib/base/status.h"
9+
#include "sw/device/lib/crypto/include/cryptolib_build_info.h"
910
#include "sw/device/lib/runtime/log.h"
1011
#include "sw/device/lib/testing/test_framework/ottf_test_config.h"
1112
#include "sw/device/lib/testing/test_framework/ujson_ottf.h"
@@ -865,7 +866,17 @@ status_t handle_cryptolib_sca_asym_init(ujson_t *uj) {
865866
TRY(pentest_send_sku_config(uj));
866867

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

871882
return OK_STATUS();

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

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

77
#include "sw/device/lib/base/memory.h"
88
#include "sw/device/lib/base/status.h"
9+
#include "sw/device/lib/crypto/include/cryptolib_build_info.h"
910
#include "sw/device/lib/runtime/log.h"
1011
#include "sw/device/lib/testing/test_framework/ottf_test_config.h"
1112
#include "sw/device/lib/testing/test_framework/ujson_ottf.h"
@@ -917,7 +918,17 @@ status_t handle_cryptolib_sca_sym_init(ujson_t *uj) {
917918
TRY(pentest_send_sku_config(uj));
918919

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

923934
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)