blob: 8f58ce4b5f2c3f0537c78c4d07f5fcea2302459d [file] [log] [blame]
Paul Bakker5121ce52009-01-03 21:22:43 +00001/*
2 * Benchmark demonstration program
3 *
Bence Szépkúti1e148272020-08-07 13:07:28 +02004 * Copyright The Mbed TLS Contributors
Manuel Pégourié-Gonnard37ff1402015-09-04 14:21:07 +02005 * SPDX-License-Identifier: Apache-2.0
6 *
7 * Licensed under the Apache License, Version 2.0 (the "License"); you may
8 * not use this file except in compliance with the License.
9 * You may obtain a copy of the License at
10 *
11 * http://www.apache.org/licenses/LICENSE-2.0
12 *
13 * Unless required by applicable law or agreed to in writing, software
14 * distributed under the License is distributed on an "AS IS" BASIS, WITHOUT
15 * WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
16 * See the License for the specific language governing permissions and
17 * limitations under the License.
Paul Bakker5121ce52009-01-03 21:22:43 +000018 */
19
Manuel Pégourié-Gonnard2cf5a7c2015-04-08 12:49:31 +020020#if !defined(MBEDTLS_CONFIG_FILE)
Manuel Pégourié-Gonnard7f809972015-03-09 17:05:11 +000021#include "mbedtls/config.h"
Manuel Pégourié-Gonnardcef4ad22014-04-29 12:39:06 +020022#else
Manuel Pégourié-Gonnard2cf5a7c2015-04-08 12:49:31 +020023#include MBEDTLS_CONFIG_FILE
Manuel Pégourié-Gonnardcef4ad22014-04-29 12:39:06 +020024#endif
Paul Bakker5121ce52009-01-03 21:22:43 +000025
Manuel Pégourié-Gonnard7f809972015-03-09 17:05:11 +000026#include "mbedtls/platform.h"
Rich Evansf90016a2015-01-19 14:26:37 +000027
Manuel Pégourié-Gonnard2cf5a7c2015-04-08 12:49:31 +020028#if !defined(MBEDTLS_TIMING_C)
Gilles Peskine1b6c09a2023-01-11 14:52:35 +010029int main(void)
Manuel Pégourié-Gonnard714929b2015-02-16 17:32:47 +000030{
Manuel Pégourié-Gonnard2cf5a7c2015-04-08 12:49:31 +020031 mbedtls_printf("MBEDTLS_TIMING_C not defined.\n");
Gilles Peskine1b6c09a2023-01-11 14:52:35 +010032 mbedtls_exit(0);
Manuel Pégourié-Gonnard714929b2015-02-16 17:32:47 +000033}
34#else
Manuel Pégourié-Gonnard50da0482014-12-19 12:10:37 +010035
Manuel Pégourié-Gonnard714929b2015-02-16 17:32:47 +000036#include <string.h>
Manuel Pégourié-Gonnard7551cb92015-05-26 16:04:06 +020037#include <stdlib.h>
Manuel Pégourié-Gonnard50da0482014-12-19 12:10:37 +010038
Manuel Pégourié-Gonnard7f809972015-03-09 17:05:11 +000039#include "mbedtls/timing.h"
Paul Bakker5121ce52009-01-03 21:22:43 +000040
Manuel Pégourié-Gonnard7f809972015-03-09 17:05:11 +000041#include "mbedtls/md4.h"
42#include "mbedtls/md5.h"
43#include "mbedtls/ripemd160.h"
44#include "mbedtls/sha1.h"
45#include "mbedtls/sha256.h"
46#include "mbedtls/sha512.h"
Manuel Pégourié-Gonnard62e813c2018-02-21 10:47:47 +010047
Manuel Pégourié-Gonnard7f809972015-03-09 17:05:11 +000048#include "mbedtls/arc4.h"
49#include "mbedtls/des.h"
50#include "mbedtls/aes.h"
Manuel Pégourié-Gonnard62e813c2018-02-21 10:47:47 +010051#include "mbedtls/aria.h"
Manuel Pégourié-Gonnard7f809972015-03-09 17:05:11 +000052#include "mbedtls/blowfish.h"
53#include "mbedtls/camellia.h"
Daniel King34b822c2016-05-15 17:28:08 -030054#include "mbedtls/chacha20.h"
Manuel Pégourié-Gonnard7f809972015-03-09 17:05:11 +000055#include "mbedtls/gcm.h"
56#include "mbedtls/ccm.h"
Manuel Pégourié-Gonnardd6aea182018-05-09 10:21:28 +020057#include "mbedtls/chachapoly.h"
Simon Butcher549dc3d2016-10-05 14:14:19 +010058#include "mbedtls/cmac.h"
Daniel Kingadc32c02016-05-16 18:25:45 -030059#include "mbedtls/poly1305.h"
Manuel Pégourié-Gonnard62e813c2018-02-21 10:47:47 +010060
Manuel Pégourié-Gonnard7f809972015-03-09 17:05:11 +000061#include "mbedtls/havege.h"
62#include "mbedtls/ctr_drbg.h"
63#include "mbedtls/hmac_drbg.h"
Manuel Pégourié-Gonnard62e813c2018-02-21 10:47:47 +010064
Manuel Pégourié-Gonnard7f809972015-03-09 17:05:11 +000065#include "mbedtls/rsa.h"
66#include "mbedtls/dhm.h"
67#include "mbedtls/ecdsa.h"
68#include "mbedtls/ecdh.h"
Manuel Pégourié-Gonnard62e813c2018-02-21 10:47:47 +010069
Manuel Pégourié-Gonnard7f809972015-03-09 17:05:11 +000070#include "mbedtls/error.h"
Paul Bakker5121ce52009-01-03 21:22:43 +000071
Manuel Pégourié-Gonnard2cf5a7c2015-04-08 12:49:31 +020072#if defined(MBEDTLS_MEMORY_BUFFER_ALLOC_C)
Manuel Pégourié-Gonnard7f809972015-03-09 17:05:11 +000073#include "mbedtls/memory_buffer_alloc.h"
Rich Evans18b78c72015-02-11 14:06:19 +000074#endif
75
Manuel Pégourié-Gonnard714929b2015-02-16 17:32:47 +000076/*
77 * For heap usage estimates, we need an estimate of the overhead per allocated
78 * block. ptmalloc2/3 (used in gnu libc for instance) uses 2 size_t per block,
79 * so use that as our baseline.
80 */
Gilles Peskine1b6c09a2023-01-11 14:52:35 +010081#define MEM_BLOCK_OVERHEAD (2 * sizeof(size_t))
Manuel Pégourié-Gonnard714929b2015-02-16 17:32:47 +000082
83/*
Manuel Pégourié-Gonnardb2a18a22015-05-27 16:29:56 +020084 * Size to use for the alloc buffer if MEMORY_BUFFER_ALLOC_C is defined.
Manuel Pégourié-Gonnard714929b2015-02-16 17:32:47 +000085 */
Christoph M. Wintersteiger0bc9c692018-10-25 12:47:18 +010086#define HEAP_SIZE (1u << 16) /* 64k */
Manuel Pégourié-Gonnard714929b2015-02-16 17:32:47 +000087
Paul Bakker02faf452011-11-29 11:23:58 +000088#define BUFSIZE 1024
Manuel Pégourié-Gonnardfef0f8f2014-01-30 20:59:00 +010089#define HEADER_FORMAT " %-24s : "
Gergely Budaia5d336b2014-01-27 23:27:06 +010090#define TITLE_LEN 25
Manuel Pégourié-Gonnard6c5abfa2015-02-13 14:12:07 +000091
Yanray Wangc96db3b2023-09-12 09:45:37 +080092#define OPTIONS \
93 "md4, md5, ripemd160, sha1, sha256, sha512,\n" \
94 "arc4, des3, des, camellia, blowfish, chacha20,\n" \
95 "aes_cbc, aes_cfb128, aes_cfb8, aes_gcm, aes_ccm, aes_xts, chachapoly,\n" \
96 "aes_cmac, des3_cmac, poly1305\n" \
97 "havege, ctr_drbg, hmac_drbg\n" \
Rich Evans85b05ec2015-02-12 11:37:29 +000098 "rsa, dhm, ecdsa, ecdh.\n"
99
Manuel Pégourié-Gonnard2cf5a7c2015-04-08 12:49:31 +0200100#if defined(MBEDTLS_ERROR_C)
Rich Evans85b05ec2015-02-12 11:37:29 +0000101#define PRINT_ERROR \
Gilles Peskine1b6c09a2023-01-11 14:52:35 +0100102 mbedtls_strerror(ret, (char *) tmp, sizeof(tmp)); \
103 mbedtls_printf("FAILED: %s\n", tmp);
Rich Evans85b05ec2015-02-12 11:37:29 +0000104#else
105#define PRINT_ERROR \
Gilles Peskine1b6c09a2023-01-11 14:52:35 +0100106 mbedtls_printf("FAILED: -0x%04x\n", (unsigned int) -ret);
Rich Evans85b05ec2015-02-12 11:37:29 +0000107#endif
108
Gilles Peskine1b6c09a2023-01-11 14:52:35 +0100109#define TIME_AND_TSC(TITLE, CODE) \
110 do { \
111 unsigned long ii, jj, tsc; \
112 int ret = 0; \
Rich Evans85b05ec2015-02-12 11:37:29 +0000113 \
Gilles Peskine1b6c09a2023-01-11 14:52:35 +0100114 mbedtls_printf(HEADER_FORMAT, TITLE); \
115 fflush(stdout); \
Rich Evans85b05ec2015-02-12 11:37:29 +0000116 \
Gilles Peskine1b6c09a2023-01-11 14:52:35 +0100117 mbedtls_set_alarm(1); \
118 for (ii = 1; ret == 0 && !mbedtls_timing_alarmed; ii++) \
119 { \
120 ret = CODE; \
121 } \
Rich Evans85b05ec2015-02-12 11:37:29 +0000122 \
Gilles Peskine1b6c09a2023-01-11 14:52:35 +0100123 tsc = mbedtls_timing_hardclock(); \
124 for (jj = 0; ret == 0 && jj < 1024; jj++) \
125 { \
126 ret = CODE; \
127 } \
Rich Evans85b05ec2015-02-12 11:37:29 +0000128 \
Gilles Peskine1b6c09a2023-01-11 14:52:35 +0100129 if (ret != 0) \
130 { \
131 PRINT_ERROR; \
132 } \
133 else \
134 { \
135 mbedtls_printf("%9lu KiB/s, %9lu cycles/byte\n", \
136 ii * BUFSIZE / 1024, \
137 (mbedtls_timing_hardclock() - tsc) \
138 / (jj * BUFSIZE)); \
139 } \
140 } while (0)
Rich Evans85b05ec2015-02-12 11:37:29 +0000141
Manuel Pégourié-Gonnard2cf5a7c2015-04-08 12:49:31 +0200142#if defined(MBEDTLS_MEMORY_BUFFER_ALLOC_C) && defined(MBEDTLS_MEMORY_DEBUG)
Manuel Pégourié-Gonnard50da0482014-12-19 12:10:37 +0100143
Manuel Pégourié-Gonnard5edd3882020-04-09 10:40:03 +0200144/* How much space to reserve for the title when printing heap usage results.
145 * Updated manually as the output of the following command:
146 *
147 * sed -n 's/.*[T]IME_PUBLIC.*"\(.*\)",/\1/p' programs/test/benchmark.c |
Manuel Pégourié-Gonnard64084952022-01-05 10:34:17 +0100148 * awk '{print length+3}' | sort -rn | head -n1
Manuel Pégourié-Gonnard5edd3882020-04-09 10:40:03 +0200149 *
Manuel Pégourié-Gonnard64084952022-01-05 10:34:17 +0100150 * This computes the maximum length of a title +3, because we appends "/s" and
151 * want at least one space. (If the value is too small, the only consequence
Shaun Case0e7791f2021-12-20 21:14:10 -0800152 * is poor alignment.) */
Manuel Pégourié-Gonnard64084952022-01-05 10:34:17 +0100153#define TITLE_SPACE 17
Manuel Pégourié-Gonnard5edd3882020-04-09 10:40:03 +0200154
Manuel Pégourié-Gonnard50da0482014-12-19 12:10:37 +0100155#define MEMORY_MEASURE_INIT \
156 size_t max_used, max_blocks, max_bytes; \
157 size_t prv_used, prv_blocks; \
Gilles Peskine1b6c09a2023-01-11 14:52:35 +0100158 mbedtls_memory_buffer_alloc_cur_get(&prv_used, &prv_blocks); \
159 mbedtls_memory_buffer_alloc_max_reset();
Manuel Pégourié-Gonnard50da0482014-12-19 12:10:37 +0100160
Gilles Peskine1b6c09a2023-01-11 14:52:35 +0100161#define MEMORY_MEASURE_PRINT(title_len) \
162 mbedtls_memory_buffer_alloc_max_get(&max_used, &max_blocks); \
Manuel Pégourié-Gonnard5edd3882020-04-09 10:40:03 +0200163 ii = TITLE_SPACE > (title_len) ? TITLE_SPACE - (title_len) : 1; \
Gilles Peskine1b6c09a2023-01-11 14:52:35 +0100164 while (ii--) mbedtls_printf(" "); \
Manuel Pégourié-Gonnard50da0482014-12-19 12:10:37 +0100165 max_used -= prv_used; \
166 max_blocks -= prv_blocks; \
167 max_bytes = max_used + MEM_BLOCK_OVERHEAD * max_blocks; \
Gilles Peskine1b6c09a2023-01-11 14:52:35 +0100168 mbedtls_printf("%6u heap bytes", (unsigned) max_bytes);
Manuel Pégourié-Gonnard50da0482014-12-19 12:10:37 +0100169
170#else
Manuel Pégourié-Gonnarde579dab2015-01-29 16:28:44 +0000171#define MEMORY_MEASURE_INIT
Gilles Peskine1b6c09a2023-01-11 14:52:35 +0100172#define MEMORY_MEASURE_PRINT(title_len)
Manuel Pégourié-Gonnard50da0482014-12-19 12:10:37 +0100173#endif
174
Gilles Peskine1b6c09a2023-01-11 14:52:35 +0100175#define TIME_PUBLIC(TITLE, TYPE, CODE) \
176 do { \
177 unsigned long ii; \
178 int ret; \
179 MEMORY_MEASURE_INIT; \
Rich Evans85b05ec2015-02-12 11:37:29 +0000180 \
Gilles Peskine1b6c09a2023-01-11 14:52:35 +0100181 mbedtls_printf(HEADER_FORMAT, TITLE); \
182 fflush(stdout); \
183 mbedtls_set_alarm(3); \
Rich Evans85b05ec2015-02-12 11:37:29 +0000184 \
Gilles Peskine1b6c09a2023-01-11 14:52:35 +0100185 ret = 0; \
186 for (ii = 1; !mbedtls_timing_alarmed && !ret; ii++) \
187 { \
188 CODE; \
189 } \
Rich Evans85b05ec2015-02-12 11:37:29 +0000190 \
Gilles Peskine1b6c09a2023-01-11 14:52:35 +0100191 if (ret == MBEDTLS_ERR_PLATFORM_FEATURE_UNSUPPORTED) \
192 { \
193 mbedtls_printf("Feature Not Supported. Skipping.\n"); \
194 ret = 0; \
195 } \
196 else if (ret != 0) \
197 { \
198 PRINT_ERROR; \
199 } \
200 else \
201 { \
202 mbedtls_printf("%6lu " TYPE "/s", ii / 3); \
203 MEMORY_MEASURE_PRINT(sizeof(TYPE) + 1); \
204 mbedtls_printf("\n"); \
205 } \
206 } while (0)
Paul Bakker5121ce52009-01-03 21:22:43 +0000207
Gilles Peskine1b6c09a2023-01-11 14:52:35 +0100208static int myrand(void *rng_state, unsigned char *output, size_t len)
Paul Bakker5121ce52009-01-03 21:22:43 +0000209{
Paul Bakkera3d195c2011-11-27 21:07:34 +0000210 size_t use_len;
211 int rnd;
212
Gilles Peskine1b6c09a2023-01-11 14:52:35 +0100213 if (rng_state != NULL) {
Paul Bakker5121ce52009-01-03 21:22:43 +0000214 rng_state = NULL;
Gilles Peskine1b6c09a2023-01-11 14:52:35 +0100215 }
Paul Bakker5121ce52009-01-03 21:22:43 +0000216
Gilles Peskine1b6c09a2023-01-11 14:52:35 +0100217 while (len > 0) {
Paul Bakkera3d195c2011-11-27 21:07:34 +0000218 use_len = len;
Gilles Peskine1b6c09a2023-01-11 14:52:35 +0100219 if (use_len > sizeof(int)) {
Paul Bakkera3d195c2011-11-27 21:07:34 +0000220 use_len = sizeof(int);
Gilles Peskine1b6c09a2023-01-11 14:52:35 +0100221 }
Paul Bakkera3d195c2011-11-27 21:07:34 +0000222
223 rnd = rand();
Gilles Peskine1b6c09a2023-01-11 14:52:35 +0100224 memcpy(output, &rnd, use_len);
Paul Bakkera3d195c2011-11-27 21:07:34 +0000225 output += use_len;
226 len -= use_len;
227 }
228
Gilles Peskine1b6c09a2023-01-11 14:52:35 +0100229 return 0;
Paul Bakker5121ce52009-01-03 21:22:43 +0000230}
231
Gilles Peskine1b6c09a2023-01-11 14:52:35 +0100232#define CHECK_AND_CONTINUE(R) \
Christoph M. Wintersteiger21411d22019-02-06 18:06:15 +0000233 { \
Gilles Peskine1b6c09a2023-01-11 14:52:35 +0100234 int CHECK_AND_CONTINUE_ret = (R); \
235 if (CHECK_AND_CONTINUE_ret == MBEDTLS_ERR_PLATFORM_FEATURE_UNSUPPORTED) { \
236 mbedtls_printf("Feature not supported. Skipping.\n"); \
Christoph M. Wintersteiger21411d22019-02-06 18:06:15 +0000237 continue; \
238 } \
Gilles Peskine1b6c09a2023-01-11 14:52:35 +0100239 else if (CHECK_AND_CONTINUE_ret != 0) { \
240 mbedtls_exit(1); \
Christoph M. Wintersteiger21411d22019-02-06 18:06:15 +0000241 } \
242 }
Christoph M. Wintersteiger3dca1a42018-12-14 11:54:59 +0000243
Manuel Pégourié-Gonnard50da0482014-12-19 12:10:37 +0100244/*
245 * Clear some memory that was used to prepare the context
246 */
Manuel Pégourié-Gonnard2cf5a7c2015-04-08 12:49:31 +0200247#if defined(MBEDTLS_ECP_C)
Gilles Peskine1b6c09a2023-01-11 14:52:35 +0100248void ecp_clear_precomputed(mbedtls_ecp_group *grp)
Manuel Pégourié-Gonnard50da0482014-12-19 12:10:37 +0100249{
Gilles Peskine1b6c09a2023-01-11 14:52:35 +0100250 if (grp->T != NULL) {
Manuel Pégourié-Gonnard50da0482014-12-19 12:10:37 +0100251 size_t i;
Gilles Peskine1b6c09a2023-01-11 14:52:35 +0100252 for (i = 0; i < grp->T_size; i++) {
253 mbedtls_ecp_point_free(&grp->T[i]);
254 }
255 mbedtls_free(grp->T);
Manuel Pégourié-Gonnard50da0482014-12-19 12:10:37 +0100256 }
257 grp->T = NULL;
258 grp->T_size = 0;
259}
260#else
Gilles Peskine1b6c09a2023-01-11 14:52:35 +0100261#define ecp_clear_precomputed(g)
Manuel Pégourié-Gonnard50da0482014-12-19 12:10:37 +0100262#endif
263
Gilles Peskine28f62f62020-07-24 02:06:46 +0200264#if defined(MBEDTLS_ECP_C)
Gilles Peskine1b6c09a2023-01-11 14:52:35 +0100265static int set_ecp_curve(const char *string, mbedtls_ecp_curve_info *curve)
Gilles Peskine28f62f62020-07-24 02:06:46 +0200266{
267 const mbedtls_ecp_curve_info *found =
Gilles Peskine1b6c09a2023-01-11 14:52:35 +0100268 mbedtls_ecp_curve_info_from_name(string);
269 if (found != NULL) {
Gilles Peskine28f62f62020-07-24 02:06:46 +0200270 *curve = *found;
Gilles Peskine1b6c09a2023-01-11 14:52:35 +0100271 return 1;
272 } else {
273 return 0;
Gilles Peskine28f62f62020-07-24 02:06:46 +0200274 }
Gilles Peskine28f62f62020-07-24 02:06:46 +0200275}
276#endif
277
Paul Bakker5121ce52009-01-03 21:22:43 +0000278unsigned char buf[BUFSIZE];
279
Manuel Pégourié-Gonnarded7cbe92013-09-17 15:30:51 +0200280typedef struct {
Manuel Pégourié-Gonnarde85fef12015-05-11 19:21:39 +0200281 char md4, md5, ripemd160, sha1, sha256, sha512,
Simon Butcher549dc3d2016-10-05 14:14:19 +0100282 arc4, des3, des,
Yanray Wangc96db3b2023-09-12 09:45:37 +0800283 aes_cbc, aes_cfb128, aes_cfb8, aes_gcm, aes_ccm, aes_xts, chachapoly,
Manuel Pégourié-Gonnardd6aea182018-05-09 10:21:28 +0200284 aes_cmac, des3_cmac,
Manuel Pégourié-Gonnard39b19042018-06-07 12:01:33 +0200285 aria, camellia, blowfish, chacha20,
Daniel Kingadc32c02016-05-16 18:25:45 -0300286 poly1305,
Manuel Pégourié-Gonnardfef0f8f2014-01-30 20:59:00 +0100287 havege, ctr_drbg, hmac_drbg,
Manuel Pégourié-Gonnardcc34f952013-09-17 16:04:08 +0200288 rsa, dhm, ecdsa, ecdh;
Manuel Pégourié-Gonnarded7cbe92013-09-17 15:30:51 +0200289} todo_list;
290
Simon Butcher63cb97e2018-12-06 17:43:31 +0000291
Gilles Peskine1b6c09a2023-01-11 14:52:35 +0100292int main(int argc, char *argv[])
Paul Bakker5690efc2011-05-26 13:16:06 +0000293{
Manuel Pégourié-Gonnard71e75dc2014-12-19 18:05:43 +0100294 int i;
Manuel Pégourié-Gonnardcc34f952013-09-17 16:04:08 +0200295 unsigned char tmp[200];
Manuel Pégourié-Gonnard8271f2f2013-09-17 14:57:55 +0200296 char title[TITLE_LEN];
Manuel Pégourié-Gonnarded7cbe92013-09-17 15:30:51 +0200297 todo_list todo;
Manuel Pégourié-Gonnard2cf5a7c2015-04-08 12:49:31 +0200298#if defined(MBEDTLS_MEMORY_BUFFER_ALLOC_C)
Manuel Pégourié-Gonnardb2a18a22015-05-27 16:29:56 +0200299 unsigned char alloc_buf[HEAP_SIZE] = { 0 };
Manuel Pégourié-Gonnard128657d2014-12-18 16:35:52 +0000300#endif
Gilles Peskine28f62f62020-07-24 02:06:46 +0200301#if defined(MBEDTLS_ECP_C)
302 mbedtls_ecp_curve_info single_curve[2] = {
303 { MBEDTLS_ECP_DP_NONE, 0, 0, NULL },
304 { MBEDTLS_ECP_DP_NONE, 0, 0, NULL },
305 };
Gilles Peskine1b6c09a2023-01-11 14:52:35 +0100306 const mbedtls_ecp_curve_info *curve_list = mbedtls_ecp_curve_list();
Gilles Peskine28f62f62020-07-24 02:06:46 +0200307#endif
308
309#if defined(MBEDTLS_ECP_C)
310 (void) curve_list; /* Unused in some configurations where no benchmark uses ECC */
311#endif
Paul Bakkercce9d772011-11-18 14:26:47 +0000312
Gilles Peskine1b6c09a2023-01-11 14:52:35 +0100313 if (argc <= 1) {
314 memset(&todo, 1, sizeof(todo));
315 } else {
316 memset(&todo, 0, sizeof(todo));
Manuel Pégourié-Gonnarded7cbe92013-09-17 15:30:51 +0200317
Gilles Peskine1b6c09a2023-01-11 14:52:35 +0100318 for (i = 1; i < argc; i++) {
319 if (strcmp(argv[i], "md4") == 0) {
Manuel Pégourié-Gonnarde85fef12015-05-11 19:21:39 +0200320 todo.md4 = 1;
Gilles Peskine1b6c09a2023-01-11 14:52:35 +0100321 } else if (strcmp(argv[i], "md5") == 0) {
Manuel Pégourié-Gonnarde85fef12015-05-11 19:21:39 +0200322 todo.md5 = 1;
Gilles Peskine1b6c09a2023-01-11 14:52:35 +0100323 } else if (strcmp(argv[i], "ripemd160") == 0) {
Manuel Pégourié-Gonnarde85fef12015-05-11 19:21:39 +0200324 todo.ripemd160 = 1;
Gilles Peskine1b6c09a2023-01-11 14:52:35 +0100325 } else if (strcmp(argv[i], "sha1") == 0) {
Manuel Pégourié-Gonnarde85fef12015-05-11 19:21:39 +0200326 todo.sha1 = 1;
Gilles Peskine1b6c09a2023-01-11 14:52:35 +0100327 } else if (strcmp(argv[i], "sha256") == 0) {
Manuel Pégourié-Gonnarde85fef12015-05-11 19:21:39 +0200328 todo.sha256 = 1;
Gilles Peskine1b6c09a2023-01-11 14:52:35 +0100329 } else if (strcmp(argv[i], "sha512") == 0) {
Manuel Pégourié-Gonnarde85fef12015-05-11 19:21:39 +0200330 todo.sha512 = 1;
Gilles Peskine1b6c09a2023-01-11 14:52:35 +0100331 } else if (strcmp(argv[i], "arc4") == 0) {
Manuel Pégourié-Gonnarded7cbe92013-09-17 15:30:51 +0200332 todo.arc4 = 1;
Gilles Peskine1b6c09a2023-01-11 14:52:35 +0100333 } else if (strcmp(argv[i], "des3") == 0) {
Manuel Pégourié-Gonnarded7cbe92013-09-17 15:30:51 +0200334 todo.des3 = 1;
Gilles Peskine1b6c09a2023-01-11 14:52:35 +0100335 } else if (strcmp(argv[i], "des") == 0) {
Manuel Pégourié-Gonnarded7cbe92013-09-17 15:30:51 +0200336 todo.des = 1;
Gilles Peskine1b6c09a2023-01-11 14:52:35 +0100337 } else if (strcmp(argv[i], "aes_cbc") == 0) {
Manuel Pégourié-Gonnarded7cbe92013-09-17 15:30:51 +0200338 todo.aes_cbc = 1;
Yanray Wangb382c2b2023-09-12 09:03:50 +0800339 } else if (strcmp(argv[i], "aes_cfb128") == 0) {
340 todo.aes_cfb128 = 1;
Yanray Wangc96db3b2023-09-12 09:45:37 +0800341 } else if (strcmp(argv[i], "aes_cfb8") == 0) {
342 todo.aes_cfb8 = 1;
Gilles Peskine1b6c09a2023-01-11 14:52:35 +0100343 } else if (strcmp(argv[i], "aes_xts") == 0) {
Aorimn5f778012016-06-09 23:22:58 +0200344 todo.aes_xts = 1;
Gilles Peskine1b6c09a2023-01-11 14:52:35 +0100345 } else if (strcmp(argv[i], "aes_gcm") == 0) {
Manuel Pégourié-Gonnarded7cbe92013-09-17 15:30:51 +0200346 todo.aes_gcm = 1;
Gilles Peskine1b6c09a2023-01-11 14:52:35 +0100347 } else if (strcmp(argv[i], "aes_ccm") == 0) {
Manuel Pégourié-Gonnard58d78a82014-05-07 12:03:02 +0200348 todo.aes_ccm = 1;
Gilles Peskine1b6c09a2023-01-11 14:52:35 +0100349 } else if (strcmp(argv[i], "chachapoly") == 0) {
Manuel Pégourié-Gonnardd6aea182018-05-09 10:21:28 +0200350 todo.chachapoly = 1;
Gilles Peskine1b6c09a2023-01-11 14:52:35 +0100351 } else if (strcmp(argv[i], "aes_cmac") == 0) {
Simon Butcher549dc3d2016-10-05 14:14:19 +0100352 todo.aes_cmac = 1;
Gilles Peskine1b6c09a2023-01-11 14:52:35 +0100353 } else if (strcmp(argv[i], "des3_cmac") == 0) {
Simon Butcher549dc3d2016-10-05 14:14:19 +0100354 todo.des3_cmac = 1;
Gilles Peskine1b6c09a2023-01-11 14:52:35 +0100355 } else if (strcmp(argv[i], "aria") == 0) {
Manuel Pégourié-Gonnard62e813c2018-02-21 10:47:47 +0100356 todo.aria = 1;
Gilles Peskine1b6c09a2023-01-11 14:52:35 +0100357 } else if (strcmp(argv[i], "camellia") == 0) {
Manuel Pégourié-Gonnarded7cbe92013-09-17 15:30:51 +0200358 todo.camellia = 1;
Gilles Peskine1b6c09a2023-01-11 14:52:35 +0100359 } else if (strcmp(argv[i], "blowfish") == 0) {
Manuel Pégourié-Gonnarded7cbe92013-09-17 15:30:51 +0200360 todo.blowfish = 1;
Gilles Peskine1b6c09a2023-01-11 14:52:35 +0100361 } else if (strcmp(argv[i], "chacha20") == 0) {
Daniel King34b822c2016-05-15 17:28:08 -0300362 todo.chacha20 = 1;
Gilles Peskine1b6c09a2023-01-11 14:52:35 +0100363 } else if (strcmp(argv[i], "poly1305") == 0) {
Daniel Kingadc32c02016-05-16 18:25:45 -0300364 todo.poly1305 = 1;
Gilles Peskine1b6c09a2023-01-11 14:52:35 +0100365 } else if (strcmp(argv[i], "havege") == 0) {
Manuel Pégourié-Gonnarded7cbe92013-09-17 15:30:51 +0200366 todo.havege = 1;
Gilles Peskine1b6c09a2023-01-11 14:52:35 +0100367 } else if (strcmp(argv[i], "ctr_drbg") == 0) {
Manuel Pégourié-Gonnarded7cbe92013-09-17 15:30:51 +0200368 todo.ctr_drbg = 1;
Gilles Peskine1b6c09a2023-01-11 14:52:35 +0100369 } else if (strcmp(argv[i], "hmac_drbg") == 0) {
Manuel Pégourié-Gonnardfef0f8f2014-01-30 20:59:00 +0100370 todo.hmac_drbg = 1;
Gilles Peskine1b6c09a2023-01-11 14:52:35 +0100371 } else if (strcmp(argv[i], "rsa") == 0) {
Manuel Pégourié-Gonnarded7cbe92013-09-17 15:30:51 +0200372 todo.rsa = 1;
Gilles Peskine1b6c09a2023-01-11 14:52:35 +0100373 } else if (strcmp(argv[i], "dhm") == 0) {
Manuel Pégourié-Gonnarded7cbe92013-09-17 15:30:51 +0200374 todo.dhm = 1;
Gilles Peskine1b6c09a2023-01-11 14:52:35 +0100375 } else if (strcmp(argv[i], "ecdsa") == 0) {
Manuel Pégourié-Gonnardcc34f952013-09-17 16:04:08 +0200376 todo.ecdsa = 1;
Gilles Peskine1b6c09a2023-01-11 14:52:35 +0100377 } else if (strcmp(argv[i], "ecdh") == 0) {
Manuel Pégourié-Gonnardcc34f952013-09-17 16:04:08 +0200378 todo.ecdh = 1;
Gilles Peskine1b6c09a2023-01-11 14:52:35 +0100379 }
Gilles Peskine28f62f62020-07-24 02:06:46 +0200380#if defined(MBEDTLS_ECP_C)
Gilles Peskine1b6c09a2023-01-11 14:52:35 +0100381 else if (set_ecp_curve(argv[i], single_curve)) {
Gilles Peskine28f62f62020-07-24 02:06:46 +0200382 curve_list = single_curve;
Gilles Peskine1b6c09a2023-01-11 14:52:35 +0100383 }
Gilles Peskine28f62f62020-07-24 02:06:46 +0200384#endif
Gilles Peskine1b6c09a2023-01-11 14:52:35 +0100385 else {
386 mbedtls_printf("Unrecognized option: %s\n", argv[i]);
387 mbedtls_printf("Available options: " OPTIONS);
Manuel Pégourié-Gonnarded7cbe92013-09-17 15:30:51 +0200388 }
389 }
390 }
Paul Bakker5121ce52009-01-03 21:22:43 +0000391
Gilles Peskine1b6c09a2023-01-11 14:52:35 +0100392 mbedtls_printf("\n");
Paul Bakker5121ce52009-01-03 21:22:43 +0000393
Manuel Pégourié-Gonnard2cf5a7c2015-04-08 12:49:31 +0200394#if defined(MBEDTLS_MEMORY_BUFFER_ALLOC_C)
Gilles Peskine1b6c09a2023-01-11 14:52:35 +0100395 mbedtls_memory_buffer_alloc_init(alloc_buf, sizeof(alloc_buf));
Manuel Pégourié-Gonnard128657d2014-12-18 16:35:52 +0000396#endif
Gilles Peskine1b6c09a2023-01-11 14:52:35 +0100397 memset(buf, 0xAA, sizeof(buf));
398 memset(tmp, 0xBB, sizeof(tmp));
Manuel Pégourié-Gonnarded7cbe92013-09-17 15:30:51 +0200399
Manuel Pégourié-Gonnard2cf5a7c2015-04-08 12:49:31 +0200400#if defined(MBEDTLS_MD4_C)
Gilles Peskine1b6c09a2023-01-11 14:52:35 +0100401 if (todo.md4) {
402 TIME_AND_TSC("MD4", mbedtls_md4_ret(buf, BUFSIZE, tmp));
403 }
Paul Bakker5121ce52009-01-03 21:22:43 +0000404#endif
405
Manuel Pégourié-Gonnard2cf5a7c2015-04-08 12:49:31 +0200406#if defined(MBEDTLS_MD5_C)
Gilles Peskine1b6c09a2023-01-11 14:52:35 +0100407 if (todo.md5) {
408 TIME_AND_TSC("MD5", mbedtls_md5_ret(buf, BUFSIZE, tmp));
409 }
Paul Bakker5121ce52009-01-03 21:22:43 +0000410#endif
411
Manuel Pégourié-Gonnard2cf5a7c2015-04-08 12:49:31 +0200412#if defined(MBEDTLS_RIPEMD160_C)
Gilles Peskine1b6c09a2023-01-11 14:52:35 +0100413 if (todo.ripemd160) {
414 TIME_AND_TSC("RIPEMD160", mbedtls_ripemd160_ret(buf, BUFSIZE, tmp));
415 }
Manuel Pégourié-Gonnard01b0b382014-01-17 14:29:46 +0100416#endif
417
Manuel Pégourié-Gonnard2cf5a7c2015-04-08 12:49:31 +0200418#if defined(MBEDTLS_SHA1_C)
Gilles Peskine1b6c09a2023-01-11 14:52:35 +0100419 if (todo.sha1) {
420 TIME_AND_TSC("SHA-1", mbedtls_sha1_ret(buf, BUFSIZE, tmp));
421 }
Paul Bakker5121ce52009-01-03 21:22:43 +0000422#endif
423
Manuel Pégourié-Gonnard2cf5a7c2015-04-08 12:49:31 +0200424#if defined(MBEDTLS_SHA256_C)
Gilles Peskine1b6c09a2023-01-11 14:52:35 +0100425 if (todo.sha256) {
426 TIME_AND_TSC("SHA-256", mbedtls_sha256_ret(buf, BUFSIZE, tmp, 0));
427 }
Paul Bakker5121ce52009-01-03 21:22:43 +0000428#endif
429
Manuel Pégourié-Gonnard2cf5a7c2015-04-08 12:49:31 +0200430#if defined(MBEDTLS_SHA512_C)
Gilles Peskine1b6c09a2023-01-11 14:52:35 +0100431 if (todo.sha512) {
432 TIME_AND_TSC("SHA-512", mbedtls_sha512_ret(buf, BUFSIZE, tmp, 0));
433 }
Paul Bakker3a3c3c22009-02-09 22:33:30 +0000434#endif
435
Manuel Pégourié-Gonnard2cf5a7c2015-04-08 12:49:31 +0200436#if defined(MBEDTLS_ARC4_C)
Gilles Peskine1b6c09a2023-01-11 14:52:35 +0100437 if (todo.arc4) {
Manuel Pégourié-Gonnard2cf5a7c2015-04-08 12:49:31 +0200438 mbedtls_arc4_context arc4;
Gilles Peskine1b6c09a2023-01-11 14:52:35 +0100439 mbedtls_arc4_init(&arc4);
440 mbedtls_arc4_setup(&arc4, tmp, 32);
441 TIME_AND_TSC("ARC4", mbedtls_arc4_crypt(&arc4, BUFSIZE, buf, buf));
442 mbedtls_arc4_free(&arc4);
Manuel Pégourié-Gonnard8271f2f2013-09-17 14:57:55 +0200443 }
Paul Bakker5121ce52009-01-03 21:22:43 +0000444#endif
445
Simon Butcher549dc3d2016-10-05 14:14:19 +0100446#if defined(MBEDTLS_DES_C)
447#if defined(MBEDTLS_CIPHER_MODE_CBC)
Gilles Peskine1b6c09a2023-01-11 14:52:35 +0100448 if (todo.des3) {
Manuel Pégourié-Gonnard2cf5a7c2015-04-08 12:49:31 +0200449 mbedtls_des3_context des3;
Gilles Peskine1b6c09a2023-01-11 14:52:35 +0100450 mbedtls_des3_init(&des3);
451 if (mbedtls_des3_set3key_enc(&des3, tmp) != 0) {
452 mbedtls_exit(1);
453 }
454 TIME_AND_TSC("3DES",
455 mbedtls_des3_crypt_cbc(&des3, MBEDTLS_DES_ENCRYPT, BUFSIZE, tmp, buf, buf));
456 mbedtls_des3_free(&des3);
Manuel Pégourié-Gonnard8271f2f2013-09-17 14:57:55 +0200457 }
Paul Bakker5121ce52009-01-03 21:22:43 +0000458
Gilles Peskine1b6c09a2023-01-11 14:52:35 +0100459 if (todo.des) {
Manuel Pégourié-Gonnard2cf5a7c2015-04-08 12:49:31 +0200460 mbedtls_des_context des;
Gilles Peskine1b6c09a2023-01-11 14:52:35 +0100461 mbedtls_des_init(&des);
462 if (mbedtls_des_setkey_enc(&des, tmp) != 0) {
463 mbedtls_exit(1);
464 }
465 TIME_AND_TSC("DES",
466 mbedtls_des_crypt_cbc(&des, MBEDTLS_DES_ENCRYPT, BUFSIZE, tmp, buf, buf));
467 mbedtls_des_free(&des);
Manuel Pégourié-Gonnard8271f2f2013-09-17 14:57:55 +0200468 }
Simon Butcher549dc3d2016-10-05 14:14:19 +0100469
470#endif /* MBEDTLS_CIPHER_MODE_CBC */
471#if defined(MBEDTLS_CMAC_C)
Gilles Peskine1b6c09a2023-01-11 14:52:35 +0100472 if (todo.des3_cmac) {
Simon Butcher549dc3d2016-10-05 14:14:19 +0100473 unsigned char output[8];
474 const mbedtls_cipher_info_t *cipher_info;
475
Gilles Peskine1b6c09a2023-01-11 14:52:35 +0100476 memset(buf, 0, sizeof(buf));
477 memset(tmp, 0, sizeof(tmp));
Simon Butcher549dc3d2016-10-05 14:14:19 +0100478
Gilles Peskine1b6c09a2023-01-11 14:52:35 +0100479 cipher_info = mbedtls_cipher_info_from_type(MBEDTLS_CIPHER_DES_EDE3_ECB);
Simon Butcher549dc3d2016-10-05 14:14:19 +0100480
Gilles Peskine1b6c09a2023-01-11 14:52:35 +0100481 TIME_AND_TSC("3DES-CMAC",
482 mbedtls_cipher_cmac(cipher_info, tmp, 192, buf,
483 BUFSIZE, output));
Simon Butcher549dc3d2016-10-05 14:14:19 +0100484 }
485#endif /* MBEDTLS_CMAC_C */
486#endif /* MBEDTLS_DES_C */
Paul Bakker5121ce52009-01-03 21:22:43 +0000487
Manuel Pégourié-Gonnard2cf5a7c2015-04-08 12:49:31 +0200488#if defined(MBEDTLS_AES_C)
489#if defined(MBEDTLS_CIPHER_MODE_CBC)
Gilles Peskine1b6c09a2023-01-11 14:52:35 +0100490 if (todo.aes_cbc) {
Manuel Pégourié-Gonnard71e75dc2014-12-19 18:05:43 +0100491 int keysize;
Manuel Pégourié-Gonnard2cf5a7c2015-04-08 12:49:31 +0200492 mbedtls_aes_context aes;
Gilles Peskine1b6c09a2023-01-11 14:52:35 +0100493 mbedtls_aes_init(&aes);
494 for (keysize = 128; keysize <= 256; keysize += 64) {
495 mbedtls_snprintf(title, sizeof(title), "AES-CBC-%d", keysize);
Paul Bakker5121ce52009-01-03 21:22:43 +0000496
Gilles Peskine1b6c09a2023-01-11 14:52:35 +0100497 memset(buf, 0, sizeof(buf));
498 memset(tmp, 0, sizeof(tmp));
499 CHECK_AND_CONTINUE(mbedtls_aes_setkey_enc(&aes, tmp, keysize));
Paul Bakker5121ce52009-01-03 21:22:43 +0000500
Gilles Peskine1b6c09a2023-01-11 14:52:35 +0100501 TIME_AND_TSC(title,
502 mbedtls_aes_crypt_cbc(&aes, MBEDTLS_AES_ENCRYPT, BUFSIZE, tmp, buf, buf));
Manuel Pégourié-Gonnard8271f2f2013-09-17 14:57:55 +0200503 }
Gilles Peskine1b6c09a2023-01-11 14:52:35 +0100504 mbedtls_aes_free(&aes);
Paul Bakker5121ce52009-01-03 21:22:43 +0000505 }
Manuel Pégourié-Gonnard8271f2f2013-09-17 14:57:55 +0200506#endif
Yanray Wangb382c2b2023-09-12 09:03:50 +0800507#if defined(MBEDTLS_CIPHER_MODE_CFB)
508 if (todo.aes_cfb128) {
509 int keysize;
510 size_t iv_off = 0;
511 mbedtls_aes_context aes;
512 mbedtls_aes_init(&aes);
513 for (keysize = 128; keysize <= 256; keysize += 64) {
514 mbedtls_snprintf(title, sizeof(title), "AES-CFB128-%d", keysize);
515
516 memset(buf, 0, sizeof(buf));
517 memset(tmp, 0, sizeof(tmp));
518 CHECK_AND_CONTINUE(mbedtls_aes_setkey_enc(&aes, tmp, keysize));
519
520 TIME_AND_TSC(title,
521 mbedtls_aes_crypt_cfb128(&aes, MBEDTLS_AES_ENCRYPT, BUFSIZE,
522 &iv_off, tmp, buf, buf));
523 }
524 mbedtls_aes_free(&aes);
525 }
Yanray Wangc96db3b2023-09-12 09:45:37 +0800526 if (todo.aes_cfb8) {
527 int keysize;
528 mbedtls_aes_context aes;
529 mbedtls_aes_init(&aes);
530 for (keysize = 128; keysize <= 256; keysize += 64) {
531 mbedtls_snprintf(title, sizeof(title), "AES-CFB8-%d", keysize);
532
533 memset(buf, 0, sizeof(buf));
534 memset(tmp, 0, sizeof(tmp));
535 CHECK_AND_CONTINUE(mbedtls_aes_setkey_enc(&aes, tmp, keysize));
536
537 TIME_AND_TSC(title,
538 mbedtls_aes_crypt_cfb8(&aes, MBEDTLS_AES_ENCRYPT, BUFSIZE, tmp, buf, buf));
539 }
540 mbedtls_aes_free(&aes);
541 }
Yanray Wangb382c2b2023-09-12 09:03:50 +0800542#endif
Aorimn5f778012016-06-09 23:22:58 +0200543#if defined(MBEDTLS_CIPHER_MODE_XTS)
Gilles Peskine1b6c09a2023-01-11 14:52:35 +0100544 if (todo.aes_xts) {
Aorimn5f778012016-06-09 23:22:58 +0200545 int keysize;
Jaeden Amero9366feb2018-05-29 18:55:17 +0100546 mbedtls_aes_xts_context ctx;
547
Gilles Peskine1b6c09a2023-01-11 14:52:35 +0100548 mbedtls_aes_xts_init(&ctx);
549 for (keysize = 128; keysize <= 256; keysize += 128) {
550 mbedtls_snprintf(title, sizeof(title), "AES-XTS-%d", keysize);
Aorimn5f778012016-06-09 23:22:58 +0200551
Gilles Peskine1b6c09a2023-01-11 14:52:35 +0100552 memset(buf, 0, sizeof(buf));
553 memset(tmp, 0, sizeof(tmp));
554 CHECK_AND_CONTINUE(mbedtls_aes_xts_setkey_enc(&ctx, tmp, keysize * 2));
Aorimn5f778012016-06-09 23:22:58 +0200555
Gilles Peskine1b6c09a2023-01-11 14:52:35 +0100556 TIME_AND_TSC(title,
557 mbedtls_aes_crypt_xts(&ctx, MBEDTLS_AES_ENCRYPT, BUFSIZE,
558 tmp, buf, buf));
Jaeden Amero9366feb2018-05-29 18:55:17 +0100559
Gilles Peskine1b6c09a2023-01-11 14:52:35 +0100560 mbedtls_aes_xts_free(&ctx);
Aorimn5f778012016-06-09 23:22:58 +0200561 }
Aorimn5f778012016-06-09 23:22:58 +0200562 }
563#endif
Manuel Pégourié-Gonnard2cf5a7c2015-04-08 12:49:31 +0200564#if defined(MBEDTLS_GCM_C)
Gilles Peskine1b6c09a2023-01-11 14:52:35 +0100565 if (todo.aes_gcm) {
Manuel Pégourié-Gonnard71e75dc2014-12-19 18:05:43 +0100566 int keysize;
Manuel Pégourié-Gonnard2cf5a7c2015-04-08 12:49:31 +0200567 mbedtls_gcm_context gcm;
Manuel Pégourié-Gonnardc34e8dd2015-04-28 21:42:17 +0200568
Gilles Peskine1b6c09a2023-01-11 14:52:35 +0100569 mbedtls_gcm_init(&gcm);
570 for (keysize = 128; keysize <= 256; keysize += 64) {
571 mbedtls_snprintf(title, sizeof(title), "AES-GCM-%d", keysize);
Paul Bakker89e80c92012-03-20 13:50:09 +0000572
Gilles Peskine1b6c09a2023-01-11 14:52:35 +0100573 memset(buf, 0, sizeof(buf));
574 memset(tmp, 0, sizeof(tmp));
575 mbedtls_gcm_setkey(&gcm, MBEDTLS_CIPHER_ID_AES, tmp, keysize);
Paul Bakker89e80c92012-03-20 13:50:09 +0000576
Gilles Peskine1b6c09a2023-01-11 14:52:35 +0100577 TIME_AND_TSC(title,
578 mbedtls_gcm_crypt_and_tag(&gcm, MBEDTLS_GCM_ENCRYPT, BUFSIZE, tmp,
579 12, NULL, 0, buf, buf, 16, tmp));
Paul Bakkerf70fe812013-12-16 16:43:10 +0100580
Gilles Peskine1b6c09a2023-01-11 14:52:35 +0100581 mbedtls_gcm_free(&gcm);
Manuel Pégourié-Gonnard8271f2f2013-09-17 14:57:55 +0200582 }
Paul Bakker89e80c92012-03-20 13:50:09 +0000583 }
584#endif
Manuel Pégourié-Gonnard2cf5a7c2015-04-08 12:49:31 +0200585#if defined(MBEDTLS_CCM_C)
Gilles Peskine1b6c09a2023-01-11 14:52:35 +0100586 if (todo.aes_ccm) {
Manuel Pégourié-Gonnard71e75dc2014-12-19 18:05:43 +0100587 int keysize;
Manuel Pégourié-Gonnard2cf5a7c2015-04-08 12:49:31 +0200588 mbedtls_ccm_context ccm;
Manuel Pégourié-Gonnard6963ff02015-04-28 18:02:54 +0200589
Gilles Peskine1b6c09a2023-01-11 14:52:35 +0100590 mbedtls_ccm_init(&ccm);
591 for (keysize = 128; keysize <= 256; keysize += 64) {
592 mbedtls_snprintf(title, sizeof(title), "AES-CCM-%d", keysize);
Manuel Pégourié-Gonnard58d78a82014-05-07 12:03:02 +0200593
Gilles Peskine1b6c09a2023-01-11 14:52:35 +0100594 memset(buf, 0, sizeof(buf));
595 memset(tmp, 0, sizeof(tmp));
596 mbedtls_ccm_setkey(&ccm, MBEDTLS_CIPHER_ID_AES, tmp, keysize);
Manuel Pégourié-Gonnard58d78a82014-05-07 12:03:02 +0200597
Gilles Peskine1b6c09a2023-01-11 14:52:35 +0100598 TIME_AND_TSC(title,
599 mbedtls_ccm_encrypt_and_tag(&ccm, BUFSIZE, tmp,
600 12, NULL, 0, buf, buf, tmp, 16));
Manuel Pégourié-Gonnard58d78a82014-05-07 12:03:02 +0200601
Gilles Peskine1b6c09a2023-01-11 14:52:35 +0100602 mbedtls_ccm_free(&ccm);
Manuel Pégourié-Gonnard58d78a82014-05-07 12:03:02 +0200603 }
604 }
605#endif
Manuel Pégourié-Gonnardd6aea182018-05-09 10:21:28 +0200606#if defined(MBEDTLS_CHACHAPOLY_C)
Gilles Peskine1b6c09a2023-01-11 14:52:35 +0100607 if (todo.chachapoly) {
Manuel Pégourié-Gonnardd6aea182018-05-09 10:21:28 +0200608 mbedtls_chachapoly_context chachapoly;
609
Gilles Peskine1b6c09a2023-01-11 14:52:35 +0100610 mbedtls_chachapoly_init(&chachapoly);
611 memset(buf, 0, sizeof(buf));
612 memset(tmp, 0, sizeof(tmp));
Manuel Pégourié-Gonnardd6aea182018-05-09 10:21:28 +0200613
Gilles Peskine1b6c09a2023-01-11 14:52:35 +0100614 mbedtls_snprintf(title, sizeof(title), "ChaCha20-Poly1305");
Manuel Pégourié-Gonnardd6aea182018-05-09 10:21:28 +0200615
Gilles Peskine1b6c09a2023-01-11 14:52:35 +0100616 mbedtls_chachapoly_setkey(&chachapoly, tmp);
Manuel Pégourié-Gonnardd6aea182018-05-09 10:21:28 +0200617
Gilles Peskine1b6c09a2023-01-11 14:52:35 +0100618 TIME_AND_TSC(title,
619 mbedtls_chachapoly_encrypt_and_tag(&chachapoly,
620 BUFSIZE, tmp, NULL, 0, buf, buf, tmp));
Manuel Pégourié-Gonnardd6aea182018-05-09 10:21:28 +0200621
Gilles Peskine1b6c09a2023-01-11 14:52:35 +0100622 mbedtls_chachapoly_free(&chachapoly);
Manuel Pégourié-Gonnardd6aea182018-05-09 10:21:28 +0200623 }
624#endif
Simon Butcher549dc3d2016-10-05 14:14:19 +0100625#if defined(MBEDTLS_CMAC_C)
Gilles Peskine1b6c09a2023-01-11 14:52:35 +0100626 if (todo.aes_cmac) {
Simon Butcher549dc3d2016-10-05 14:14:19 +0100627 unsigned char output[16];
628 const mbedtls_cipher_info_t *cipher_info;
629 mbedtls_cipher_type_t cipher_type;
630 int keysize;
631
Gilles Peskine1b6c09a2023-01-11 14:52:35 +0100632 for (keysize = 128, cipher_type = MBEDTLS_CIPHER_AES_128_ECB;
Simon Butcher549dc3d2016-10-05 14:14:19 +0100633 keysize <= 256;
Gilles Peskine1b6c09a2023-01-11 14:52:35 +0100634 keysize += 64, cipher_type++) {
635 mbedtls_snprintf(title, sizeof(title), "AES-CMAC-%d", keysize);
Simon Butcher549dc3d2016-10-05 14:14:19 +0100636
Gilles Peskine1b6c09a2023-01-11 14:52:35 +0100637 memset(buf, 0, sizeof(buf));
638 memset(tmp, 0, sizeof(tmp));
Simon Butcher549dc3d2016-10-05 14:14:19 +0100639
Gilles Peskine1b6c09a2023-01-11 14:52:35 +0100640 cipher_info = mbedtls_cipher_info_from_type(cipher_type);
Simon Butcher549dc3d2016-10-05 14:14:19 +0100641
Gilles Peskine1b6c09a2023-01-11 14:52:35 +0100642 TIME_AND_TSC(title,
643 mbedtls_cipher_cmac(cipher_info, tmp, keysize,
644 buf, BUFSIZE, output));
Simon Butcher549dc3d2016-10-05 14:14:19 +0100645 }
646
Gilles Peskine1b6c09a2023-01-11 14:52:35 +0100647 memset(buf, 0, sizeof(buf));
648 memset(tmp, 0, sizeof(tmp));
649 TIME_AND_TSC("AES-CMAC-PRF-128",
650 mbedtls_aes_cmac_prf_128(tmp, 16, buf, BUFSIZE,
651 output));
Simon Butcher549dc3d2016-10-05 14:14:19 +0100652 }
653#endif /* MBEDTLS_CMAC_C */
654#endif /* MBEDTLS_AES_C */
Paul Bakker5121ce52009-01-03 21:22:43 +0000655
Manuel Pégourié-Gonnard62e813c2018-02-21 10:47:47 +0100656#if defined(MBEDTLS_ARIA_C) && defined(MBEDTLS_CIPHER_MODE_CBC)
Gilles Peskine1b6c09a2023-01-11 14:52:35 +0100657 if (todo.aria) {
Manuel Pégourié-Gonnard62e813c2018-02-21 10:47:47 +0100658 int keysize;
659 mbedtls_aria_context aria;
Gilles Peskine1b6c09a2023-01-11 14:52:35 +0100660 mbedtls_aria_init(&aria);
661 for (keysize = 128; keysize <= 256; keysize += 64) {
662 mbedtls_snprintf(title, sizeof(title), "ARIA-CBC-%d", keysize);
Manuel Pégourié-Gonnard62e813c2018-02-21 10:47:47 +0100663
Gilles Peskine1b6c09a2023-01-11 14:52:35 +0100664 memset(buf, 0, sizeof(buf));
665 memset(tmp, 0, sizeof(tmp));
666 mbedtls_aria_setkey_enc(&aria, tmp, keysize);
Manuel Pégourié-Gonnard62e813c2018-02-21 10:47:47 +0100667
Gilles Peskine1b6c09a2023-01-11 14:52:35 +0100668 TIME_AND_TSC(title,
669 mbedtls_aria_crypt_cbc(&aria, MBEDTLS_ARIA_ENCRYPT,
670 BUFSIZE, tmp, buf, buf));
Manuel Pégourié-Gonnard62e813c2018-02-21 10:47:47 +0100671 }
Gilles Peskine1b6c09a2023-01-11 14:52:35 +0100672 mbedtls_aria_free(&aria);
Manuel Pégourié-Gonnard62e813c2018-02-21 10:47:47 +0100673 }
674#endif
675
Manuel Pégourié-Gonnard2cf5a7c2015-04-08 12:49:31 +0200676#if defined(MBEDTLS_CAMELLIA_C) && defined(MBEDTLS_CIPHER_MODE_CBC)
Gilles Peskine1b6c09a2023-01-11 14:52:35 +0100677 if (todo.camellia) {
Manuel Pégourié-Gonnard71e75dc2014-12-19 18:05:43 +0100678 int keysize;
Manuel Pégourié-Gonnard2cf5a7c2015-04-08 12:49:31 +0200679 mbedtls_camellia_context camellia;
Gilles Peskine1b6c09a2023-01-11 14:52:35 +0100680 mbedtls_camellia_init(&camellia);
681 for (keysize = 128; keysize <= 256; keysize += 64) {
682 mbedtls_snprintf(title, sizeof(title), "CAMELLIA-CBC-%d", keysize);
Paul Bakker38119b12009-01-10 23:31:23 +0000683
Gilles Peskine1b6c09a2023-01-11 14:52:35 +0100684 memset(buf, 0, sizeof(buf));
685 memset(tmp, 0, sizeof(tmp));
686 mbedtls_camellia_setkey_enc(&camellia, tmp, keysize);
Paul Bakker38119b12009-01-10 23:31:23 +0000687
Gilles Peskine1b6c09a2023-01-11 14:52:35 +0100688 TIME_AND_TSC(title,
689 mbedtls_camellia_crypt_cbc(&camellia, MBEDTLS_CAMELLIA_ENCRYPT,
690 BUFSIZE, tmp, buf, buf));
Manuel Pégourié-Gonnard8271f2f2013-09-17 14:57:55 +0200691 }
Gilles Peskine1b6c09a2023-01-11 14:52:35 +0100692 mbedtls_camellia_free(&camellia);
Paul Bakker38119b12009-01-10 23:31:23 +0000693 }
694#endif
695
Daniel King34b822c2016-05-15 17:28:08 -0300696#if defined(MBEDTLS_CHACHA20_C)
Gilles Peskine1b6c09a2023-01-11 14:52:35 +0100697 if (todo.chacha20) {
698 TIME_AND_TSC("ChaCha20", mbedtls_chacha20_crypt(buf, buf, 0U, BUFSIZE, buf, buf));
Daniel King34b822c2016-05-15 17:28:08 -0300699 }
700#endif
701
Daniel Kingadc32c02016-05-16 18:25:45 -0300702#if defined(MBEDTLS_POLY1305_C)
Gilles Peskine1b6c09a2023-01-11 14:52:35 +0100703 if (todo.poly1305) {
704 TIME_AND_TSC("Poly1305", mbedtls_poly1305_mac(buf, buf, BUFSIZE, buf));
Daniel Kingadc32c02016-05-16 18:25:45 -0300705 }
706#endif
707
Manuel Pégourié-Gonnard2cf5a7c2015-04-08 12:49:31 +0200708#if defined(MBEDTLS_BLOWFISH_C) && defined(MBEDTLS_CIPHER_MODE_CBC)
Gilles Peskine1b6c09a2023-01-11 14:52:35 +0100709 if (todo.blowfish) {
Manuel Pégourié-Gonnard71e75dc2014-12-19 18:05:43 +0100710 int keysize;
Manuel Pégourié-Gonnard2cf5a7c2015-04-08 12:49:31 +0200711 mbedtls_blowfish_context blowfish;
Gilles Peskine1b6c09a2023-01-11 14:52:35 +0100712 mbedtls_blowfish_init(&blowfish);
Paul Bakker8cfd9d82014-06-18 11:16:11 +0200713
Gilles Peskine1b6c09a2023-01-11 14:52:35 +0100714 for (keysize = 128; keysize <= 256; keysize += 64) {
715 mbedtls_snprintf(title, sizeof(title), "BLOWFISH-CBC-%d", keysize);
Paul Bakker3d58fe82012-07-04 17:15:31 +0000716
Gilles Peskine1b6c09a2023-01-11 14:52:35 +0100717 memset(buf, 0, sizeof(buf));
718 memset(tmp, 0, sizeof(tmp));
719 mbedtls_blowfish_setkey(&blowfish, tmp, keysize);
Paul Bakker3d58fe82012-07-04 17:15:31 +0000720
Gilles Peskine1b6c09a2023-01-11 14:52:35 +0100721 TIME_AND_TSC(title,
722 mbedtls_blowfish_crypt_cbc(&blowfish, MBEDTLS_BLOWFISH_ENCRYPT, BUFSIZE,
723 tmp, buf, buf));
Manuel Pégourié-Gonnard8271f2f2013-09-17 14:57:55 +0200724 }
Paul Bakker8cfd9d82014-06-18 11:16:11 +0200725
Gilles Peskine1b6c09a2023-01-11 14:52:35 +0100726 mbedtls_blowfish_free(&blowfish);
Paul Bakker3d58fe82012-07-04 17:15:31 +0000727 }
728#endif
729
Manuel Pégourié-Gonnard2cf5a7c2015-04-08 12:49:31 +0200730#if defined(MBEDTLS_HAVEGE_C)
Gilles Peskine1b6c09a2023-01-11 14:52:35 +0100731 if (todo.havege) {
Manuel Pégourié-Gonnard2cf5a7c2015-04-08 12:49:31 +0200732 mbedtls_havege_state hs;
Gilles Peskine1b6c09a2023-01-11 14:52:35 +0100733 mbedtls_havege_init(&hs);
734 TIME_AND_TSC("HAVEGE", mbedtls_havege_random(&hs, buf, BUFSIZE));
735 mbedtls_havege_free(&hs);
Manuel Pégourié-Gonnard8271f2f2013-09-17 14:57:55 +0200736 }
Paul Bakker02faf452011-11-29 11:23:58 +0000737#endif
738
Manuel Pégourié-Gonnard2cf5a7c2015-04-08 12:49:31 +0200739#if defined(MBEDTLS_CTR_DRBG_C)
Gilles Peskine1b6c09a2023-01-11 14:52:35 +0100740 if (todo.ctr_drbg) {
Manuel Pégourié-Gonnard2cf5a7c2015-04-08 12:49:31 +0200741 mbedtls_ctr_drbg_context ctr_drbg;
Paul Bakker02faf452011-11-29 11:23:58 +0000742
Gilles Peskine1b6c09a2023-01-11 14:52:35 +0100743 mbedtls_ctr_drbg_init(&ctr_drbg);
744 if (mbedtls_ctr_drbg_seed(&ctr_drbg, myrand, NULL, NULL, 0) != 0) {
Manuel Pégourié-Gonnard2cf5a7c2015-04-08 12:49:31 +0200745 mbedtls_exit(1);
Gilles Peskine1b6c09a2023-01-11 14:52:35 +0100746 }
747 TIME_AND_TSC("CTR_DRBG (NOPR)",
748 mbedtls_ctr_drbg_random(&ctr_drbg, buf, BUFSIZE));
749 mbedtls_ctr_drbg_free(&ctr_drbg);
Paul Bakker02faf452011-11-29 11:23:58 +0000750
Gilles Peskine1b6c09a2023-01-11 14:52:35 +0100751 mbedtls_ctr_drbg_init(&ctr_drbg);
752 if (mbedtls_ctr_drbg_seed(&ctr_drbg, myrand, NULL, NULL, 0) != 0) {
Manuel Pégourié-Gonnard2cf5a7c2015-04-08 12:49:31 +0200753 mbedtls_exit(1);
Gilles Peskine1b6c09a2023-01-11 14:52:35 +0100754 }
755 mbedtls_ctr_drbg_set_prediction_resistance(&ctr_drbg, MBEDTLS_CTR_DRBG_PR_ON);
756 TIME_AND_TSC("CTR_DRBG (PR)",
757 mbedtls_ctr_drbg_random(&ctr_drbg, buf, BUFSIZE));
758 mbedtls_ctr_drbg_free(&ctr_drbg);
Manuel Pégourié-Gonnard8271f2f2013-09-17 14:57:55 +0200759 }
Paul Bakker02faf452011-11-29 11:23:58 +0000760#endif
761
Andrzej Kurekb3b0ec92022-10-18 08:21:07 -0400762#if defined(MBEDTLS_HMAC_DRBG_C) && \
Gilles Peskine1b6c09a2023-01-11 14:52:35 +0100763 (defined(MBEDTLS_SHA1_C) || defined(MBEDTLS_SHA256_C))
764 if (todo.hmac_drbg) {
Manuel Pégourié-Gonnard2cf5a7c2015-04-08 12:49:31 +0200765 mbedtls_hmac_drbg_context hmac_drbg;
766 const mbedtls_md_info_t *md_info;
Manuel Pégourié-Gonnardfef0f8f2014-01-30 20:59:00 +0100767
Gilles Peskine1b6c09a2023-01-11 14:52:35 +0100768 mbedtls_hmac_drbg_init(&hmac_drbg);
Manuel Pégourié-Gonnardf9e94812015-04-28 22:07:14 +0200769
Manuel Pégourié-Gonnard2cf5a7c2015-04-08 12:49:31 +0200770#if defined(MBEDTLS_SHA1_C)
Gilles Peskine1b6c09a2023-01-11 14:52:35 +0100771 if ((md_info = mbedtls_md_info_from_type(MBEDTLS_MD_SHA1)) == NULL) {
Manuel Pégourié-Gonnard2cf5a7c2015-04-08 12:49:31 +0200772 mbedtls_exit(1);
Gilles Peskine1b6c09a2023-01-11 14:52:35 +0100773 }
Manuel Pégourié-Gonnardfef0f8f2014-01-30 20:59:00 +0100774
Gilles Peskine1b6c09a2023-01-11 14:52:35 +0100775 if (mbedtls_hmac_drbg_seed(&hmac_drbg, md_info, myrand, NULL, NULL, 0) != 0) {
Manuel Pégourié-Gonnard2cf5a7c2015-04-08 12:49:31 +0200776 mbedtls_exit(1);
Gilles Peskine1b6c09a2023-01-11 14:52:35 +0100777 }
778 TIME_AND_TSC("HMAC_DRBG SHA-1 (NOPR)",
779 mbedtls_hmac_drbg_random(&hmac_drbg, buf, BUFSIZE));
Manuel Pégourié-Gonnardfef0f8f2014-01-30 20:59:00 +0100780
Gilles Peskine1b6c09a2023-01-11 14:52:35 +0100781 if (mbedtls_hmac_drbg_seed(&hmac_drbg, md_info, myrand, NULL, NULL, 0) != 0) {
Manuel Pégourié-Gonnard2cf5a7c2015-04-08 12:49:31 +0200782 mbedtls_exit(1);
Gilles Peskine1b6c09a2023-01-11 14:52:35 +0100783 }
784 mbedtls_hmac_drbg_set_prediction_resistance(&hmac_drbg,
785 MBEDTLS_HMAC_DRBG_PR_ON);
786 TIME_AND_TSC("HMAC_DRBG SHA-1 (PR)",
787 mbedtls_hmac_drbg_random(&hmac_drbg, buf, BUFSIZE));
Manuel Pégourié-Gonnardfef0f8f2014-01-30 20:59:00 +0100788#endif
789
Manuel Pégourié-Gonnard2cf5a7c2015-04-08 12:49:31 +0200790#if defined(MBEDTLS_SHA256_C)
Gilles Peskine1b6c09a2023-01-11 14:52:35 +0100791 if ((md_info = mbedtls_md_info_from_type(MBEDTLS_MD_SHA256)) == NULL) {
Manuel Pégourié-Gonnard2cf5a7c2015-04-08 12:49:31 +0200792 mbedtls_exit(1);
Gilles Peskine1b6c09a2023-01-11 14:52:35 +0100793 }
Manuel Pégourié-Gonnardfef0f8f2014-01-30 20:59:00 +0100794
Gilles Peskine1b6c09a2023-01-11 14:52:35 +0100795 if (mbedtls_hmac_drbg_seed(&hmac_drbg, md_info, myrand, NULL, NULL, 0) != 0) {
Manuel Pégourié-Gonnard2cf5a7c2015-04-08 12:49:31 +0200796 mbedtls_exit(1);
Gilles Peskine1b6c09a2023-01-11 14:52:35 +0100797 }
798 TIME_AND_TSC("HMAC_DRBG SHA-256 (NOPR)",
799 mbedtls_hmac_drbg_random(&hmac_drbg, buf, BUFSIZE));
Manuel Pégourié-Gonnardfef0f8f2014-01-30 20:59:00 +0100800
Gilles Peskine1b6c09a2023-01-11 14:52:35 +0100801 if (mbedtls_hmac_drbg_seed(&hmac_drbg, md_info, myrand, NULL, NULL, 0) != 0) {
Manuel Pégourié-Gonnard2cf5a7c2015-04-08 12:49:31 +0200802 mbedtls_exit(1);
Gilles Peskine1b6c09a2023-01-11 14:52:35 +0100803 }
804 mbedtls_hmac_drbg_set_prediction_resistance(&hmac_drbg,
805 MBEDTLS_HMAC_DRBG_PR_ON);
806 TIME_AND_TSC("HMAC_DRBG SHA-256 (PR)",
807 mbedtls_hmac_drbg_random(&hmac_drbg, buf, BUFSIZE));
Manuel Pégourié-Gonnardfef0f8f2014-01-30 20:59:00 +0100808#endif
Gilles Peskine1b6c09a2023-01-11 14:52:35 +0100809 mbedtls_hmac_drbg_free(&hmac_drbg);
Manuel Pégourié-Gonnardfef0f8f2014-01-30 20:59:00 +0100810 }
Andrzej Kurekb3b0ec92022-10-18 08:21:07 -0400811#endif /* MBEDTLS_HMAC_DRBG_C && ( MBEDTLS_SHA1_C || MBEDTLS_SHA256_C ) */
Manuel Pégourié-Gonnardfef0f8f2014-01-30 20:59:00 +0100812
Manuel Pégourié-Gonnard2cf5a7c2015-04-08 12:49:31 +0200813#if defined(MBEDTLS_RSA_C) && defined(MBEDTLS_GENPRIME)
Gilles Peskine1b6c09a2023-01-11 14:52:35 +0100814 if (todo.rsa) {
Manuel Pégourié-Gonnard71e75dc2014-12-19 18:05:43 +0100815 int keysize;
Manuel Pégourié-Gonnard2cf5a7c2015-04-08 12:49:31 +0200816 mbedtls_rsa_context rsa;
Gilles Peskine1b6c09a2023-01-11 14:52:35 +0100817 for (keysize = 2048; keysize <= 4096; keysize *= 2) {
818 mbedtls_snprintf(title, sizeof(title), "RSA-%d", keysize);
Manuel Pégourié-Gonnard8271f2f2013-09-17 14:57:55 +0200819
Gilles Peskine1b6c09a2023-01-11 14:52:35 +0100820 mbedtls_rsa_init(&rsa, MBEDTLS_RSA_PKCS_V15, 0);
821 mbedtls_rsa_gen_key(&rsa, myrand, NULL, keysize, 65537);
Manuel Pégourié-Gonnard8271f2f2013-09-17 14:57:55 +0200822
Gilles Peskine1b6c09a2023-01-11 14:52:35 +0100823 TIME_PUBLIC(title, " public",
824 buf[0] = 0;
825 ret = mbedtls_rsa_public(&rsa, buf, buf));
Manuel Pégourié-Gonnard8271f2f2013-09-17 14:57:55 +0200826
Gilles Peskine1b6c09a2023-01-11 14:52:35 +0100827 TIME_PUBLIC(title, "private",
828 buf[0] = 0;
829 ret = mbedtls_rsa_private(&rsa, myrand, NULL, buf, buf));
Manuel Pégourié-Gonnard8271f2f2013-09-17 14:57:55 +0200830
Gilles Peskine1b6c09a2023-01-11 14:52:35 +0100831 mbedtls_rsa_free(&rsa);
Manuel Pégourié-Gonnard8271f2f2013-09-17 14:57:55 +0200832 }
Paul Bakker5121ce52009-01-03 21:22:43 +0000833 }
Paul Bakker5121ce52009-01-03 21:22:43 +0000834#endif
835
Manuel Pégourié-Gonnard2cf5a7c2015-04-08 12:49:31 +0200836#if defined(MBEDTLS_DHM_C) && defined(MBEDTLS_BIGNUM_C)
Gilles Peskine1b6c09a2023-01-11 14:52:35 +0100837 if (todo.dhm) {
Manuel Pégourié-Gonnard4f3368e2015-07-19 15:01:28 +0200838 int dhm_sizes[] = { 2048, 3072 };
Brendan Shankse61514d2018-03-08 17:40:56 -0800839 static const unsigned char dhm_P_2048[] =
Hanno Beckerb9539212017-10-04 13:13:34 +0100840 MBEDTLS_DHM_RFC3526_MODP_2048_P_BIN;
Brendan Shankse61514d2018-03-08 17:40:56 -0800841 static const unsigned char dhm_P_3072[] =
Hanno Beckerb9539212017-10-04 13:13:34 +0100842 MBEDTLS_DHM_RFC3526_MODP_3072_P_BIN;
Brendan Shankse61514d2018-03-08 17:40:56 -0800843 static const unsigned char dhm_G_2048[] =
Hanno Beckerb9539212017-10-04 13:13:34 +0100844 MBEDTLS_DHM_RFC3526_MODP_2048_G_BIN;
Brendan Shankse61514d2018-03-08 17:40:56 -0800845 static const unsigned char dhm_G_3072[] =
Hanno Beckerb9539212017-10-04 13:13:34 +0100846 MBEDTLS_DHM_RFC3526_MODP_3072_G_BIN;
847
848 const unsigned char *dhm_P[] = { dhm_P_2048, dhm_P_3072 };
Gilles Peskine1b6c09a2023-01-11 14:52:35 +0100849 const size_t dhm_P_size[] = { sizeof(dhm_P_2048),
850 sizeof(dhm_P_3072) };
Hanno Beckerb9539212017-10-04 13:13:34 +0100851
852 const unsigned char *dhm_G[] = { dhm_G_2048, dhm_G_3072 };
Gilles Peskine1b6c09a2023-01-11 14:52:35 +0100853 const size_t dhm_G_size[] = { sizeof(dhm_G_2048),
854 sizeof(dhm_G_3072) };
Manuel Pégourié-Gonnard8271f2f2013-09-17 14:57:55 +0200855
Manuel Pégourié-Gonnard2cf5a7c2015-04-08 12:49:31 +0200856 mbedtls_dhm_context dhm;
Manuel Pégourié-Gonnard8271f2f2013-09-17 14:57:55 +0200857 size_t olen;
Gilles Peskine1b6c09a2023-01-11 14:52:35 +0100858 for (i = 0; (size_t) i < sizeof(dhm_sizes) / sizeof(dhm_sizes[0]); i++) {
859 mbedtls_dhm_init(&dhm);
Manuel Pégourié-Gonnard8271f2f2013-09-17 14:57:55 +0200860
Gilles Peskine1b6c09a2023-01-11 14:52:35 +0100861 if (mbedtls_mpi_read_binary(&dhm.P, dhm_P[i],
862 dhm_P_size[i]) != 0 ||
863 mbedtls_mpi_read_binary(&dhm.G, dhm_G[i],
864 dhm_G_size[i]) != 0) {
865 mbedtls_exit(1);
Paul Bakkercbe3d0d2014-04-17 16:00:59 +0200866 }
867
Gilles Peskine1b6c09a2023-01-11 14:52:35 +0100868 dhm.len = mbedtls_mpi_size(&dhm.P);
869 mbedtls_dhm_make_public(&dhm, (int) dhm.len, buf, dhm.len, myrand, NULL);
870 if (mbedtls_mpi_copy(&dhm.GY, &dhm.GX) != 0) {
871 mbedtls_exit(1);
872 }
Manuel Pégourié-Gonnard8271f2f2013-09-17 14:57:55 +0200873
Gilles Peskine1b6c09a2023-01-11 14:52:35 +0100874 mbedtls_snprintf(title, sizeof(title), "DHE-%d", dhm_sizes[i]);
875 TIME_PUBLIC(title, "handshake",
876 ret |= mbedtls_dhm_make_public(&dhm, (int) dhm.len, buf, dhm.len,
877 myrand, NULL);
878 ret |=
879 mbedtls_dhm_calc_secret(&dhm, buf, sizeof(buf), &olen, myrand, NULL));
Manuel Pégourié-Gonnard8271f2f2013-09-17 14:57:55 +0200880
Gilles Peskine1b6c09a2023-01-11 14:52:35 +0100881 mbedtls_snprintf(title, sizeof(title), "DH-%d", dhm_sizes[i]);
882 TIME_PUBLIC(title, "handshake",
883 ret |=
884 mbedtls_dhm_calc_secret(&dhm, buf, sizeof(buf), &olen, myrand, NULL));
Manuel Pégourié-Gonnard8271f2f2013-09-17 14:57:55 +0200885
Gilles Peskine1b6c09a2023-01-11 14:52:35 +0100886 mbedtls_dhm_free(&dhm);
Manuel Pégourié-Gonnard8271f2f2013-09-17 14:57:55 +0200887 }
Manuel Pégourié-Gonnarde870c0a2012-11-08 11:31:48 +0100888 }
Manuel Pégourié-Gonnarde870c0a2012-11-08 11:31:48 +0100889#endif
890
Manuel Pégourié-Gonnard2cf5a7c2015-04-08 12:49:31 +0200891#if defined(MBEDTLS_ECDSA_C) && defined(MBEDTLS_SHA256_C)
Gilles Peskine1b6c09a2023-01-11 14:52:35 +0100892 if (todo.ecdsa) {
Manuel Pégourié-Gonnard2cf5a7c2015-04-08 12:49:31 +0200893 mbedtls_ecdsa_context ecdsa;
894 const mbedtls_ecp_curve_info *curve_info;
Manuel Pégourié-Gonnardcc34f952013-09-17 16:04:08 +0200895 size_t sig_len;
896
Gilles Peskine1b6c09a2023-01-11 14:52:35 +0100897 memset(buf, 0x2A, sizeof(buf));
Manuel Pégourié-Gonnardcc34f952013-09-17 16:04:08 +0200898
Gilles Peskine1b6c09a2023-01-11 14:52:35 +0100899 for (curve_info = curve_list;
Manuel Pégourié-Gonnard2cf5a7c2015-04-08 12:49:31 +0200900 curve_info->grp_id != MBEDTLS_ECP_DP_NONE;
Gilles Peskine1b6c09a2023-01-11 14:52:35 +0100901 curve_info++) {
902 if (!mbedtls_ecdsa_can_do(curve_info->grp_id)) {
Christoph M. Wintersteiger6a1a9e42019-01-07 13:47:30 +0000903 continue;
Gilles Peskine1b6c09a2023-01-11 14:52:35 +0100904 }
Christoph M. Wintersteiger6a1a9e42019-01-07 13:47:30 +0000905
Gilles Peskine1b6c09a2023-01-11 14:52:35 +0100906 mbedtls_ecdsa_init(&ecdsa);
Manuel Pégourié-Gonnardcc34f952013-09-17 16:04:08 +0200907
Gilles Peskine1b6c09a2023-01-11 14:52:35 +0100908 if (mbedtls_ecdsa_genkey(&ecdsa, curve_info->grp_id, myrand, NULL) != 0) {
909 mbedtls_exit(1);
910 }
911 ecp_clear_precomputed(&ecdsa.grp);
Manuel Pégourié-Gonnardcc34f952013-09-17 16:04:08 +0200912
Gilles Peskine1b6c09a2023-01-11 14:52:35 +0100913 mbedtls_snprintf(title, sizeof(title), "ECDSA-%s",
914 curve_info->name);
915 TIME_PUBLIC(title, "sign",
916 ret =
917 mbedtls_ecdsa_write_signature(&ecdsa, MBEDTLS_MD_SHA256, buf,
918 curve_info->bit_size,
919 tmp, &sig_len, myrand, NULL));
Manuel Pégourié-Gonnard56cd3192013-09-17 17:23:07 +0200920
Gilles Peskine1b6c09a2023-01-11 14:52:35 +0100921 mbedtls_ecdsa_free(&ecdsa);
Manuel Pégourié-Gonnard50da0482014-12-19 12:10:37 +0100922 }
923
Gilles Peskine1b6c09a2023-01-11 14:52:35 +0100924 for (curve_info = curve_list;
Manuel Pégourié-Gonnard2cf5a7c2015-04-08 12:49:31 +0200925 curve_info->grp_id != MBEDTLS_ECP_DP_NONE;
Gilles Peskine1b6c09a2023-01-11 14:52:35 +0100926 curve_info++) {
927 if (!mbedtls_ecdsa_can_do(curve_info->grp_id)) {
Christoph M. Wintersteiger6a1a9e42019-01-07 13:47:30 +0000928 continue;
Manuel Pégourié-Gonnard50da0482014-12-19 12:10:37 +0100929 }
Manuel Pégourié-Gonnard50da0482014-12-19 12:10:37 +0100930
Gilles Peskine1b6c09a2023-01-11 14:52:35 +0100931 mbedtls_ecdsa_init(&ecdsa);
Manuel Pégourié-Gonnardcc34f952013-09-17 16:04:08 +0200932
Gilles Peskine1b6c09a2023-01-11 14:52:35 +0100933 if (mbedtls_ecdsa_genkey(&ecdsa, curve_info->grp_id, myrand, NULL) != 0 ||
934 mbedtls_ecdsa_write_signature(&ecdsa, MBEDTLS_MD_SHA256, buf, curve_info->bit_size,
935 tmp, &sig_len, myrand, NULL) != 0) {
936 mbedtls_exit(1);
937 }
938 ecp_clear_precomputed(&ecdsa.grp);
939
940 mbedtls_snprintf(title, sizeof(title), "ECDSA-%s",
941 curve_info->name);
942 TIME_PUBLIC(title, "verify",
943 ret = mbedtls_ecdsa_read_signature(&ecdsa, buf, curve_info->bit_size,
944 tmp, sig_len));
945
946 mbedtls_ecdsa_free(&ecdsa);
Manuel Pégourié-Gonnardcc34f952013-09-17 16:04:08 +0200947 }
948 }
949#endif
950
Janos Follath52735ef2018-08-15 10:19:16 +0100951#if defined(MBEDTLS_ECDH_C) && defined(MBEDTLS_ECDH_LEGACY_CONTEXT)
Gilles Peskine1b6c09a2023-01-11 14:52:35 +0100952 if (todo.ecdh) {
Manuel Pégourié-Gonnard2cf5a7c2015-04-08 12:49:31 +0200953 mbedtls_ecdh_context ecdh;
Manuel Pégourié-Gonnard2cf5a7c2015-04-08 12:49:31 +0200954 mbedtls_mpi z;
Nicholas Wilson08f3ef12015-11-10 13:10:01 +0000955 const mbedtls_ecp_curve_info montgomery_curve_list[] = {
956#if defined(MBEDTLS_ECP_DP_CURVE25519_ENABLED)
957 { MBEDTLS_ECP_DP_CURVE25519, 0, 0, "Curve25519" },
Manuel Pégourié-Gonnard85391f22015-02-05 09:54:48 +0000958#endif
Nicholas Wilson08f3ef12015-11-10 13:10:01 +0000959#if defined(MBEDTLS_ECP_DP_CURVE448_ENABLED)
960 { MBEDTLS_ECP_DP_CURVE448, 0, 0, "Curve448" },
961#endif
962 { MBEDTLS_ECP_DP_NONE, 0, 0, 0 }
963 };
Manuel Pégourié-Gonnard2cf5a7c2015-04-08 12:49:31 +0200964 const mbedtls_ecp_curve_info *curve_info;
Manuel Pégourié-Gonnardcc34f952013-09-17 16:04:08 +0200965 size_t olen;
Gilles Peskine28f62f62020-07-24 02:06:46 +0200966 const mbedtls_ecp_curve_info *selected_montgomery_curve_list =
967 montgomery_curve_list;
Manuel Pégourié-Gonnardcc34f952013-09-17 16:04:08 +0200968
Gilles Peskine1b6c09a2023-01-11 14:52:35 +0100969 if (curve_list == (const mbedtls_ecp_curve_info *) &single_curve) {
Gilles Peskine28f62f62020-07-24 02:06:46 +0200970 mbedtls_ecp_group grp;
Gilles Peskine1b6c09a2023-01-11 14:52:35 +0100971 mbedtls_ecp_group_init(&grp);
972 if (mbedtls_ecp_group_load(&grp, curve_list->grp_id) != 0) {
973 mbedtls_exit(1);
974 }
975 if (mbedtls_ecp_get_type(&grp) == MBEDTLS_ECP_TYPE_MONTGOMERY) {
Gilles Peskine28f62f62020-07-24 02:06:46 +0200976 selected_montgomery_curve_list = single_curve;
Gilles Peskine1b6c09a2023-01-11 14:52:35 +0100977 } else { /* empty list */
Gilles Peskine28f62f62020-07-24 02:06:46 +0200978 selected_montgomery_curve_list = single_curve + 1;
Gilles Peskine1b6c09a2023-01-11 14:52:35 +0100979 }
980 mbedtls_ecp_group_free(&grp);
Gilles Peskine28f62f62020-07-24 02:06:46 +0200981 }
982
Gilles Peskine1b6c09a2023-01-11 14:52:35 +0100983 for (curve_info = curve_list;
Manuel Pégourié-Gonnard2cf5a7c2015-04-08 12:49:31 +0200984 curve_info->grp_id != MBEDTLS_ECP_DP_NONE;
Gilles Peskine1b6c09a2023-01-11 14:52:35 +0100985 curve_info++) {
986 if (!mbedtls_ecdh_can_do(curve_info->grp_id)) {
Gilles Peskinec6c7c492019-02-11 18:41:27 +0100987 continue;
Gilles Peskine1b6c09a2023-01-11 14:52:35 +0100988 }
Gilles Peskinec6c7c492019-02-11 18:41:27 +0100989
Gilles Peskine1b6c09a2023-01-11 14:52:35 +0100990 mbedtls_ecdh_init(&ecdh);
Manuel Pégourié-Gonnardcc34f952013-09-17 16:04:08 +0200991
Gilles Peskine1b6c09a2023-01-11 14:52:35 +0100992 CHECK_AND_CONTINUE(mbedtls_ecp_group_load(&ecdh.grp, curve_info->grp_id));
993 CHECK_AND_CONTINUE(mbedtls_ecdh_make_public(&ecdh, &olen, buf, sizeof(buf),
994 myrand, NULL));
995 CHECK_AND_CONTINUE(mbedtls_ecp_copy(&ecdh.Qp, &ecdh.Q));
996 ecp_clear_precomputed(&ecdh.grp);
Manuel Pégourié-Gonnardcc34f952013-09-17 16:04:08 +0200997
Gilles Peskine1b6c09a2023-01-11 14:52:35 +0100998 mbedtls_snprintf(title, sizeof(title), "ECDHE-%s",
999 curve_info->name);
1000 TIME_PUBLIC(title, "handshake",
1001 CHECK_AND_CONTINUE(mbedtls_ecdh_make_public(&ecdh, &olen, buf, sizeof(buf),
1002 myrand, NULL));
1003 CHECK_AND_CONTINUE(mbedtls_ecdh_calc_secret(&ecdh, &olen, buf, sizeof(buf),
1004 myrand, NULL)));
1005 mbedtls_ecdh_free(&ecdh);
Manuel Pégourié-Gonnard50da0482014-12-19 12:10:37 +01001006 }
1007
Nicholas Wilson08f3ef12015-11-10 13:10:01 +00001008 /* Montgomery curves need to be handled separately */
Gilles Peskine1b6c09a2023-01-11 14:52:35 +01001009 for (curve_info = selected_montgomery_curve_list;
1010 curve_info->grp_id != MBEDTLS_ECP_DP_NONE;
1011 curve_info++) {
1012 mbedtls_ecdh_init(&ecdh);
1013 mbedtls_mpi_init(&z);
Nicholas Wilson08f3ef12015-11-10 13:10:01 +00001014
Gilles Peskine1b6c09a2023-01-11 14:52:35 +01001015 CHECK_AND_CONTINUE(mbedtls_ecp_group_load(&ecdh.grp, curve_info->grp_id));
1016 CHECK_AND_CONTINUE(mbedtls_ecdh_gen_public(&ecdh.grp, &ecdh.d, &ecdh.Qp, myrand, NULL));
Nicholas Wilson08f3ef12015-11-10 13:10:01 +00001017
Gilles Peskine1b6c09a2023-01-11 14:52:35 +01001018 mbedtls_snprintf(title, sizeof(title), "ECDHE-%s",
1019 curve_info->name);
1020 TIME_PUBLIC(title, "handshake",
1021 CHECK_AND_CONTINUE(mbedtls_ecdh_gen_public(&ecdh.grp, &ecdh.d, &ecdh.Q,
1022 myrand, NULL));
1023 CHECK_AND_CONTINUE(mbedtls_ecdh_compute_shared(&ecdh.grp, &z, &ecdh.Qp,
1024 &ecdh.d,
1025 myrand, NULL)));
Nicholas Wilson08f3ef12015-11-10 13:10:01 +00001026
Gilles Peskine1b6c09a2023-01-11 14:52:35 +01001027 mbedtls_ecdh_free(&ecdh);
1028 mbedtls_mpi_free(&z);
Manuel Pégourié-Gonnard85391f22015-02-05 09:54:48 +00001029 }
1030
Gilles Peskine1b6c09a2023-01-11 14:52:35 +01001031 for (curve_info = curve_list;
Manuel Pégourié-Gonnard2cf5a7c2015-04-08 12:49:31 +02001032 curve_info->grp_id != MBEDTLS_ECP_DP_NONE;
Gilles Peskine1b6c09a2023-01-11 14:52:35 +01001033 curve_info++) {
1034 if (!mbedtls_ecdh_can_do(curve_info->grp_id)) {
Gilles Peskinec6c7c492019-02-11 18:41:27 +01001035 continue;
Gilles Peskine1b6c09a2023-01-11 14:52:35 +01001036 }
Gilles Peskinec6c7c492019-02-11 18:41:27 +01001037
Gilles Peskine1b6c09a2023-01-11 14:52:35 +01001038 mbedtls_ecdh_init(&ecdh);
Manuel Pégourié-Gonnard50da0482014-12-19 12:10:37 +01001039
Gilles Peskine1b6c09a2023-01-11 14:52:35 +01001040 CHECK_AND_CONTINUE(mbedtls_ecp_group_load(&ecdh.grp, curve_info->grp_id));
1041 CHECK_AND_CONTINUE(mbedtls_ecdh_make_public(&ecdh, &olen, buf, sizeof(buf),
1042 myrand, NULL));
1043 CHECK_AND_CONTINUE(mbedtls_ecp_copy(&ecdh.Qp, &ecdh.Q));
1044 CHECK_AND_CONTINUE(mbedtls_ecdh_make_public(&ecdh, &olen, buf, sizeof(buf),
1045 myrand, NULL));
1046 ecp_clear_precomputed(&ecdh.grp);
Manuel Pégourié-Gonnardcc34f952013-09-17 16:04:08 +02001047
Gilles Peskine1b6c09a2023-01-11 14:52:35 +01001048 mbedtls_snprintf(title, sizeof(title), "ECDH-%s",
1049 curve_info->name);
1050 TIME_PUBLIC(title, "handshake",
1051 CHECK_AND_CONTINUE(mbedtls_ecdh_calc_secret(&ecdh, &olen, buf, sizeof(buf),
1052 myrand, NULL)));
1053 mbedtls_ecdh_free(&ecdh);
Manuel Pégourié-Gonnardcc34f952013-09-17 16:04:08 +02001054 }
Manuel Pégourié-Gonnard85391f22015-02-05 09:54:48 +00001055
Nicholas Wilson08f3ef12015-11-10 13:10:01 +00001056 /* Montgomery curves need to be handled separately */
Gilles Peskine1b6c09a2023-01-11 14:52:35 +01001057 for (curve_info = selected_montgomery_curve_list;
1058 curve_info->grp_id != MBEDTLS_ECP_DP_NONE;
1059 curve_info++) {
1060 mbedtls_ecdh_init(&ecdh);
1061 mbedtls_mpi_init(&z);
Nicholas Wilson08f3ef12015-11-10 13:10:01 +00001062
Gilles Peskine1b6c09a2023-01-11 14:52:35 +01001063 CHECK_AND_CONTINUE(mbedtls_ecp_group_load(&ecdh.grp, curve_info->grp_id));
1064 CHECK_AND_CONTINUE(mbedtls_ecdh_gen_public(&ecdh.grp, &ecdh.d, &ecdh.Qp,
1065 myrand, NULL));
1066 CHECK_AND_CONTINUE(mbedtls_ecdh_gen_public(&ecdh.grp, &ecdh.d, &ecdh.Q, myrand, NULL));
Nicholas Wilson08f3ef12015-11-10 13:10:01 +00001067
Gilles Peskine1b6c09a2023-01-11 14:52:35 +01001068 mbedtls_snprintf(title, sizeof(title), "ECDH-%s",
1069 curve_info->name);
1070 TIME_PUBLIC(title, "handshake",
1071 CHECK_AND_CONTINUE(mbedtls_ecdh_compute_shared(&ecdh.grp, &z, &ecdh.Qp,
1072 &ecdh.d,
1073 myrand, NULL)));
Nicholas Wilson08f3ef12015-11-10 13:10:01 +00001074
Gilles Peskine1b6c09a2023-01-11 14:52:35 +01001075 mbedtls_ecdh_free(&ecdh);
1076 mbedtls_mpi_free(&z);
Manuel Pégourié-Gonnard85391f22015-02-05 09:54:48 +00001077 }
Manuel Pégourié-Gonnardcc34f952013-09-17 16:04:08 +02001078 }
1079#endif
Manuel Pégourié-Gonnard50da0482014-12-19 12:10:37 +01001080
Christoph M. Wintersteigere50b9702018-12-14 11:03:02 +00001081#if defined(MBEDTLS_ECDH_C)
Gilles Peskine1b6c09a2023-01-11 14:52:35 +01001082 if (todo.ecdh) {
Christoph M. Wintersteiger0bc9c692018-10-25 12:47:18 +01001083 mbedtls_ecdh_context ecdh_srv, ecdh_cli;
1084 unsigned char buf_srv[BUFSIZE], buf_cli[BUFSIZE];
Christoph M. Wintersteiger0bc9c692018-10-25 12:47:18 +01001085 const mbedtls_ecp_curve_info *curve_info;
1086 size_t olen;
1087
Gilles Peskine1b6c09a2023-01-11 14:52:35 +01001088 for (curve_info = curve_list;
1089 curve_info->grp_id != MBEDTLS_ECP_DP_NONE;
1090 curve_info++) {
1091 if (!mbedtls_ecdh_can_do(curve_info->grp_id)) {
Gilles Peskinec6c7c492019-02-11 18:41:27 +01001092 continue;
Gilles Peskine1b6c09a2023-01-11 14:52:35 +01001093 }
Gilles Peskinec6c7c492019-02-11 18:41:27 +01001094
Gilles Peskine1b6c09a2023-01-11 14:52:35 +01001095 mbedtls_ecdh_init(&ecdh_srv);
1096 mbedtls_ecdh_init(&ecdh_cli);
Christoph M. Wintersteiger0bc9c692018-10-25 12:47:18 +01001097
Gilles Peskine1b6c09a2023-01-11 14:52:35 +01001098 mbedtls_snprintf(title, sizeof(title), "ECDHE-%s", curve_info->name);
1099 TIME_PUBLIC(title,
1100 "full handshake",
1101 const unsigned char *p_srv = buf_srv;
Christoph M. Wintersteiger12f359f2019-02-26 12:26:04 +00001102
Gilles Peskine1b6c09a2023-01-11 14:52:35 +01001103 CHECK_AND_CONTINUE(mbedtls_ecdh_setup(&ecdh_srv, curve_info->grp_id));
1104 CHECK_AND_CONTINUE(mbedtls_ecdh_make_params(&ecdh_srv, &olen, buf_srv,
1105 sizeof(buf_srv), myrand, NULL));
Christoph M. Wintersteiger0bc9c692018-10-25 12:47:18 +01001106
Gilles Peskine1b6c09a2023-01-11 14:52:35 +01001107 CHECK_AND_CONTINUE(mbedtls_ecdh_read_params(&ecdh_cli, &p_srv,
1108 p_srv + olen));
1109 CHECK_AND_CONTINUE(mbedtls_ecdh_make_public(&ecdh_cli, &olen, buf_cli,
1110 sizeof(buf_cli), myrand, NULL));
Christoph M. Wintersteiger0bc9c692018-10-25 12:47:18 +01001111
Gilles Peskine1b6c09a2023-01-11 14:52:35 +01001112 CHECK_AND_CONTINUE(mbedtls_ecdh_read_public(&ecdh_srv, buf_cli, olen));
1113 CHECK_AND_CONTINUE(mbedtls_ecdh_calc_secret(&ecdh_srv, &olen, buf_srv,
1114 sizeof(buf_srv), myrand, NULL));
Christoph M. Wintersteiger0bc9c692018-10-25 12:47:18 +01001115
Gilles Peskine1b6c09a2023-01-11 14:52:35 +01001116 CHECK_AND_CONTINUE(mbedtls_ecdh_calc_secret(&ecdh_cli, &olen, buf_cli,
1117 sizeof(buf_cli), myrand, NULL));
1118 mbedtls_ecdh_free(&ecdh_cli);
Christoph M. Wintersteiger12f359f2019-02-26 12:26:04 +00001119
Gilles Peskine1b6c09a2023-01-11 14:52:35 +01001120 mbedtls_ecdh_free(&ecdh_srv);
1121 );
Christoph M. Wintersteiger0bc9c692018-10-25 12:47:18 +01001122
Christoph M. Wintersteiger0bc9c692018-10-25 12:47:18 +01001123 }
1124 }
1125#endif
1126
Gilles Peskine1b6c09a2023-01-11 14:52:35 +01001127 mbedtls_printf("\n");
Paul Bakker1d4da2e2009-10-25 12:36:53 +00001128
Manuel Pégourié-Gonnard2cf5a7c2015-04-08 12:49:31 +02001129#if defined(MBEDTLS_MEMORY_BUFFER_ALLOC_C)
1130 mbedtls_memory_buffer_alloc_free();
Manuel Pégourié-Gonnard128657d2014-12-18 16:35:52 +00001131#endif
1132
Paul Bakkercce9d772011-11-18 14:26:47 +00001133#if defined(_WIN32)
Gilles Peskine1b6c09a2023-01-11 14:52:35 +01001134 mbedtls_printf(" Press Enter to exit this program.\n");
1135 fflush(stdout); getchar();
Paul Bakker5121ce52009-01-03 21:22:43 +00001136#endif
1137
Gilles Peskine1b6c09a2023-01-11 14:52:35 +01001138 mbedtls_exit(0);
Paul Bakker5121ce52009-01-03 21:22:43 +00001139}
Manuel Pégourié-Gonnard8271f2f2013-09-17 14:57:55 +02001140
Manuel Pégourié-Gonnard2cf5a7c2015-04-08 12:49:31 +02001141#endif /* MBEDTLS_TIMING_C */