1 // SPDX-License-Identifier: GPL-2.0
2 /*
3 * Copyright (c) 2015, Linaro Limited
4 */
5
6 #include <stdio.h>
7 #include <stdlib.h>
8 #include <string.h>
9
10 #include "xtest_test.h"
11 #include "xtest_helpers.h"
12
13 #include <crypto_common.h>
14 #include <util.h>
15
16 /* SHA bechmarks */
17 static void xtest_tee_benchmark_2001(ADBG_Case_t *Case_p);
18 static void xtest_tee_benchmark_2002(ADBG_Case_t *Case_p);
19
20 /* AES benchmarks */
21 static void xtest_tee_benchmark_2011(ADBG_Case_t *Case_p);
22 static void xtest_tee_benchmark_2012(ADBG_Case_t *Case_p);
23
24 /* ----------------------------------------------------------------------- */
25 /* -------------------------- SHA Benchmarks ----------------------------- */
26 /* ----------------------------------------------------------------------- */
27
xtest_tee_benchmark_2001(ADBG_Case_t * c)28 static void xtest_tee_benchmark_2001(ADBG_Case_t *c)
29 {
30 UNUSED(c);
31
32 int algo = TA_SHA_SHA1; /* Algorithm */
33 size_t size = 1024; /* Buffer size */
34 int offset = 0; /* Buffer offset wrt. alloc'ed address */
35
36 sha_perf_run_test(algo, size, CRYPTO_DEF_COUNT,
37 CRYPTO_DEF_LOOPS, CRYPTO_USE_RANDOM, offset,
38 CRYPTO_DEF_WARMUP, CRYPTO_DEF_VERBOSITY);
39
40 }
41
xtest_tee_benchmark_2002(ADBG_Case_t * c)42 static void xtest_tee_benchmark_2002(ADBG_Case_t *c)
43 {
44 UNUSED(c);
45
46 int algo = TA_SHA_SHA256; /* Algorithm */
47 size_t size = 4096; /* Buffer size */
48 int offset = 0; /* Buffer offset wrt. alloc'ed address */
49
50 sha_perf_run_test(algo, size, CRYPTO_DEF_COUNT,
51 CRYPTO_DEF_LOOPS, CRYPTO_USE_RANDOM, offset,
52 CRYPTO_DEF_WARMUP, CRYPTO_DEF_VERBOSITY);
53
54 }
55
56 ADBG_CASE_DEFINE(benchmark, 2001, xtest_tee_benchmark_2001,
57 "TEE SHA Performance test (TA_SHA_SHA1)");
58 ADBG_CASE_DEFINE(benchmark, 2002, xtest_tee_benchmark_2002,
59 "TEE SHA Performance test (TA_SHA_SHA226)");
60
61
62 /* ----------------------------------------------------------------------- */
63 /* -------------------------- AES Benchmarks ----------------------------- */
64 /* ----------------------------------------------------------------------- */
65
xtest_tee_benchmark_2011(ADBG_Case_t * c)66 static void xtest_tee_benchmark_2011(ADBG_Case_t *c)
67 {
68 UNUSED(c);
69
70 int mode = TA_AES_ECB; /* AES mode */
71 int decrypt = 0; /* Encrypt */
72 int keysize = AES_128;
73 size_t size = 1024; /* Buffer size */
74
75 aes_perf_run_test(mode, keysize, decrypt, size, CRYPTO_DEF_UNIT_SIZE,
76 CRYPTO_DEF_COUNT, CRYPTO_DEF_LOOPS, CRYPTO_USE_RANDOM,
77 AES_PERF_INPLACE, CRYPTO_DEF_WARMUP, CRYPTO_DEF_VERBOSITY);
78 }
79
xtest_tee_benchmark_2012(ADBG_Case_t * c)80 static void xtest_tee_benchmark_2012(ADBG_Case_t *c)
81 {
82 UNUSED(c);
83
84 int mode = TA_AES_CBC; /* AES mode */
85 int decrypt = 0; /* Encrypt */
86 int keysize = AES_256;
87 size_t size = 1024; /* Buffer size */
88
89 aes_perf_run_test(mode, keysize, decrypt, size, CRYPTO_DEF_UNIT_SIZE,
90 CRYPTO_DEF_COUNT, CRYPTO_DEF_LOOPS, CRYPTO_USE_RANDOM,
91 AES_PERF_INPLACE, CRYPTO_DEF_WARMUP, CRYPTO_DEF_VERBOSITY);
92 }
93
94 ADBG_CASE_DEFINE(benchmark, 2011, xtest_tee_benchmark_2011,
95 "TEE AES Performance test (TA_AES_ECB)");
96 ADBG_CASE_DEFINE(benchmark, 2012, xtest_tee_benchmark_2012,
97 "TEE AES Performance test (TA_AES_CBC)");
98