Skip to content

Commit

Permalink
amend! amend! amend! amend! amend! amend! xtest: add asymmetric ciphe…
Browse files Browse the repository at this point in the history
…r perf test

rename acipher_perf.c to asym_perf.c

xtest: add asymmetric cipher perf test

Add perf test for DH, RSA, ECDH, ECDSA algorithm

Signed-off-by: Zexi Yu <[email protected]>
  • Loading branch information
yuzexiyzx committed Dec 18, 2023
1 parent 753abb8 commit 3c5c5b5
Show file tree
Hide file tree
Showing 5 changed files with 28 additions and 20 deletions.
2 changes: 1 addition & 1 deletion Android.mk
Original file line number Diff line number Diff line change
Expand Up @@ -43,7 +43,7 @@ srcs += adbg/src/adbg_case.c \
adbg/src/adbg_run.c \
adbg/src/security_utils_hex.c \
aes_perf.c \
acipher_perf.c \
asym_perf.c \
benchmark_1000.c \
benchmark_2000.c \
clear_storage.c \
Expand Down
2 changes: 1 addition & 1 deletion host/xtest/CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -46,7 +46,7 @@ set (SRC
adbg/src/adbg_run.c
adbg/src/security_utils_hex.c
aes_perf.c
acipher_perf.c
asym_perf.c
benchmark_1000.c
benchmark_2000.c
clear_storage.c
Expand Down
2 changes: 1 addition & 1 deletion host/xtest/Makefile
Original file line number Diff line number Diff line change
Expand Up @@ -58,7 +58,7 @@ srcs += adbg/src/adbg_case.c \
adbg/src/adbg_run.c \
adbg/src/security_utils_hex.c \
aes_perf.c \
acipher_perf.c \
asym_perf.c \
benchmark_1000.c \
benchmark_2000.c \
clear_storage.c \
Expand Down
38 changes: 23 additions & 15 deletions host/xtest/acipher_perf.c → host/xtest/asym_perf.c
Original file line number Diff line number Diff line change
Expand Up @@ -657,29 +657,37 @@ static int check_rsa_hash_params(uint32_t rsa_algo, int width_bits, int size,
if (hash_len == -1)
return -1;

if (rsa_algo == RSASSA_PKCS1_V1_5_SHA1 &&
width_bytes < hash_len + DERCODE_SHA1_LEN + PKCS_V1_5_MIN) {
fprintf(stderr, "The size or algo is not valid!\n");
return -1;
} else if (rsa_algo >= RSASSA_PKCS1_V1_5_SHA1 &&
rsa_algo <= RSASSA_PKCS1_V1_5_SHA512 &&
width_bytes < hash_len + DERCODE_SHA_LEN + PKCS_V1_5_MIN) {
fprintf(stderr, "The size or algo is not valid!\n");
return -1;
} else if (rsa_algo >= RSASSA_PKCS1_PSS_MGF1_SHA1 &&
rsa_algo <= RSASSA_PKCS1_PSS_MGF1_SHA512) {
switch (rsa_algo) {
case RSASSA_PKCS1_V1_5_SHA1:
if (width_bytes < hash_len + DERCODE_SHA1_LEN + PKCS_V1_5_MIN) {
fprintf(stderr, "The size or algo is not valid!\n");
return -1;
}
return 0;
case RSASSA_PKCS1_V1_5_SHA224:
case RSASSA_PKCS1_V1_5_SHA256:
case RSASSA_PKCS1_V1_5_SHA384:
case RSASSA_PKCS1_V1_5_SHA512:
if (width_bytes < hash_len + DERCODE_SHA_LEN + PKCS_V1_5_MIN) {
fprintf(stderr, "The size or algo is not valid!\n");
return -1;
}
return 0;
case RSASSA_PKCS1_PSS_MGF1_SHA1:
case RSASSA_PKCS1_PSS_MGF1_SHA224:
case RSASSA_PKCS1_PSS_MGF1_SHA256:
case RSASSA_PKCS1_PSS_MGF1_SHA384:
case RSASSA_PKCS1_PSS_MGF1_SHA512:
salt_temp = (salt_len == 0 ? hash_len : salt_len);

if (salt_temp > width_bytes ||
width_bytes < hash_len + salt_temp + PSS_OTHER_LEN) {
fprintf(stderr, "The size or algo is not valid!\n");
return -1;
}
} else {
return 0;
default:
return -1;
}

return 0;
}

int asym_perf_runner_cmd_parser(int argc, char *argv[])
Expand Down
4 changes: 2 additions & 2 deletions host/xtest/xtest_main.c
Original file line number Diff line number Diff line change
Expand Up @@ -103,7 +103,7 @@ void usage(char *program)
printf("\t--sha-perf [opts] Deprecated, same as --hash-perf\n");
printf("\t--hash-perf [opts] Hash performance testing tool (-h for usage)\n");
printf("\t--aes-perf [opts] AES performance testing tool (-h for usage)\n");
printf("\t--acipher-perf [opts] Acipher performance testing tool (-h for usage)\n");
printf("\t--asym-perf [opts] Asym performance testing tool (-h for usage)\n");
#ifdef CFG_SECSTOR_TA_MGMT_PTA
printf("\t--install-ta [directory or list of TAs]\n");
printf("\t Install TAs\n");
Expand Down Expand Up @@ -170,7 +170,7 @@ int main(int argc, char *argv[])
return hash_perf_runner_cmd_parser(argc-1, &argv[1]);
else if (argc > 1 && !strcmp(argv[1], "--aes-perf"))
return aes_perf_runner_cmd_parser(argc-1, &argv[1]);
else if (argc > 1 && !strcmp(argv[1], "--acipher-perf"))
else if (argc > 1 && !strcmp(argv[1], "--asym-perf"))
return asym_perf_runner_cmd_parser(argc-1, &argv[1]);
#ifdef CFG_SECSTOR_TA_MGMT_PTA
else if (argc > 1 && !strcmp(argv[1], "--install-ta"))
Expand Down

0 comments on commit 3c5c5b5

Please sign in to comment.