diff options
author | Paul Selkirk <paul@psgd.org> | 2019-01-12 18:20:10 -0500 |
---|---|---|
committer | Paul Selkirk <paul@psgd.org> | 2019-01-12 18:20:10 -0500 |
commit | 44dc84d3696795fbe0b6f1786cabaa08fd88ade6 (patch) | |
tree | 34f3fa7cc69b5f89c4c6cc90d6015b24fe9eba53 /projects/cli-test/mgmt-keywrap.c | |
parent | 07af68c08baefbced001a0081256cb1fff8ed491 (diff) |
Timing tests for RSA signing and sub-components thereof.
This is not the sort of thing that should go anywhere near production
code, so it's on a dangling branch. I may rebase it from time to time.
Diffstat (limited to 'projects/cli-test/mgmt-keywrap.c')
-rw-r--r-- | projects/cli-test/mgmt-keywrap.c | 81 |
1 files changed, 61 insertions, 20 deletions
diff --git a/projects/cli-test/mgmt-keywrap.c b/projects/cli-test/mgmt-keywrap.c index 7d3e219..920d1ee 100644 --- a/projects/cli-test/mgmt-keywrap.c +++ b/projects/cli-test/mgmt-keywrap.c @@ -232,10 +232,19 @@ static int cmd_keywrap_test(struct cli_def *cli, const char *command, char *argv cli_print(cli, "with %s: OK", i ? "keywrap core" : "software keywrap"); } + uint32_t start, elapsed, per; +#define TIMER_START() \ + start = HAL_GetTick() +#define TIMER_STOP(op) \ + elapsed = HAL_GetTick() - start; \ + per = 1000 * elapsed / iterations; \ + cli_print(cli, "%ld.%03lds total, %ld.%03ldms per " op, \ + elapsed / 1000, elapsed % 1000, per / 1000, per % 1000) + cli_print(cli, "\n2. wrap timing with software keywrap"); hal_aes_use_keywrap_core(0); - uint32_t start = HAL_GetTick(); + TIMER_START(); for (int i = 0; i < iterations; ++i) { C_len = sizeof(C); if ((err = hal_aes_keywrap(NULL, K_256, sizeof(K_256), Q, keysize, C, &C_len)) != LIBHAL_OK) { @@ -243,10 +252,7 @@ static int cmd_keywrap_test(struct cli_def *cli, const char *command, char *argv return CLI_ERROR; } } - uint32_t elapsed = HAL_GetTick() - start; - uint32_t per = 1000 * elapsed / iterations; - cli_print(cli, "%ld.%03lds total, %ld.%03ldms per wrap", - elapsed / 1000, elapsed % 1000, per / 1000, per % 1000); + TIMER_STOP("wrap"); cli_print(cli, "\n3. wrap timing with keywrap core"); @@ -254,7 +260,7 @@ static int cmd_keywrap_test(struct cli_def *cli, const char *command, char *argv cli_print(cli, "keywrap core not found, skipping"); } else { - start = HAL_GetTick(); + TIMER_START(); for (int i = 0; i < iterations; ++i) { C_len = sizeof(C); if ((err = hal_aes_keywrap(NULL, K_256, sizeof(K_256), Q, keysize, C, &C_len)) != LIBHAL_OK) { @@ -262,16 +268,13 @@ static int cmd_keywrap_test(struct cli_def *cli, const char *command, char *argv 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); + TIMER_STOP("wrap"); } cli_print(cli, "\n4. unwrap timing with software keywrap"); hal_aes_use_keywrap_core(0); - start = HAL_GetTick(); + TIMER_START(); for (int i = 0; i < iterations; ++i) { Q_len = sizeof(Q); if ((err = hal_aes_keyunwrap(NULL, K_256, sizeof(K_256), C, C_len, Q, &Q_len)) != LIBHAL_OK) { @@ -279,10 +282,7 @@ static int cmd_keywrap_test(struct cli_def *cli, const char *command, char *argv 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); + TIMER_STOP("unwrap"); cli_print(cli, "\n5. unwrap timing with keywrap core"); @@ -290,7 +290,7 @@ static int cmd_keywrap_test(struct cli_def *cli, const char *command, char *argv cli_print(cli, "keywrap core not found, skipping"); } else { - start = HAL_GetTick(); + TIMER_START(); for (int i = 0; i < iterations; ++i) { Q_len = sizeof(Q); if ((err = hal_aes_keyunwrap(NULL, K_256, sizeof(K_256), C, C_len, Q, &Q_len)) != LIBHAL_OK) { @@ -298,19 +298,60 @@ static int cmd_keywrap_test(struct cli_def *cli, const char *command, char *argv 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); + TIMER_STOP("unwrap"); + } + + uint8_t kek[KEK_LENGTH]; + size_t kek_len; + cli_print(cli, "\n6. hal_mkm_get_kek"); + TIMER_START(); + for (int i = 0; i < iterations; ++i) { + if ((err = hal_mkm_get_kek(kek, &kek_len, sizeof(kek))) != LIBHAL_OK) { + cli_print(cli, "hal_mkm_get_kek: %s", hal_error_string(err)); + return CLI_ERROR; + } } + TIMER_STOP("fetch"); + +#undef TIMER_START +#undef TIMER_STOP return CLI_OK; } +static int cmd_keywrap_core(struct cli_def *cli, const char *command, char *argv[], int argc) +{ + command = command; + + if (argc == 1) { + int onoff = -1; + if (strcmp(argv[0], "on") == 0) + onoff = 1; + else if (strcmp(argv[0], "off") == 0) + onoff = 0; + if (onoff >= 0) { + int ret = hal_aes_use_keywrap_core(onoff); + if (ret) + cli_print(cli, "keywrap core enabled"); + else if (onoff) + cli_print(cli, "keywrap core not found"); + else + cli_print(cli, "keywrap core disabled"); + return CLI_OK; + } + } + + cli_print(cli, "Syntax: keywrap core <on|off>"); + return CLI_ERROR; +} + void configure_cli_keywrap(struct cli_def *cli) { struct cli_command *c_keywrap = cli_register_command(cli, NULL, "keywrap", NULL, 0, 0, NULL); + /* keywrap core */ + cli_register_command(cli, c_keywrap, "core", cmd_keywrap_core, 0, 0, "Toggle use of the keywrap core"); + /* keywrap test */ cli_register_command(cli, c_keywrap, "test", cmd_keywrap_test, 0, 0, "Test the keywrap core"); } |