aboutsummaryrefslogtreecommitdiff
path: root/projects
diff options
context:
space:
mode:
Diffstat (limited to 'projects')
-rw-r--r--projects/cli-test/mgmt-keywrap.c50
1 files changed, 40 insertions, 10 deletions
diff --git a/projects/cli-test/mgmt-keywrap.c b/projects/cli-test/mgmt-keywrap.c
index 798206d..1f98658 100644
--- a/projects/cli-test/mgmt-keywrap.c
+++ b/projects/cli-test/mgmt-keywrap.c
@@ -165,10 +165,7 @@ static int cmd_keywrap_test(struct cli_def *cli, const char *command, char *argv
cli_print(cli, "\n2. Test vectors with keywrap core");
if (hal_aes_use_keywrap_core(1) == 0) {
- cli_print(cli, "keywrap core not found");
-#if 0
- return CLI_ERROR;
-#endif
+ cli_print(cli, "keywrap core not found, skipping");
}
else {
run_test(cli, K_128, sizeof(K_128), C_128, sizeof(C_128));
@@ -188,8 +185,8 @@ static int cmd_keywrap_test(struct cli_def *cli, const char *command, char *argv
if (keysize <= 0 || iterations <= 0)
goto usage;
- uint8_t Q[keysize + 8];
- uint8_t C[keysize + 8];
+ uint8_t Q[keysize + 8]; size_t Q_len;
+ uint8_t C[keysize + 8]; size_t C_len;
memset(C, 0, sizeof(C));
if ((err = hal_get_random(NULL, Q, keysize)) != LIBHAL_OK) {
cli_print(cli, "hal_get_random: %s", hal_error_string(err));
@@ -203,10 +200,9 @@ static int cmd_keywrap_test(struct cli_def *cli, const char *command, char *argv
return CLI_ERROR;
}
- cli_print(cli, "\n3. timing with software keywrap");
+ cli_print(cli, "\n3. wrap timing with software keywrap");
hal_aes_use_keywrap_core(0);
- size_t C_len = sizeof(C);
uint32_t start = HAL_GetTick();
for (int i = 0; i < iterations; ++i) {
C_len = sizeof(C);
@@ -220,7 +216,7 @@ static int cmd_keywrap_test(struct cli_def *cli, const char *command, char *argv
cli_print(cli, "%ld.%03lds total, %ld.%03ldms per wrap",
elapsed / 1000, elapsed % 1000, per / 1000, per % 1000);
- cli_print(cli, "\n4. timing with keywrap core");
+ cli_print(cli, "\n4. wrap timing with keywrap core");
if (hal_aes_use_keywrap_core(1) == 0) {
cli_print(cli, "keywrap core not found, skipping");
@@ -240,7 +236,41 @@ static int cmd_keywrap_test(struct cli_def *cli, const char *command, char *argv
elapsed / 1000, elapsed % 1000, per / 1000, per % 1000);
}
- /* XXX measure unwrap timing as well */
+ cli_print(cli, "\n5. unwrap timing with software keywrap");
+
+ hal_aes_use_keywrap_core(0);
+ start = HAL_GetTick();
+ for (int i = 0; i < iterations; ++i) {
+ Q_len = sizeof(Q);
+ if ((err = hal_aes_keyunwrap(NULL, kek, kek_len, C, C_len, Q, &Q_len)) != LIBHAL_OK) {
+ cli_print(cli, "hal_aes_keyunwrap: %s", hal_error_string(err));
+ return CLI_ERROR;
+ }
+ }
+ elapsed = HAL_GetTick() - start;
+ per = 1000 * elapsed / iterations;
+ cli_print(cli, "%ld.%03lds total, %ld.%03ldms per wrap",
+ elapsed / 1000, elapsed % 1000, per / 1000, per % 1000);
+
+ cli_print(cli, "\n6. unwrap timing with keywrap core");
+
+ if (hal_aes_use_keywrap_core(1) == 0) {
+ cli_print(cli, "keywrap core not found, skipping");
+ }
+ else {
+ start = HAL_GetTick();
+ for (int i = 0; i < iterations; ++i) {
+ Q_len = sizeof(Q);
+ if ((err = hal_aes_keyunwrap(NULL, kek, kek_len, C, C_len, Q, &Q_len)) != LIBHAL_OK) {
+ cli_print(cli, "hal_aes_keywrap: %s", hal_error_string(err));
+ return CLI_ERROR;
+ }
+ }
+ elapsed = HAL_GetTick() - start;
+ per = 1000 * elapsed / iterations;
+ cli_print(cli, "%ld.%03lds total, %ld.%03ldms per wrap",
+ elapsed / 1000, elapsed % 1000, per / 1000, per % 1000);
+ }
return CLI_OK;
}