Igor Opaniuk | 136644a | 2016-09-13 13:40:56 +0300 | [diff] [blame] | 1 | /* |
| 2 | * Copyright (c) 2015, Linaro Limited |
| 3 | * |
| 4 | * This program is free software; you can redistribute it and/or modify |
| 5 | * it under the terms of the GNU General Public License Version 2 as |
| 6 | * published by the Free Software Foundation. |
| 7 | * |
| 8 | * This program is distributed in the hope that it will be useful, |
| 9 | * but WITHOUT ANY WARRANTY; without even the implied warranty of |
| 10 | * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the |
| 11 | * GNU General Public License for more details. |
| 12 | */ |
| 13 | |
| 14 | #include <stdio.h> |
| 15 | #include <stdlib.h> |
| 16 | #include <string.h> |
| 17 | |
| 18 | #include "xtest_test.h" |
| 19 | #include "xtest_helpers.h" |
| 20 | |
| 21 | #include <sha_perf.h> |
Igor Opaniuk | 44aff4b | 2016-09-16 10:18:00 +0300 | [diff] [blame^] | 22 | #include <aes_perf.h> |
Igor Opaniuk | 136644a | 2016-09-13 13:40:56 +0300 | [diff] [blame] | 23 | #include <util.h> |
| 24 | |
Igor Opaniuk | 44aff4b | 2016-09-16 10:18:00 +0300 | [diff] [blame^] | 25 | #define SHA_PERF_COUNT 5000 /* Number of measurements */ |
Igor Opaniuk | 136644a | 2016-09-13 13:40:56 +0300 | [diff] [blame] | 26 | #define SHA_PERF_WARMUP 2 /* Start with a 2-second busy loop */ |
| 27 | #define SHA_PERF_LOOPS 1 /* Inner loops */ |
| 28 | #define SHA_PERF_RANDOM_IN 1 /* Get input data from /dev/urandom */ |
| 29 | #define SHA_PERF_VERBOSITY 0 |
| 30 | |
Igor Opaniuk | 44aff4b | 2016-09-16 10:18:00 +0300 | [diff] [blame^] | 31 | #define AES_PERF_COUNT 5000 /* Number of measurements */ |
| 32 | #define AES_PERF_WARMUP 2 /* Start with a 2-second busy loop */ |
| 33 | #define AES_PERF_LOOPS 1 /* Inner loops */ |
| 34 | #define AES_PERF_RANDOM_IN 1 /* Get input data from /dev/urandom */ |
| 35 | #define AES_PERF_VERBOSITY 0 |
| 36 | #define AES_PERF_INPLACE 0 |
Igor Opaniuk | 136644a | 2016-09-13 13:40:56 +0300 | [diff] [blame] | 37 | |
Igor Opaniuk | 44aff4b | 2016-09-16 10:18:00 +0300 | [diff] [blame^] | 38 | /* SHA bechmarks */ |
Igor Opaniuk | 136644a | 2016-09-13 13:40:56 +0300 | [diff] [blame] | 39 | static void xtest_tee_benchmark_2001(ADBG_Case_t *Case_p); |
| 40 | static void xtest_tee_benchmark_2002(ADBG_Case_t *Case_p); |
| 41 | |
Igor Opaniuk | 44aff4b | 2016-09-16 10:18:00 +0300 | [diff] [blame^] | 42 | /* AES benchmarks */ |
| 43 | static void xtest_tee_benchmark_2011(ADBG_Case_t *Case_p); |
| 44 | static void xtest_tee_benchmark_2012(ADBG_Case_t *Case_p); |
| 45 | |
| 46 | /* ----------------------------------------------------------------------- */ |
| 47 | /* -------------------------- SHA Benchmarks ----------------------------- */ |
| 48 | /* ----------------------------------------------------------------------- */ |
| 49 | |
Igor Opaniuk | 136644a | 2016-09-13 13:40:56 +0300 | [diff] [blame] | 50 | static void xtest_tee_benchmark_2001(ADBG_Case_t *c) |
| 51 | { |
| 52 | UNUSED(c); |
| 53 | |
| 54 | int algo = TA_SHA_SHA1; /* Algorithm */ |
| 55 | size_t size = 1024; /* Buffer size */ |
| 56 | int offset = 0; /* Buffer offset wrt. alloc'ed address */ |
| 57 | |
Igor Opaniuk | 44aff4b | 2016-09-16 10:18:00 +0300 | [diff] [blame^] | 58 | sha_perf_run_test(algo, size, SHA_PERF_COUNT, |
| 59 | SHA_PERF_LOOPS, SHA_PERF_RANDOM_IN, offset, |
Igor Opaniuk | 136644a | 2016-09-13 13:40:56 +0300 | [diff] [blame] | 60 | SHA_PERF_WARMUP, SHA_PERF_VERBOSITY); |
| 61 | |
| 62 | } |
| 63 | |
| 64 | static void xtest_tee_benchmark_2002(ADBG_Case_t *c) |
| 65 | { |
| 66 | UNUSED(c); |
| 67 | |
| 68 | int algo = TA_SHA_SHA256; /* Algorithm */ |
| 69 | size_t size = 4096; /* Buffer size */ |
| 70 | int offset = 0; /* Buffer offset wrt. alloc'ed address */ |
| 71 | |
Igor Opaniuk | 44aff4b | 2016-09-16 10:18:00 +0300 | [diff] [blame^] | 72 | sha_perf_run_test(algo, size, SHA_PERF_COUNT, |
| 73 | SHA_PERF_LOOPS, SHA_PERF_RANDOM_IN, offset, |
Igor Opaniuk | 136644a | 2016-09-13 13:40:56 +0300 | [diff] [blame] | 74 | SHA_PERF_WARMUP, SHA_PERF_VERBOSITY); |
| 75 | |
| 76 | } |
| 77 | |
| 78 | ADBG_CASE_DEFINE(XTEST_TEE_BENCHMARK_2001, xtest_tee_benchmark_2001, |
| 79 | /* Title */ |
| 80 | "TEE SHA Performance test (TA_SHA_SHA1)", |
| 81 | /* Short description */ |
| 82 | "Hashing 1024 bytes buffer with SHA1 algo, offset = 0", |
| 83 | /* Requirement IDs */ "", |
| 84 | /* How to implement */ "" |
| 85 | ); |
| 86 | |
| 87 | ADBG_CASE_DEFINE(XTEST_TEE_BENCHMARK_2002, xtest_tee_benchmark_2002, |
| 88 | /* Title */ |
| 89 | "TEE SHA Performance test (TA_SHA_SHA226)", |
| 90 | /* Short description */ |
| 91 | "Hashing 4096 bytes buffer with SHA256 algo, offset = 0", |
| 92 | /* Requirement IDs */ "", |
| 93 | /* How to implement */ "" |
| 94 | ); |
| 95 | |
Igor Opaniuk | 44aff4b | 2016-09-16 10:18:00 +0300 | [diff] [blame^] | 96 | |
| 97 | /* ----------------------------------------------------------------------- */ |
| 98 | /* -------------------------- AES Benchmarks ----------------------------- */ |
| 99 | /* ----------------------------------------------------------------------- */ |
| 100 | |
| 101 | static void xtest_tee_benchmark_2011(ADBG_Case_t *c) |
| 102 | { |
| 103 | UNUSED(c); |
| 104 | |
| 105 | int mode = TA_AES_ECB; /* AES mode */ |
| 106 | int decrypt = 0; /* Encrypt */ |
| 107 | int keysize = AES_128; |
| 108 | size_t size = 1024; /* Buffer size */ |
| 109 | |
| 110 | |
| 111 | aes_perf_run_test(mode, keysize, decrypt, size, AES_PERF_COUNT, |
| 112 | AES_PERF_LOOPS, AES_PERF_RANDOM_IN, AES_PERF_INPLACE, |
| 113 | AES_PERF_WARMUP, AES_PERF_VERBOSITY); |
| 114 | |
| 115 | } |
| 116 | |
| 117 | static void xtest_tee_benchmark_2012(ADBG_Case_t *c) |
| 118 | { |
| 119 | UNUSED(c); |
| 120 | |
| 121 | int mode = TA_AES_ECB; /* AES mode */ |
| 122 | int decrypt = 0; /* Encrypt */ |
| 123 | int keysize = AES_128; |
| 124 | size_t size = 1024; /* Buffer size */ |
| 125 | |
| 126 | aes_perf_run_test(mode, keysize, decrypt, size, AES_PERF_COUNT, |
| 127 | AES_PERF_LOOPS, AES_PERF_RANDOM_IN, AES_PERF_INPLACE, |
| 128 | AES_PERF_WARMUP, AES_PERF_VERBOSITY); |
| 129 | |
| 130 | |
| 131 | |
| 132 | } |
| 133 | |
| 134 | ADBG_CASE_DEFINE(XTEST_TEE_BENCHMARK_2011, xtest_tee_benchmark_2011, |
| 135 | /* Title */ |
| 136 | "TEE AES Performance test (TA_AES_ECB)", |
| 137 | /* Short description */ |
| 138 | "Short description...", |
| 139 | /* Requirement IDs */ "", |
| 140 | /* How to implement */ "" |
| 141 | ); |
| 142 | |
| 143 | ADBG_CASE_DEFINE(XTEST_TEE_BENCHMARK_2012, xtest_tee_benchmark_2012, |
| 144 | /* Title */ |
| 145 | "TEE AES Performance test (TA_AES_CBC)", |
| 146 | /* Short description */ |
| 147 | "Short description...", |
| 148 | /* Requirement IDs */ "", |
| 149 | /* How to implement */ "" |
| 150 | ); |
| 151 | |