Paul Bakker | 5121ce5 | 2009-01-03 21:22:43 +0000 | [diff] [blame] | 1 | /* |
| 2 | * Benchmark demonstration program |
| 3 | * |
Simon Butcher | 549dc3d | 2016-10-05 14:14:19 +0100 | [diff] [blame] | 4 | * Copyright (C) 2006-2016, ARM Limited, All Rights Reserved |
Manuel Pégourié-Gonnard | 37ff140 | 2015-09-04 14:21:07 +0200 | [diff] [blame] | 5 | * 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 Bakker | b96f154 | 2010-07-18 20:36:00 +0000 | [diff] [blame] | 18 | * |
Manuel Pégourié-Gonnard | fe44643 | 2015-03-06 13:17:10 +0000 | [diff] [blame] | 19 | * This file is part of mbed TLS (https://tls.mbed.org) |
Paul Bakker | 5121ce5 | 2009-01-03 21:22:43 +0000 | [diff] [blame] | 20 | */ |
| 21 | |
Manuel Pégourié-Gonnard | 2cf5a7c | 2015-04-08 12:49:31 +0200 | [diff] [blame] | 22 | #if !defined(MBEDTLS_CONFIG_FILE) |
Manuel Pégourié-Gonnard | 7f80997 | 2015-03-09 17:05:11 +0000 | [diff] [blame] | 23 | #include "mbedtls/config.h" |
Manuel Pégourié-Gonnard | cef4ad2 | 2014-04-29 12:39:06 +0200 | [diff] [blame] | 24 | #else |
Manuel Pégourié-Gonnard | 2cf5a7c | 2015-04-08 12:49:31 +0200 | [diff] [blame] | 25 | #include MBEDTLS_CONFIG_FILE |
Manuel Pégourié-Gonnard | cef4ad2 | 2014-04-29 12:39:06 +0200 | [diff] [blame] | 26 | #endif |
Paul Bakker | 5121ce5 | 2009-01-03 21:22:43 +0000 | [diff] [blame] | 27 | |
Manuel Pégourié-Gonnard | 2cf5a7c | 2015-04-08 12:49:31 +0200 | [diff] [blame] | 28 | #if defined(MBEDTLS_PLATFORM_C) |
Manuel Pégourié-Gonnard | 7f80997 | 2015-03-09 17:05:11 +0000 | [diff] [blame] | 29 | #include "mbedtls/platform.h" |
Rich Evans | f90016a | 2015-01-19 14:26:37 +0000 | [diff] [blame] | 30 | #else |
Rich Evans | 18b78c7 | 2015-02-11 14:06:19 +0000 | [diff] [blame] | 31 | #include <stdio.h> |
Manuel Pégourié-Gonnard | 3ef6a6d | 2018-12-10 14:31:45 +0100 | [diff] [blame] | 32 | #include <stdlib.h> |
Manuel Pégourié-Gonnard | 2cf5a7c | 2015-04-08 12:49:31 +0200 | [diff] [blame] | 33 | #define mbedtls_exit exit |
| 34 | #define mbedtls_printf printf |
| 35 | #define mbedtls_snprintf snprintf |
| 36 | #define mbedtls_free free |
Manuel Pégourié-Gonnard | 3ef6a6d | 2018-12-10 14:31:45 +0100 | [diff] [blame] | 37 | #define mbedtls_exit exit |
| 38 | #define MBEDTLS_EXIT_SUCCESS EXIT_SUCCESS |
| 39 | #define MBEDTLS_EXIT_FAILURE EXIT_FAILURE |
Rich Evans | f90016a | 2015-01-19 14:26:37 +0000 | [diff] [blame] | 40 | #endif |
| 41 | |
Manuel Pégourié-Gonnard | 2cf5a7c | 2015-04-08 12:49:31 +0200 | [diff] [blame] | 42 | #if !defined(MBEDTLS_TIMING_C) |
Manuel Pégourié-Gonnard | 714929b | 2015-02-16 17:32:47 +0000 | [diff] [blame] | 43 | int main( void ) |
| 44 | { |
Manuel Pégourié-Gonnard | 2cf5a7c | 2015-04-08 12:49:31 +0200 | [diff] [blame] | 45 | mbedtls_printf("MBEDTLS_TIMING_C not defined.\n"); |
Manuel Pégourié-Gonnard | 714929b | 2015-02-16 17:32:47 +0000 | [diff] [blame] | 46 | return( 0 ); |
| 47 | } |
| 48 | #else |
Manuel Pégourié-Gonnard | 50da048 | 2014-12-19 12:10:37 +0100 | [diff] [blame] | 49 | |
Manuel Pégourié-Gonnard | 714929b | 2015-02-16 17:32:47 +0000 | [diff] [blame] | 50 | #include <string.h> |
Manuel Pégourié-Gonnard | 7551cb9 | 2015-05-26 16:04:06 +0200 | [diff] [blame] | 51 | #include <stdlib.h> |
Manuel Pégourié-Gonnard | 50da048 | 2014-12-19 12:10:37 +0100 | [diff] [blame] | 52 | |
Manuel Pégourié-Gonnard | 7f80997 | 2015-03-09 17:05:11 +0000 | [diff] [blame] | 53 | #include "mbedtls/timing.h" |
Paul Bakker | 5121ce5 | 2009-01-03 21:22:43 +0000 | [diff] [blame] | 54 | |
Manuel Pégourié-Gonnard | 7f80997 | 2015-03-09 17:05:11 +0000 | [diff] [blame] | 55 | #include "mbedtls/md4.h" |
| 56 | #include "mbedtls/md5.h" |
| 57 | #include "mbedtls/ripemd160.h" |
| 58 | #include "mbedtls/sha1.h" |
| 59 | #include "mbedtls/sha256.h" |
| 60 | #include "mbedtls/sha512.h" |
Manuel Pégourié-Gonnard | 62e813c | 2018-02-21 10:47:47 +0100 | [diff] [blame] | 61 | |
Manuel Pégourié-Gonnard | 7f80997 | 2015-03-09 17:05:11 +0000 | [diff] [blame] | 62 | #include "mbedtls/arc4.h" |
| 63 | #include "mbedtls/des.h" |
| 64 | #include "mbedtls/aes.h" |
Manuel Pégourié-Gonnard | 62e813c | 2018-02-21 10:47:47 +0100 | [diff] [blame] | 65 | #include "mbedtls/aria.h" |
Manuel Pégourié-Gonnard | 7f80997 | 2015-03-09 17:05:11 +0000 | [diff] [blame] | 66 | #include "mbedtls/blowfish.h" |
| 67 | #include "mbedtls/camellia.h" |
Daniel King | 34b822c | 2016-05-15 17:28:08 -0300 | [diff] [blame] | 68 | #include "mbedtls/chacha20.h" |
Manuel Pégourié-Gonnard | 7f80997 | 2015-03-09 17:05:11 +0000 | [diff] [blame] | 69 | #include "mbedtls/gcm.h" |
| 70 | #include "mbedtls/ccm.h" |
Manuel Pégourié-Gonnard | d6aea18 | 2018-05-09 10:21:28 +0200 | [diff] [blame] | 71 | #include "mbedtls/chachapoly.h" |
Simon Butcher | 549dc3d | 2016-10-05 14:14:19 +0100 | [diff] [blame] | 72 | #include "mbedtls/cmac.h" |
Daniel King | adc32c0 | 2016-05-16 18:25:45 -0300 | [diff] [blame] | 73 | #include "mbedtls/poly1305.h" |
Manuel Pégourié-Gonnard | 62e813c | 2018-02-21 10:47:47 +0100 | [diff] [blame] | 74 | |
Manuel Pégourié-Gonnard | 7f80997 | 2015-03-09 17:05:11 +0000 | [diff] [blame] | 75 | #include "mbedtls/havege.h" |
| 76 | #include "mbedtls/ctr_drbg.h" |
| 77 | #include "mbedtls/hmac_drbg.h" |
Manuel Pégourié-Gonnard | 62e813c | 2018-02-21 10:47:47 +0100 | [diff] [blame] | 78 | |
Manuel Pégourié-Gonnard | 7f80997 | 2015-03-09 17:05:11 +0000 | [diff] [blame] | 79 | #include "mbedtls/rsa.h" |
| 80 | #include "mbedtls/dhm.h" |
| 81 | #include "mbedtls/ecdsa.h" |
| 82 | #include "mbedtls/ecdh.h" |
Manuel Pégourié-Gonnard | 62e813c | 2018-02-21 10:47:47 +0100 | [diff] [blame] | 83 | |
Manuel Pégourié-Gonnard | 7f80997 | 2015-03-09 17:05:11 +0000 | [diff] [blame] | 84 | #include "mbedtls/error.h" |
Paul Bakker | 5121ce5 | 2009-01-03 21:22:43 +0000 | [diff] [blame] | 85 | |
Manuel Pégourié-Gonnard | 2cf5a7c | 2015-04-08 12:49:31 +0200 | [diff] [blame] | 86 | #if defined(MBEDTLS_MEMORY_BUFFER_ALLOC_C) |
Manuel Pégourié-Gonnard | 7f80997 | 2015-03-09 17:05:11 +0000 | [diff] [blame] | 87 | #include "mbedtls/memory_buffer_alloc.h" |
Rich Evans | 18b78c7 | 2015-02-11 14:06:19 +0000 | [diff] [blame] | 88 | #endif |
| 89 | |
Manuel Pégourié-Gonnard | 714929b | 2015-02-16 17:32:47 +0000 | [diff] [blame] | 90 | /* |
| 91 | * For heap usage estimates, we need an estimate of the overhead per allocated |
| 92 | * block. ptmalloc2/3 (used in gnu libc for instance) uses 2 size_t per block, |
| 93 | * so use that as our baseline. |
| 94 | */ |
| 95 | #define MEM_BLOCK_OVERHEAD ( 2 * sizeof( size_t ) ) |
| 96 | |
| 97 | /* |
Manuel Pégourié-Gonnard | b2a18a2 | 2015-05-27 16:29:56 +0200 | [diff] [blame] | 98 | * Size to use for the alloc buffer if MEMORY_BUFFER_ALLOC_C is defined. |
Manuel Pégourié-Gonnard | 714929b | 2015-02-16 17:32:47 +0000 | [diff] [blame] | 99 | */ |
Christoph M. Wintersteiger | 696deda | 2018-10-25 12:47:18 +0100 | [diff] [blame] | 100 | #define HEAP_SIZE (1u << 16) /* 64k */ |
Manuel Pégourié-Gonnard | 714929b | 2015-02-16 17:32:47 +0000 | [diff] [blame] | 101 | |
Paul Bakker | 02faf45 | 2011-11-29 11:23:58 +0000 | [diff] [blame] | 102 | #define BUFSIZE 1024 |
Manuel Pégourié-Gonnard | fef0f8f | 2014-01-30 20:59:00 +0100 | [diff] [blame] | 103 | #define HEADER_FORMAT " %-24s : " |
Gergely Budai | a5d336b | 2014-01-27 23:27:06 +0100 | [diff] [blame] | 104 | #define TITLE_LEN 25 |
Manuel Pégourié-Gonnard | 6c5abfa | 2015-02-13 14:12:07 +0000 | [diff] [blame] | 105 | |
Rich Evans | 85b05ec | 2015-02-12 11:37:29 +0000 | [diff] [blame] | 106 | #define OPTIONS \ |
Manuel Pégourié-Gonnard | e85fef1 | 2015-05-11 19:21:39 +0200 | [diff] [blame] | 107 | "md4, md5, ripemd160, sha1, sha256, sha512,\n" \ |
Daniel King | 34b822c | 2016-05-15 17:28:08 -0300 | [diff] [blame] | 108 | "arc4, des3, des, camellia, blowfish, chacha20,\n" \ |
Manuel Pégourié-Gonnard | 0dadba2 | 2018-06-19 11:11:15 +0200 | [diff] [blame] | 109 | "aes_cbc, aes_gcm, aes_ccm, aes_ctx, chachapoly,\n" \ |
Daniel King | adc32c0 | 2016-05-16 18:25:45 -0300 | [diff] [blame] | 110 | "aes_cmac, des3_cmac, poly1305\n" \ |
Rich Evans | 85b05ec | 2015-02-12 11:37:29 +0000 | [diff] [blame] | 111 | "havege, ctr_drbg, hmac_drbg\n" \ |
| 112 | "rsa, dhm, ecdsa, ecdh.\n" |
| 113 | |
Manuel Pégourié-Gonnard | 2cf5a7c | 2015-04-08 12:49:31 +0200 | [diff] [blame] | 114 | #if defined(MBEDTLS_ERROR_C) |
Rich Evans | 85b05ec | 2015-02-12 11:37:29 +0000 | [diff] [blame] | 115 | #define PRINT_ERROR \ |
Simon Butcher | b981b16 | 2016-10-06 10:27:22 +0100 | [diff] [blame] | 116 | mbedtls_strerror( ret, ( char * )tmp, sizeof( tmp ) ); \ |
Manuel Pégourié-Gonnard | 2cf5a7c | 2015-04-08 12:49:31 +0200 | [diff] [blame] | 117 | mbedtls_printf( "FAILED: %s\n", tmp ); |
Rich Evans | 85b05ec | 2015-02-12 11:37:29 +0000 | [diff] [blame] | 118 | #else |
| 119 | #define PRINT_ERROR \ |
Manuel Pégourié-Gonnard | 2cf5a7c | 2015-04-08 12:49:31 +0200 | [diff] [blame] | 120 | mbedtls_printf( "FAILED: -0x%04x\n", -ret ); |
Rich Evans | 85b05ec | 2015-02-12 11:37:29 +0000 | [diff] [blame] | 121 | #endif |
| 122 | |
| 123 | #define TIME_AND_TSC( TITLE, CODE ) \ |
| 124 | do { \ |
Manuel Pégourié-Gonnard | ea35666 | 2015-08-27 12:02:40 +0200 | [diff] [blame] | 125 | unsigned long ii, jj, tsc; \ |
Manuel Pégourié-Gonnard | 51d7cfe | 2018-06-25 11:19:51 +0200 | [diff] [blame] | 126 | int ret = 0; \ |
Rich Evans | 85b05ec | 2015-02-12 11:37:29 +0000 | [diff] [blame] | 127 | \ |
Manuel Pégourié-Gonnard | ea35666 | 2015-08-27 12:02:40 +0200 | [diff] [blame] | 128 | mbedtls_printf( HEADER_FORMAT, TITLE ); \ |
Rich Evans | 85b05ec | 2015-02-12 11:37:29 +0000 | [diff] [blame] | 129 | fflush( stdout ); \ |
| 130 | \ |
Manuel Pégourié-Gonnard | ea35666 | 2015-08-27 12:02:40 +0200 | [diff] [blame] | 131 | mbedtls_set_alarm( 1 ); \ |
Manuel Pégourié-Gonnard | 51d7cfe | 2018-06-25 11:19:51 +0200 | [diff] [blame] | 132 | for( ii = 1; ret == 0 && ! mbedtls_timing_alarmed; ii++ ) \ |
Rich Evans | 85b05ec | 2015-02-12 11:37:29 +0000 | [diff] [blame] | 133 | { \ |
Manuel Pégourié-Gonnard | 51d7cfe | 2018-06-25 11:19:51 +0200 | [diff] [blame] | 134 | ret = CODE; \ |
Rich Evans | 85b05ec | 2015-02-12 11:37:29 +0000 | [diff] [blame] | 135 | } \ |
| 136 | \ |
Manuel Pégourié-Gonnard | ea35666 | 2015-08-27 12:02:40 +0200 | [diff] [blame] | 137 | tsc = mbedtls_timing_hardclock(); \ |
Manuel Pégourié-Gonnard | 51d7cfe | 2018-06-25 11:19:51 +0200 | [diff] [blame] | 138 | for( jj = 0; ret == 0 && jj < 1024; jj++ ) \ |
Rich Evans | 85b05ec | 2015-02-12 11:37:29 +0000 | [diff] [blame] | 139 | { \ |
Manuel Pégourié-Gonnard | 51d7cfe | 2018-06-25 11:19:51 +0200 | [diff] [blame] | 140 | ret = CODE; \ |
Rich Evans | 85b05ec | 2015-02-12 11:37:29 +0000 | [diff] [blame] | 141 | } \ |
| 142 | \ |
Manuel Pégourié-Gonnard | 51d7cfe | 2018-06-25 11:19:51 +0200 | [diff] [blame] | 143 | if( ret != 0 ) \ |
| 144 | { \ |
| 145 | PRINT_ERROR; \ |
| 146 | } \ |
| 147 | else \ |
| 148 | { \ |
| 149 | mbedtls_printf( "%9lu KiB/s, %9lu cycles/byte\n", \ |
| 150 | ii * BUFSIZE / 1024, \ |
| 151 | ( mbedtls_timing_hardclock() - tsc ) \ |
| 152 | / ( jj * BUFSIZE ) ); \ |
| 153 | } \ |
Rich Evans | 85b05ec | 2015-02-12 11:37:29 +0000 | [diff] [blame] | 154 | } while( 0 ) |
| 155 | |
Manuel Pégourié-Gonnard | 2cf5a7c | 2015-04-08 12:49:31 +0200 | [diff] [blame] | 156 | #if defined(MBEDTLS_MEMORY_BUFFER_ALLOC_C) && defined(MBEDTLS_MEMORY_DEBUG) |
Manuel Pégourié-Gonnard | 50da048 | 2014-12-19 12:10:37 +0100 | [diff] [blame] | 157 | |
| 158 | #define MEMORY_MEASURE_INIT \ |
| 159 | size_t max_used, max_blocks, max_bytes; \ |
| 160 | size_t prv_used, prv_blocks; \ |
Manuel Pégourié-Gonnard | ea35666 | 2015-08-27 12:02:40 +0200 | [diff] [blame] | 161 | mbedtls_memory_buffer_alloc_cur_get( &prv_used, &prv_blocks ); \ |
Manuel Pégourié-Gonnard | 2cf5a7c | 2015-04-08 12:49:31 +0200 | [diff] [blame] | 162 | mbedtls_memory_buffer_alloc_max_reset( ); |
Manuel Pégourié-Gonnard | 50da048 | 2014-12-19 12:10:37 +0100 | [diff] [blame] | 163 | |
| 164 | #define MEMORY_MEASURE_PRINT( title_len ) \ |
Manuel Pégourié-Gonnard | ea35666 | 2015-08-27 12:02:40 +0200 | [diff] [blame] | 165 | mbedtls_memory_buffer_alloc_max_get( &max_used, &max_blocks ); \ |
Hanno Becker | 1eeca41 | 2018-10-15 12:01:35 +0100 | [diff] [blame] | 166 | for( ii = 12 - (title_len); ii != 0; ii-- ) mbedtls_printf( " " ); \ |
Manuel Pégourié-Gonnard | 50da048 | 2014-12-19 12:10:37 +0100 | [diff] [blame] | 167 | max_used -= prv_used; \ |
| 168 | max_blocks -= prv_blocks; \ |
| 169 | max_bytes = max_used + MEM_BLOCK_OVERHEAD * max_blocks; \ |
Manuel Pégourié-Gonnard | 2cf5a7c | 2015-04-08 12:49:31 +0200 | [diff] [blame] | 170 | mbedtls_printf( "%6u heap bytes", (unsigned) max_bytes ); |
Manuel Pégourié-Gonnard | 50da048 | 2014-12-19 12:10:37 +0100 | [diff] [blame] | 171 | |
| 172 | #else |
Manuel Pégourié-Gonnard | e579dab | 2015-01-29 16:28:44 +0000 | [diff] [blame] | 173 | #define MEMORY_MEASURE_INIT |
| 174 | #define MEMORY_MEASURE_PRINT( title_len ) |
Manuel Pégourié-Gonnard | 50da048 | 2014-12-19 12:10:37 +0100 | [diff] [blame] | 175 | #endif |
| 176 | |
Rich Evans | 85b05ec | 2015-02-12 11:37:29 +0000 | [diff] [blame] | 177 | #define TIME_PUBLIC( TITLE, TYPE, CODE ) \ |
| 178 | do { \ |
Manuel Pégourié-Gonnard | ea35666 | 2015-08-27 12:02:40 +0200 | [diff] [blame] | 179 | unsigned long ii; \ |
Rich Evans | 85b05ec | 2015-02-12 11:37:29 +0000 | [diff] [blame] | 180 | int ret; \ |
Manuel Pégourié-Gonnard | 50da048 | 2014-12-19 12:10:37 +0100 | [diff] [blame] | 181 | MEMORY_MEASURE_INIT; \ |
Rich Evans | 85b05ec | 2015-02-12 11:37:29 +0000 | [diff] [blame] | 182 | \ |
Manuel Pégourié-Gonnard | ea35666 | 2015-08-27 12:02:40 +0200 | [diff] [blame] | 183 | mbedtls_printf( HEADER_FORMAT, TITLE ); \ |
Rich Evans | 85b05ec | 2015-02-12 11:37:29 +0000 | [diff] [blame] | 184 | fflush( stdout ); \ |
Manuel Pégourié-Gonnard | ea35666 | 2015-08-27 12:02:40 +0200 | [diff] [blame] | 185 | mbedtls_set_alarm( 3 ); \ |
Rich Evans | 85b05ec | 2015-02-12 11:37:29 +0000 | [diff] [blame] | 186 | \ |
| 187 | ret = 0; \ |
Manuel Pégourié-Gonnard | ea35666 | 2015-08-27 12:02:40 +0200 | [diff] [blame] | 188 | for( ii = 1; ! mbedtls_timing_alarmed && ! ret ; ii++ ) \ |
Rich Evans | 85b05ec | 2015-02-12 11:37:29 +0000 | [diff] [blame] | 189 | { \ |
| 190 | CODE; \ |
| 191 | } \ |
| 192 | \ |
| 193 | if( ret != 0 ) \ |
| 194 | { \ |
Manuel Pégourié-Gonnard | 50da048 | 2014-12-19 12:10:37 +0100 | [diff] [blame] | 195 | PRINT_ERROR; \ |
Rich Evans | 85b05ec | 2015-02-12 11:37:29 +0000 | [diff] [blame] | 196 | } \ |
| 197 | else \ |
Manuel Pégourié-Gonnard | 50da048 | 2014-12-19 12:10:37 +0100 | [diff] [blame] | 198 | { \ |
Manuel Pégourié-Gonnard | ea35666 | 2015-08-27 12:02:40 +0200 | [diff] [blame] | 199 | mbedtls_printf( "%6lu " TYPE "/s", ii / 3 ); \ |
Manuel Pégourié-Gonnard | 50da048 | 2014-12-19 12:10:37 +0100 | [diff] [blame] | 200 | MEMORY_MEASURE_PRINT( sizeof( TYPE ) + 1 ); \ |
Manuel Pégourié-Gonnard | ea35666 | 2015-08-27 12:02:40 +0200 | [diff] [blame] | 201 | mbedtls_printf( "\n" ); \ |
Manuel Pégourié-Gonnard | 50da048 | 2014-12-19 12:10:37 +0100 | [diff] [blame] | 202 | } \ |
Rich Evans | 85b05ec | 2015-02-12 11:37:29 +0000 | [diff] [blame] | 203 | } while( 0 ) |
Paul Bakker | 5121ce5 | 2009-01-03 21:22:43 +0000 | [diff] [blame] | 204 | |
Paul Bakker | a3d195c | 2011-11-27 21:07:34 +0000 | [diff] [blame] | 205 | static int myrand( void *rng_state, unsigned char *output, size_t len ) |
Paul Bakker | 5121ce5 | 2009-01-03 21:22:43 +0000 | [diff] [blame] | 206 | { |
Paul Bakker | a3d195c | 2011-11-27 21:07:34 +0000 | [diff] [blame] | 207 | size_t use_len; |
| 208 | int rnd; |
| 209 | |
Paul Bakker | 5121ce5 | 2009-01-03 21:22:43 +0000 | [diff] [blame] | 210 | if( rng_state != NULL ) |
| 211 | rng_state = NULL; |
| 212 | |
Paul Bakker | a3d195c | 2011-11-27 21:07:34 +0000 | [diff] [blame] | 213 | while( len > 0 ) |
| 214 | { |
| 215 | use_len = len; |
| 216 | if( use_len > sizeof(int) ) |
| 217 | use_len = sizeof(int); |
| 218 | |
| 219 | rnd = rand(); |
| 220 | memcpy( output, &rnd, use_len ); |
| 221 | output += use_len; |
| 222 | len -= use_len; |
| 223 | } |
| 224 | |
| 225 | return( 0 ); |
Paul Bakker | 5121ce5 | 2009-01-03 21:22:43 +0000 | [diff] [blame] | 226 | } |
| 227 | |
Christoph M. Wintersteiger | 3c44962 | 2018-12-14 11:54:59 +0000 | [diff] [blame^] | 228 | #if defined(MBEDTLS_ECDH_C) |
| 229 | static void check( int r ) |
| 230 | { |
| 231 | if( r != 0 ) |
| 232 | mbedtls_exit( 1 ); |
| 233 | } |
| 234 | #endif |
| 235 | |
Manuel Pégourié-Gonnard | 50da048 | 2014-12-19 12:10:37 +0100 | [diff] [blame] | 236 | /* |
| 237 | * Clear some memory that was used to prepare the context |
| 238 | */ |
Manuel Pégourié-Gonnard | 2cf5a7c | 2015-04-08 12:49:31 +0200 | [diff] [blame] | 239 | #if defined(MBEDTLS_ECP_C) |
| 240 | void ecp_clear_precomputed( mbedtls_ecp_group *grp ) |
Manuel Pégourié-Gonnard | 50da048 | 2014-12-19 12:10:37 +0100 | [diff] [blame] | 241 | { |
| 242 | if( grp->T != NULL ) |
| 243 | { |
| 244 | size_t i; |
| 245 | for( i = 0; i < grp->T_size; i++ ) |
Manuel Pégourié-Gonnard | 2cf5a7c | 2015-04-08 12:49:31 +0200 | [diff] [blame] | 246 | mbedtls_ecp_point_free( &grp->T[i] ); |
| 247 | mbedtls_free( grp->T ); |
Manuel Pégourié-Gonnard | 50da048 | 2014-12-19 12:10:37 +0100 | [diff] [blame] | 248 | } |
| 249 | grp->T = NULL; |
| 250 | grp->T_size = 0; |
| 251 | } |
| 252 | #else |
| 253 | #define ecp_clear_precomputed( g ) |
| 254 | #endif |
| 255 | |
Paul Bakker | 5121ce5 | 2009-01-03 21:22:43 +0000 | [diff] [blame] | 256 | unsigned char buf[BUFSIZE]; |
| 257 | |
Manuel Pégourié-Gonnard | ed7cbe9 | 2013-09-17 15:30:51 +0200 | [diff] [blame] | 258 | typedef struct { |
Manuel Pégourié-Gonnard | e85fef1 | 2015-05-11 19:21:39 +0200 | [diff] [blame] | 259 | char md4, md5, ripemd160, sha1, sha256, sha512, |
Simon Butcher | 549dc3d | 2016-10-05 14:14:19 +0100 | [diff] [blame] | 260 | arc4, des3, des, |
Manuel Pégourié-Gonnard | 0dadba2 | 2018-06-19 11:11:15 +0200 | [diff] [blame] | 261 | aes_cbc, aes_gcm, aes_ccm, aes_xts, chachapoly, |
Manuel Pégourié-Gonnard | d6aea18 | 2018-05-09 10:21:28 +0200 | [diff] [blame] | 262 | aes_cmac, des3_cmac, |
Manuel Pégourié-Gonnard | 39b1904 | 2018-06-07 12:01:33 +0200 | [diff] [blame] | 263 | aria, camellia, blowfish, chacha20, |
Daniel King | adc32c0 | 2016-05-16 18:25:45 -0300 | [diff] [blame] | 264 | poly1305, |
Manuel Pégourié-Gonnard | fef0f8f | 2014-01-30 20:59:00 +0100 | [diff] [blame] | 265 | havege, ctr_drbg, hmac_drbg, |
Manuel Pégourié-Gonnard | cc34f95 | 2013-09-17 16:04:08 +0200 | [diff] [blame] | 266 | rsa, dhm, ecdsa, ecdh; |
Manuel Pégourié-Gonnard | ed7cbe9 | 2013-09-17 15:30:51 +0200 | [diff] [blame] | 267 | } todo_list; |
| 268 | |
Simon Butcher | 63cb97e | 2018-12-06 17:43:31 +0000 | [diff] [blame] | 269 | |
Paul Bakker | cce9d77 | 2011-11-18 14:26:47 +0000 | [diff] [blame] | 270 | int main( int argc, char *argv[] ) |
Paul Bakker | 5690efc | 2011-05-26 13:16:06 +0000 | [diff] [blame] | 271 | { |
Manuel Pégourié-Gonnard | 71e75dc | 2014-12-19 18:05:43 +0100 | [diff] [blame] | 272 | int i; |
Manuel Pégourié-Gonnard | cc34f95 | 2013-09-17 16:04:08 +0200 | [diff] [blame] | 273 | unsigned char tmp[200]; |
Manuel Pégourié-Gonnard | 8271f2f | 2013-09-17 14:57:55 +0200 | [diff] [blame] | 274 | char title[TITLE_LEN]; |
Manuel Pégourié-Gonnard | ed7cbe9 | 2013-09-17 15:30:51 +0200 | [diff] [blame] | 275 | todo_list todo; |
Manuel Pégourié-Gonnard | 2cf5a7c | 2015-04-08 12:49:31 +0200 | [diff] [blame] | 276 | #if defined(MBEDTLS_MEMORY_BUFFER_ALLOC_C) |
Manuel Pégourié-Gonnard | b2a18a2 | 2015-05-27 16:29:56 +0200 | [diff] [blame] | 277 | unsigned char alloc_buf[HEAP_SIZE] = { 0 }; |
Manuel Pégourié-Gonnard | 128657d | 2014-12-18 16:35:52 +0000 | [diff] [blame] | 278 | #endif |
Paul Bakker | cce9d77 | 2011-11-18 14:26:47 +0000 | [diff] [blame] | 279 | |
Manuel Pégourié-Gonnard | c439e7b | 2015-03-03 13:12:00 +0000 | [diff] [blame] | 280 | if( argc <= 1 ) |
| 281 | { |
Manuel Pégourié-Gonnard | ed7cbe9 | 2013-09-17 15:30:51 +0200 | [diff] [blame] | 282 | memset( &todo, 1, sizeof( todo ) ); |
Manuel Pégourié-Gonnard | c439e7b | 2015-03-03 13:12:00 +0000 | [diff] [blame] | 283 | } |
Manuel Pégourié-Gonnard | ed7cbe9 | 2013-09-17 15:30:51 +0200 | [diff] [blame] | 284 | else |
| 285 | { |
| 286 | memset( &todo, 0, sizeof( todo ) ); |
| 287 | |
| 288 | for( i = 1; i < argc; i++ ) |
| 289 | { |
Manuel Pégourié-Gonnard | e85fef1 | 2015-05-11 19:21:39 +0200 | [diff] [blame] | 290 | if( strcmp( argv[i], "md4" ) == 0 ) |
| 291 | todo.md4 = 1; |
| 292 | else if( strcmp( argv[i], "md5" ) == 0 ) |
| 293 | todo.md5 = 1; |
| 294 | else if( strcmp( argv[i], "ripemd160" ) == 0 ) |
| 295 | todo.ripemd160 = 1; |
| 296 | else if( strcmp( argv[i], "sha1" ) == 0 ) |
| 297 | todo.sha1 = 1; |
| 298 | else if( strcmp( argv[i], "sha256" ) == 0 ) |
| 299 | todo.sha256 = 1; |
| 300 | else if( strcmp( argv[i], "sha512" ) == 0 ) |
| 301 | todo.sha512 = 1; |
Manuel Pégourié-Gonnard | ed7cbe9 | 2013-09-17 15:30:51 +0200 | [diff] [blame] | 302 | else if( strcmp( argv[i], "arc4" ) == 0 ) |
| 303 | todo.arc4 = 1; |
| 304 | else if( strcmp( argv[i], "des3" ) == 0 ) |
| 305 | todo.des3 = 1; |
| 306 | else if( strcmp( argv[i], "des" ) == 0 ) |
| 307 | todo.des = 1; |
| 308 | else if( strcmp( argv[i], "aes_cbc" ) == 0 ) |
| 309 | todo.aes_cbc = 1; |
Aorimn | 5f77801 | 2016-06-09 23:22:58 +0200 | [diff] [blame] | 310 | else if( strcmp( argv[i], "aes_xts" ) == 0 ) |
| 311 | todo.aes_xts = 1; |
Manuel Pégourié-Gonnard | ed7cbe9 | 2013-09-17 15:30:51 +0200 | [diff] [blame] | 312 | else if( strcmp( argv[i], "aes_gcm" ) == 0 ) |
| 313 | todo.aes_gcm = 1; |
Manuel Pégourié-Gonnard | 58d78a8 | 2014-05-07 12:03:02 +0200 | [diff] [blame] | 314 | else if( strcmp( argv[i], "aes_ccm" ) == 0 ) |
| 315 | todo.aes_ccm = 1; |
Manuel Pégourié-Gonnard | d6aea18 | 2018-05-09 10:21:28 +0200 | [diff] [blame] | 316 | else if( strcmp( argv[i], "chachapoly" ) == 0 ) |
| 317 | todo.chachapoly = 1; |
Simon Butcher | 549dc3d | 2016-10-05 14:14:19 +0100 | [diff] [blame] | 318 | else if( strcmp( argv[i], "aes_cmac" ) == 0 ) |
| 319 | todo.aes_cmac = 1; |
| 320 | else if( strcmp( argv[i], "des3_cmac" ) == 0 ) |
| 321 | todo.des3_cmac = 1; |
Manuel Pégourié-Gonnard | 62e813c | 2018-02-21 10:47:47 +0100 | [diff] [blame] | 322 | else if( strcmp( argv[i], "aria" ) == 0 ) |
| 323 | todo.aria = 1; |
Manuel Pégourié-Gonnard | ed7cbe9 | 2013-09-17 15:30:51 +0200 | [diff] [blame] | 324 | else if( strcmp( argv[i], "camellia" ) == 0 ) |
| 325 | todo.camellia = 1; |
| 326 | else if( strcmp( argv[i], "blowfish" ) == 0 ) |
| 327 | todo.blowfish = 1; |
Daniel King | 34b822c | 2016-05-15 17:28:08 -0300 | [diff] [blame] | 328 | else if( strcmp( argv[i], "chacha20" ) == 0 ) |
| 329 | todo.chacha20 = 1; |
Daniel King | adc32c0 | 2016-05-16 18:25:45 -0300 | [diff] [blame] | 330 | else if( strcmp( argv[i], "poly1305" ) == 0 ) |
| 331 | todo.poly1305 = 1; |
Manuel Pégourié-Gonnard | ed7cbe9 | 2013-09-17 15:30:51 +0200 | [diff] [blame] | 332 | else if( strcmp( argv[i], "havege" ) == 0 ) |
| 333 | todo.havege = 1; |
| 334 | else if( strcmp( argv[i], "ctr_drbg" ) == 0 ) |
| 335 | todo.ctr_drbg = 1; |
Manuel Pégourié-Gonnard | fef0f8f | 2014-01-30 20:59:00 +0100 | [diff] [blame] | 336 | else if( strcmp( argv[i], "hmac_drbg" ) == 0 ) |
| 337 | todo.hmac_drbg = 1; |
Manuel Pégourié-Gonnard | ed7cbe9 | 2013-09-17 15:30:51 +0200 | [diff] [blame] | 338 | else if( strcmp( argv[i], "rsa" ) == 0 ) |
| 339 | todo.rsa = 1; |
| 340 | else if( strcmp( argv[i], "dhm" ) == 0 ) |
| 341 | todo.dhm = 1; |
Manuel Pégourié-Gonnard | cc34f95 | 2013-09-17 16:04:08 +0200 | [diff] [blame] | 342 | else if( strcmp( argv[i], "ecdsa" ) == 0 ) |
| 343 | todo.ecdsa = 1; |
| 344 | else if( strcmp( argv[i], "ecdh" ) == 0 ) |
| 345 | todo.ecdh = 1; |
Manuel Pégourié-Gonnard | ed7cbe9 | 2013-09-17 15:30:51 +0200 | [diff] [blame] | 346 | else |
| 347 | { |
Manuel Pégourié-Gonnard | 2cf5a7c | 2015-04-08 12:49:31 +0200 | [diff] [blame] | 348 | mbedtls_printf( "Unrecognized option: %s\n", argv[i] ); |
| 349 | mbedtls_printf( "Available options: " OPTIONS ); |
Manuel Pégourié-Gonnard | ed7cbe9 | 2013-09-17 15:30:51 +0200 | [diff] [blame] | 350 | } |
| 351 | } |
| 352 | } |
Paul Bakker | 5121ce5 | 2009-01-03 21:22:43 +0000 | [diff] [blame] | 353 | |
Manuel Pégourié-Gonnard | 2cf5a7c | 2015-04-08 12:49:31 +0200 | [diff] [blame] | 354 | mbedtls_printf( "\n" ); |
Paul Bakker | 5121ce5 | 2009-01-03 21:22:43 +0000 | [diff] [blame] | 355 | |
Manuel Pégourié-Gonnard | 2cf5a7c | 2015-04-08 12:49:31 +0200 | [diff] [blame] | 356 | #if defined(MBEDTLS_MEMORY_BUFFER_ALLOC_C) |
Manuel Pégourié-Gonnard | b2a18a2 | 2015-05-27 16:29:56 +0200 | [diff] [blame] | 357 | mbedtls_memory_buffer_alloc_init( alloc_buf, sizeof( alloc_buf ) ); |
Manuel Pégourié-Gonnard | 128657d | 2014-12-18 16:35:52 +0000 | [diff] [blame] | 358 | #endif |
Manuel Pégourié-Gonnard | ed7cbe9 | 2013-09-17 15:30:51 +0200 | [diff] [blame] | 359 | memset( buf, 0xAA, sizeof( buf ) ); |
Paul Bakker | df71dd1 | 2014-04-17 16:03:48 +0200 | [diff] [blame] | 360 | memset( tmp, 0xBB, sizeof( tmp ) ); |
Manuel Pégourié-Gonnard | ed7cbe9 | 2013-09-17 15:30:51 +0200 | [diff] [blame] | 361 | |
Manuel Pégourié-Gonnard | 2cf5a7c | 2015-04-08 12:49:31 +0200 | [diff] [blame] | 362 | #if defined(MBEDTLS_MD4_C) |
Manuel Pégourié-Gonnard | e85fef1 | 2015-05-11 19:21:39 +0200 | [diff] [blame] | 363 | if( todo.md4 ) |
Gilles Peskine | 9e4f77c | 2018-01-22 11:48:08 +0100 | [diff] [blame] | 364 | TIME_AND_TSC( "MD4", mbedtls_md4_ret( buf, BUFSIZE, tmp ) ); |
Paul Bakker | 5121ce5 | 2009-01-03 21:22:43 +0000 | [diff] [blame] | 365 | #endif |
| 366 | |
Manuel Pégourié-Gonnard | 2cf5a7c | 2015-04-08 12:49:31 +0200 | [diff] [blame] | 367 | #if defined(MBEDTLS_MD5_C) |
Manuel Pégourié-Gonnard | e85fef1 | 2015-05-11 19:21:39 +0200 | [diff] [blame] | 368 | if( todo.md5 ) |
Gilles Peskine | 9e4f77c | 2018-01-22 11:48:08 +0100 | [diff] [blame] | 369 | TIME_AND_TSC( "MD5", mbedtls_md5_ret( buf, BUFSIZE, tmp ) ); |
Paul Bakker | 5121ce5 | 2009-01-03 21:22:43 +0000 | [diff] [blame] | 370 | #endif |
| 371 | |
Manuel Pégourié-Gonnard | 2cf5a7c | 2015-04-08 12:49:31 +0200 | [diff] [blame] | 372 | #if defined(MBEDTLS_RIPEMD160_C) |
Manuel Pégourié-Gonnard | e85fef1 | 2015-05-11 19:21:39 +0200 | [diff] [blame] | 373 | if( todo.ripemd160 ) |
Gilles Peskine | 9e4f77c | 2018-01-22 11:48:08 +0100 | [diff] [blame] | 374 | TIME_AND_TSC( "RIPEMD160", mbedtls_ripemd160_ret( buf, BUFSIZE, tmp ) ); |
Manuel Pégourié-Gonnard | 01b0b38 | 2014-01-17 14:29:46 +0100 | [diff] [blame] | 375 | #endif |
| 376 | |
Manuel Pégourié-Gonnard | 2cf5a7c | 2015-04-08 12:49:31 +0200 | [diff] [blame] | 377 | #if defined(MBEDTLS_SHA1_C) |
Manuel Pégourié-Gonnard | e85fef1 | 2015-05-11 19:21:39 +0200 | [diff] [blame] | 378 | if( todo.sha1 ) |
Gilles Peskine | 9e4f77c | 2018-01-22 11:48:08 +0100 | [diff] [blame] | 379 | TIME_AND_TSC( "SHA-1", mbedtls_sha1_ret( buf, BUFSIZE, tmp ) ); |
Paul Bakker | 5121ce5 | 2009-01-03 21:22:43 +0000 | [diff] [blame] | 380 | #endif |
| 381 | |
Manuel Pégourié-Gonnard | 2cf5a7c | 2015-04-08 12:49:31 +0200 | [diff] [blame] | 382 | #if defined(MBEDTLS_SHA256_C) |
Manuel Pégourié-Gonnard | e85fef1 | 2015-05-11 19:21:39 +0200 | [diff] [blame] | 383 | if( todo.sha256 ) |
Gilles Peskine | 9e4f77c | 2018-01-22 11:48:08 +0100 | [diff] [blame] | 384 | TIME_AND_TSC( "SHA-256", mbedtls_sha256_ret( buf, BUFSIZE, tmp, 0 ) ); |
Paul Bakker | 5121ce5 | 2009-01-03 21:22:43 +0000 | [diff] [blame] | 385 | #endif |
| 386 | |
Manuel Pégourié-Gonnard | 2cf5a7c | 2015-04-08 12:49:31 +0200 | [diff] [blame] | 387 | #if defined(MBEDTLS_SHA512_C) |
Manuel Pégourié-Gonnard | e85fef1 | 2015-05-11 19:21:39 +0200 | [diff] [blame] | 388 | if( todo.sha512 ) |
Gilles Peskine | 9e4f77c | 2018-01-22 11:48:08 +0100 | [diff] [blame] | 389 | TIME_AND_TSC( "SHA-512", mbedtls_sha512_ret( buf, BUFSIZE, tmp, 0 ) ); |
Paul Bakker | 3a3c3c2 | 2009-02-09 22:33:30 +0000 | [diff] [blame] | 390 | #endif |
| 391 | |
Manuel Pégourié-Gonnard | 2cf5a7c | 2015-04-08 12:49:31 +0200 | [diff] [blame] | 392 | #if defined(MBEDTLS_ARC4_C) |
Manuel Pégourié-Gonnard | ed7cbe9 | 2013-09-17 15:30:51 +0200 | [diff] [blame] | 393 | if( todo.arc4 ) |
Manuel Pégourié-Gonnard | 8271f2f | 2013-09-17 14:57:55 +0200 | [diff] [blame] | 394 | { |
Manuel Pégourié-Gonnard | 2cf5a7c | 2015-04-08 12:49:31 +0200 | [diff] [blame] | 395 | mbedtls_arc4_context arc4; |
| 396 | mbedtls_arc4_init( &arc4 ); |
| 397 | mbedtls_arc4_setup( &arc4, tmp, 32 ); |
| 398 | TIME_AND_TSC( "ARC4", mbedtls_arc4_crypt( &arc4, BUFSIZE, buf, buf ) ); |
| 399 | mbedtls_arc4_free( &arc4 ); |
Manuel Pégourié-Gonnard | 8271f2f | 2013-09-17 14:57:55 +0200 | [diff] [blame] | 400 | } |
Paul Bakker | 5121ce5 | 2009-01-03 21:22:43 +0000 | [diff] [blame] | 401 | #endif |
| 402 | |
Simon Butcher | 549dc3d | 2016-10-05 14:14:19 +0100 | [diff] [blame] | 403 | #if defined(MBEDTLS_DES_C) |
| 404 | #if defined(MBEDTLS_CIPHER_MODE_CBC) |
Manuel Pégourié-Gonnard | ed7cbe9 | 2013-09-17 15:30:51 +0200 | [diff] [blame] | 405 | if( todo.des3 ) |
Manuel Pégourié-Gonnard | 8271f2f | 2013-09-17 14:57:55 +0200 | [diff] [blame] | 406 | { |
Manuel Pégourié-Gonnard | 2cf5a7c | 2015-04-08 12:49:31 +0200 | [diff] [blame] | 407 | mbedtls_des3_context des3; |
| 408 | mbedtls_des3_init( &des3 ); |
| 409 | mbedtls_des3_set3key_enc( &des3, tmp ); |
Manuel Pégourié-Gonnard | 8271f2f | 2013-09-17 14:57:55 +0200 | [diff] [blame] | 410 | TIME_AND_TSC( "3DES", |
Manuel Pégourié-Gonnard | 2cf5a7c | 2015-04-08 12:49:31 +0200 | [diff] [blame] | 411 | mbedtls_des3_crypt_cbc( &des3, MBEDTLS_DES_ENCRYPT, BUFSIZE, tmp, buf, buf ) ); |
| 412 | mbedtls_des3_free( &des3 ); |
Manuel Pégourié-Gonnard | 8271f2f | 2013-09-17 14:57:55 +0200 | [diff] [blame] | 413 | } |
Paul Bakker | 5121ce5 | 2009-01-03 21:22:43 +0000 | [diff] [blame] | 414 | |
Manuel Pégourié-Gonnard | ed7cbe9 | 2013-09-17 15:30:51 +0200 | [diff] [blame] | 415 | if( todo.des ) |
Manuel Pégourié-Gonnard | 8271f2f | 2013-09-17 14:57:55 +0200 | [diff] [blame] | 416 | { |
Manuel Pégourié-Gonnard | 2cf5a7c | 2015-04-08 12:49:31 +0200 | [diff] [blame] | 417 | mbedtls_des_context des; |
| 418 | mbedtls_des_init( &des ); |
| 419 | mbedtls_des_setkey_enc( &des, tmp ); |
Manuel Pégourié-Gonnard | 8271f2f | 2013-09-17 14:57:55 +0200 | [diff] [blame] | 420 | TIME_AND_TSC( "DES", |
Manuel Pégourié-Gonnard | 2cf5a7c | 2015-04-08 12:49:31 +0200 | [diff] [blame] | 421 | mbedtls_des_crypt_cbc( &des, MBEDTLS_DES_ENCRYPT, BUFSIZE, tmp, buf, buf ) ); |
| 422 | mbedtls_des_free( &des ); |
Manuel Pégourié-Gonnard | 8271f2f | 2013-09-17 14:57:55 +0200 | [diff] [blame] | 423 | } |
Simon Butcher | 549dc3d | 2016-10-05 14:14:19 +0100 | [diff] [blame] | 424 | |
| 425 | #endif /* MBEDTLS_CIPHER_MODE_CBC */ |
| 426 | #if defined(MBEDTLS_CMAC_C) |
| 427 | if( todo.des3_cmac ) |
| 428 | { |
| 429 | unsigned char output[8]; |
| 430 | const mbedtls_cipher_info_t *cipher_info; |
| 431 | |
| 432 | memset( buf, 0, sizeof( buf ) ); |
| 433 | memset( tmp, 0, sizeof( tmp ) ); |
| 434 | |
| 435 | cipher_info = mbedtls_cipher_info_from_type( MBEDTLS_CIPHER_DES_EDE3_ECB ); |
| 436 | |
| 437 | TIME_AND_TSC( "3DES-CMAC", |
Simon Butcher | b981b16 | 2016-10-06 10:27:22 +0100 | [diff] [blame] | 438 | mbedtls_cipher_cmac( cipher_info, tmp, 192, buf, |
| 439 | BUFSIZE, output ) ); |
Simon Butcher | 549dc3d | 2016-10-05 14:14:19 +0100 | [diff] [blame] | 440 | } |
| 441 | #endif /* MBEDTLS_CMAC_C */ |
| 442 | #endif /* MBEDTLS_DES_C */ |
Paul Bakker | 5121ce5 | 2009-01-03 21:22:43 +0000 | [diff] [blame] | 443 | |
Manuel Pégourié-Gonnard | 2cf5a7c | 2015-04-08 12:49:31 +0200 | [diff] [blame] | 444 | #if defined(MBEDTLS_AES_C) |
| 445 | #if defined(MBEDTLS_CIPHER_MODE_CBC) |
Manuel Pégourié-Gonnard | ed7cbe9 | 2013-09-17 15:30:51 +0200 | [diff] [blame] | 446 | if( todo.aes_cbc ) |
Paul Bakker | 5121ce5 | 2009-01-03 21:22:43 +0000 | [diff] [blame] | 447 | { |
Manuel Pégourié-Gonnard | 71e75dc | 2014-12-19 18:05:43 +0100 | [diff] [blame] | 448 | int keysize; |
Manuel Pégourié-Gonnard | 2cf5a7c | 2015-04-08 12:49:31 +0200 | [diff] [blame] | 449 | mbedtls_aes_context aes; |
| 450 | mbedtls_aes_init( &aes ); |
Manuel Pégourié-Gonnard | 8271f2f | 2013-09-17 14:57:55 +0200 | [diff] [blame] | 451 | for( keysize = 128; keysize <= 256; keysize += 64 ) |
| 452 | { |
Manuel Pégourié-Gonnard | 2cf5a7c | 2015-04-08 12:49:31 +0200 | [diff] [blame] | 453 | mbedtls_snprintf( title, sizeof( title ), "AES-CBC-%d", keysize ); |
Paul Bakker | 5121ce5 | 2009-01-03 21:22:43 +0000 | [diff] [blame] | 454 | |
Manuel Pégourié-Gonnard | 8271f2f | 2013-09-17 14:57:55 +0200 | [diff] [blame] | 455 | memset( buf, 0, sizeof( buf ) ); |
| 456 | memset( tmp, 0, sizeof( tmp ) ); |
Manuel Pégourié-Gonnard | 2cf5a7c | 2015-04-08 12:49:31 +0200 | [diff] [blame] | 457 | mbedtls_aes_setkey_enc( &aes, tmp, keysize ); |
Paul Bakker | 5121ce5 | 2009-01-03 21:22:43 +0000 | [diff] [blame] | 458 | |
Manuel Pégourié-Gonnard | 8271f2f | 2013-09-17 14:57:55 +0200 | [diff] [blame] | 459 | TIME_AND_TSC( title, |
Manuel Pégourié-Gonnard | 2cf5a7c | 2015-04-08 12:49:31 +0200 | [diff] [blame] | 460 | mbedtls_aes_crypt_cbc( &aes, MBEDTLS_AES_ENCRYPT, BUFSIZE, tmp, buf, buf ) ); |
Manuel Pégourié-Gonnard | 8271f2f | 2013-09-17 14:57:55 +0200 | [diff] [blame] | 461 | } |
Manuel Pégourié-Gonnard | 2cf5a7c | 2015-04-08 12:49:31 +0200 | [diff] [blame] | 462 | mbedtls_aes_free( &aes ); |
Paul Bakker | 5121ce5 | 2009-01-03 21:22:43 +0000 | [diff] [blame] | 463 | } |
Manuel Pégourié-Gonnard | 8271f2f | 2013-09-17 14:57:55 +0200 | [diff] [blame] | 464 | #endif |
Aorimn | 5f77801 | 2016-06-09 23:22:58 +0200 | [diff] [blame] | 465 | #if defined(MBEDTLS_CIPHER_MODE_XTS) |
| 466 | if( todo.aes_xts ) |
| 467 | { |
| 468 | int keysize; |
Jaeden Amero | 9366feb | 2018-05-29 18:55:17 +0100 | [diff] [blame] | 469 | mbedtls_aes_xts_context ctx; |
| 470 | |
| 471 | mbedtls_aes_xts_init( &ctx ); |
| 472 | for( keysize = 128; keysize <= 256; keysize += 128 ) |
Aorimn | 5f77801 | 2016-06-09 23:22:58 +0200 | [diff] [blame] | 473 | { |
| 474 | mbedtls_snprintf( title, sizeof( title ), "AES-XTS-%d", keysize ); |
| 475 | |
| 476 | memset( buf, 0, sizeof( buf ) ); |
| 477 | memset( tmp, 0, sizeof( tmp ) ); |
Jaeden Amero | 9366feb | 2018-05-29 18:55:17 +0100 | [diff] [blame] | 478 | mbedtls_aes_xts_setkey_enc( &ctx, tmp, keysize * 2 ); |
Aorimn | 5f77801 | 2016-06-09 23:22:58 +0200 | [diff] [blame] | 479 | |
| 480 | TIME_AND_TSC( title, |
Jaeden Amero | 9366feb | 2018-05-29 18:55:17 +0100 | [diff] [blame] | 481 | mbedtls_aes_crypt_xts( &ctx, MBEDTLS_AES_ENCRYPT, BUFSIZE, |
| 482 | tmp, buf, buf ) ); |
| 483 | |
| 484 | mbedtls_aes_xts_free( &ctx ); |
Aorimn | 5f77801 | 2016-06-09 23:22:58 +0200 | [diff] [blame] | 485 | } |
Aorimn | 5f77801 | 2016-06-09 23:22:58 +0200 | [diff] [blame] | 486 | } |
| 487 | #endif |
Manuel Pégourié-Gonnard | 2cf5a7c | 2015-04-08 12:49:31 +0200 | [diff] [blame] | 488 | #if defined(MBEDTLS_GCM_C) |
Manuel Pégourié-Gonnard | ed7cbe9 | 2013-09-17 15:30:51 +0200 | [diff] [blame] | 489 | if( todo.aes_gcm ) |
Paul Bakker | 89e80c9 | 2012-03-20 13:50:09 +0000 | [diff] [blame] | 490 | { |
Manuel Pégourié-Gonnard | 71e75dc | 2014-12-19 18:05:43 +0100 | [diff] [blame] | 491 | int keysize; |
Manuel Pégourié-Gonnard | 2cf5a7c | 2015-04-08 12:49:31 +0200 | [diff] [blame] | 492 | mbedtls_gcm_context gcm; |
Manuel Pégourié-Gonnard | c34e8dd | 2015-04-28 21:42:17 +0200 | [diff] [blame] | 493 | |
| 494 | mbedtls_gcm_init( &gcm ); |
Manuel Pégourié-Gonnard | 8271f2f | 2013-09-17 14:57:55 +0200 | [diff] [blame] | 495 | for( keysize = 128; keysize <= 256; keysize += 64 ) |
| 496 | { |
Manuel Pégourié-Gonnard | 2cf5a7c | 2015-04-08 12:49:31 +0200 | [diff] [blame] | 497 | mbedtls_snprintf( title, sizeof( title ), "AES-GCM-%d", keysize ); |
Paul Bakker | 89e80c9 | 2012-03-20 13:50:09 +0000 | [diff] [blame] | 498 | |
Manuel Pégourié-Gonnard | 8271f2f | 2013-09-17 14:57:55 +0200 | [diff] [blame] | 499 | memset( buf, 0, sizeof( buf ) ); |
| 500 | memset( tmp, 0, sizeof( tmp ) ); |
Manuel Pégourié-Gonnard | c34e8dd | 2015-04-28 21:42:17 +0200 | [diff] [blame] | 501 | mbedtls_gcm_setkey( &gcm, MBEDTLS_CIPHER_ID_AES, tmp, keysize ); |
Paul Bakker | 89e80c9 | 2012-03-20 13:50:09 +0000 | [diff] [blame] | 502 | |
Manuel Pégourié-Gonnard | 8271f2f | 2013-09-17 14:57:55 +0200 | [diff] [blame] | 503 | TIME_AND_TSC( title, |
Manuel Pégourié-Gonnard | 2cf5a7c | 2015-04-08 12:49:31 +0200 | [diff] [blame] | 504 | mbedtls_gcm_crypt_and_tag( &gcm, MBEDTLS_GCM_ENCRYPT, BUFSIZE, tmp, |
Manuel Pégourié-Gonnard | 8271f2f | 2013-09-17 14:57:55 +0200 | [diff] [blame] | 505 | 12, NULL, 0, buf, buf, 16, tmp ) ); |
Paul Bakker | f70fe81 | 2013-12-16 16:43:10 +0100 | [diff] [blame] | 506 | |
Manuel Pégourié-Gonnard | 2cf5a7c | 2015-04-08 12:49:31 +0200 | [diff] [blame] | 507 | mbedtls_gcm_free( &gcm ); |
Manuel Pégourié-Gonnard | 8271f2f | 2013-09-17 14:57:55 +0200 | [diff] [blame] | 508 | } |
Paul Bakker | 89e80c9 | 2012-03-20 13:50:09 +0000 | [diff] [blame] | 509 | } |
| 510 | #endif |
Manuel Pégourié-Gonnard | 2cf5a7c | 2015-04-08 12:49:31 +0200 | [diff] [blame] | 511 | #if defined(MBEDTLS_CCM_C) |
Manuel Pégourié-Gonnard | 58d78a8 | 2014-05-07 12:03:02 +0200 | [diff] [blame] | 512 | if( todo.aes_ccm ) |
| 513 | { |
Manuel Pégourié-Gonnard | 71e75dc | 2014-12-19 18:05:43 +0100 | [diff] [blame] | 514 | int keysize; |
Manuel Pégourié-Gonnard | 2cf5a7c | 2015-04-08 12:49:31 +0200 | [diff] [blame] | 515 | mbedtls_ccm_context ccm; |
Manuel Pégourié-Gonnard | 6963ff0 | 2015-04-28 18:02:54 +0200 | [diff] [blame] | 516 | |
| 517 | mbedtls_ccm_init( &ccm ); |
Manuel Pégourié-Gonnard | 58d78a8 | 2014-05-07 12:03:02 +0200 | [diff] [blame] | 518 | for( keysize = 128; keysize <= 256; keysize += 64 ) |
| 519 | { |
Manuel Pégourié-Gonnard | 2cf5a7c | 2015-04-08 12:49:31 +0200 | [diff] [blame] | 520 | mbedtls_snprintf( title, sizeof( title ), "AES-CCM-%d", keysize ); |
Manuel Pégourié-Gonnard | 58d78a8 | 2014-05-07 12:03:02 +0200 | [diff] [blame] | 521 | |
| 522 | memset( buf, 0, sizeof( buf ) ); |
| 523 | memset( tmp, 0, sizeof( tmp ) ); |
Manuel Pégourié-Gonnard | 6963ff0 | 2015-04-28 18:02:54 +0200 | [diff] [blame] | 524 | mbedtls_ccm_setkey( &ccm, MBEDTLS_CIPHER_ID_AES, tmp, keysize ); |
Manuel Pégourié-Gonnard | 58d78a8 | 2014-05-07 12:03:02 +0200 | [diff] [blame] | 525 | |
| 526 | TIME_AND_TSC( title, |
Manuel Pégourié-Gonnard | 2cf5a7c | 2015-04-08 12:49:31 +0200 | [diff] [blame] | 527 | mbedtls_ccm_encrypt_and_tag( &ccm, BUFSIZE, tmp, |
Manuel Pégourié-Gonnard | 58d78a8 | 2014-05-07 12:03:02 +0200 | [diff] [blame] | 528 | 12, NULL, 0, buf, buf, tmp, 16 ) ); |
| 529 | |
Manuel Pégourié-Gonnard | 2cf5a7c | 2015-04-08 12:49:31 +0200 | [diff] [blame] | 530 | mbedtls_ccm_free( &ccm ); |
Manuel Pégourié-Gonnard | 58d78a8 | 2014-05-07 12:03:02 +0200 | [diff] [blame] | 531 | } |
| 532 | } |
| 533 | #endif |
Manuel Pégourié-Gonnard | d6aea18 | 2018-05-09 10:21:28 +0200 | [diff] [blame] | 534 | #if defined(MBEDTLS_CHACHAPOLY_C) |
| 535 | if( todo.chachapoly ) |
| 536 | { |
| 537 | mbedtls_chachapoly_context chachapoly; |
| 538 | |
| 539 | mbedtls_chachapoly_init( &chachapoly ); |
| 540 | memset( buf, 0, sizeof( buf ) ); |
| 541 | memset( tmp, 0, sizeof( tmp ) ); |
| 542 | |
| 543 | mbedtls_snprintf( title, sizeof( title ), "ChaCha20-Poly1305" ); |
| 544 | |
| 545 | mbedtls_chachapoly_setkey( &chachapoly, tmp ); |
| 546 | |
| 547 | TIME_AND_TSC( title, |
Manuel Pégourié-Gonnard | 3dc62a0 | 2018-06-04 12:18:19 +0200 | [diff] [blame] | 548 | mbedtls_chachapoly_encrypt_and_tag( &chachapoly, |
| 549 | BUFSIZE, tmp, NULL, 0, buf, buf, tmp ) ); |
Manuel Pégourié-Gonnard | d6aea18 | 2018-05-09 10:21:28 +0200 | [diff] [blame] | 550 | |
| 551 | mbedtls_chachapoly_free( &chachapoly ); |
| 552 | } |
| 553 | #endif |
Simon Butcher | 549dc3d | 2016-10-05 14:14:19 +0100 | [diff] [blame] | 554 | #if defined(MBEDTLS_CMAC_C) |
| 555 | if( todo.aes_cmac ) |
| 556 | { |
| 557 | unsigned char output[16]; |
| 558 | const mbedtls_cipher_info_t *cipher_info; |
| 559 | mbedtls_cipher_type_t cipher_type; |
| 560 | int keysize; |
| 561 | |
| 562 | for( keysize = 128, cipher_type = MBEDTLS_CIPHER_AES_128_ECB; |
| 563 | keysize <= 256; |
| 564 | keysize += 64, cipher_type++ ) |
| 565 | { |
| 566 | mbedtls_snprintf( title, sizeof( title ), "AES-CMAC-%d", keysize ); |
| 567 | |
| 568 | memset( buf, 0, sizeof( buf ) ); |
| 569 | memset( tmp, 0, sizeof( tmp ) ); |
| 570 | |
| 571 | cipher_info = mbedtls_cipher_info_from_type( cipher_type ); |
| 572 | |
| 573 | TIME_AND_TSC( title, |
Andres AG | a592dcc | 2016-10-06 15:23:39 +0100 | [diff] [blame] | 574 | mbedtls_cipher_cmac( cipher_info, tmp, keysize, |
| 575 | buf, BUFSIZE, output ) ); |
Simon Butcher | 549dc3d | 2016-10-05 14:14:19 +0100 | [diff] [blame] | 576 | } |
| 577 | |
| 578 | memset( buf, 0, sizeof( buf ) ); |
| 579 | memset( tmp, 0, sizeof( tmp ) ); |
| 580 | TIME_AND_TSC( "AES-CMAC-PRF-128", |
Simon Butcher | b981b16 | 2016-10-06 10:27:22 +0100 | [diff] [blame] | 581 | mbedtls_aes_cmac_prf_128( tmp, 16, buf, BUFSIZE, |
| 582 | output ) ); |
Simon Butcher | 549dc3d | 2016-10-05 14:14:19 +0100 | [diff] [blame] | 583 | } |
| 584 | #endif /* MBEDTLS_CMAC_C */ |
| 585 | #endif /* MBEDTLS_AES_C */ |
Paul Bakker | 5121ce5 | 2009-01-03 21:22:43 +0000 | [diff] [blame] | 586 | |
Manuel Pégourié-Gonnard | 62e813c | 2018-02-21 10:47:47 +0100 | [diff] [blame] | 587 | #if defined(MBEDTLS_ARIA_C) && defined(MBEDTLS_CIPHER_MODE_CBC) |
| 588 | if( todo.aria ) |
| 589 | { |
| 590 | int keysize; |
| 591 | mbedtls_aria_context aria; |
| 592 | mbedtls_aria_init( &aria ); |
| 593 | for( keysize = 128; keysize <= 256; keysize += 64 ) |
| 594 | { |
| 595 | mbedtls_snprintf( title, sizeof( title ), "ARIA-CBC-%d", keysize ); |
| 596 | |
| 597 | memset( buf, 0, sizeof( buf ) ); |
| 598 | memset( tmp, 0, sizeof( tmp ) ); |
| 599 | mbedtls_aria_setkey_enc( &aria, tmp, keysize ); |
| 600 | |
| 601 | TIME_AND_TSC( title, |
| 602 | mbedtls_aria_crypt_cbc( &aria, MBEDTLS_ARIA_ENCRYPT, |
| 603 | BUFSIZE, tmp, buf, buf ) ); |
| 604 | } |
| 605 | mbedtls_aria_free( &aria ); |
| 606 | } |
| 607 | #endif |
| 608 | |
Manuel Pégourié-Gonnard | 2cf5a7c | 2015-04-08 12:49:31 +0200 | [diff] [blame] | 609 | #if defined(MBEDTLS_CAMELLIA_C) && defined(MBEDTLS_CIPHER_MODE_CBC) |
Manuel Pégourié-Gonnard | ed7cbe9 | 2013-09-17 15:30:51 +0200 | [diff] [blame] | 610 | if( todo.camellia ) |
Paul Bakker | 38119b1 | 2009-01-10 23:31:23 +0000 | [diff] [blame] | 611 | { |
Manuel Pégourié-Gonnard | 71e75dc | 2014-12-19 18:05:43 +0100 | [diff] [blame] | 612 | int keysize; |
Manuel Pégourié-Gonnard | 2cf5a7c | 2015-04-08 12:49:31 +0200 | [diff] [blame] | 613 | mbedtls_camellia_context camellia; |
| 614 | mbedtls_camellia_init( &camellia ); |
Manuel Pégourié-Gonnard | 8271f2f | 2013-09-17 14:57:55 +0200 | [diff] [blame] | 615 | for( keysize = 128; keysize <= 256; keysize += 64 ) |
| 616 | { |
Manuel Pégourié-Gonnard | 2cf5a7c | 2015-04-08 12:49:31 +0200 | [diff] [blame] | 617 | mbedtls_snprintf( title, sizeof( title ), "CAMELLIA-CBC-%d", keysize ); |
Paul Bakker | 38119b1 | 2009-01-10 23:31:23 +0000 | [diff] [blame] | 618 | |
Manuel Pégourié-Gonnard | 8271f2f | 2013-09-17 14:57:55 +0200 | [diff] [blame] | 619 | memset( buf, 0, sizeof( buf ) ); |
| 620 | memset( tmp, 0, sizeof( tmp ) ); |
Manuel Pégourié-Gonnard | 2cf5a7c | 2015-04-08 12:49:31 +0200 | [diff] [blame] | 621 | mbedtls_camellia_setkey_enc( &camellia, tmp, keysize ); |
Paul Bakker | 38119b1 | 2009-01-10 23:31:23 +0000 | [diff] [blame] | 622 | |
Manuel Pégourié-Gonnard | 8271f2f | 2013-09-17 14:57:55 +0200 | [diff] [blame] | 623 | TIME_AND_TSC( title, |
Manuel Pégourié-Gonnard | 2cf5a7c | 2015-04-08 12:49:31 +0200 | [diff] [blame] | 624 | mbedtls_camellia_crypt_cbc( &camellia, MBEDTLS_CAMELLIA_ENCRYPT, |
Manuel Pégourié-Gonnard | 8271f2f | 2013-09-17 14:57:55 +0200 | [diff] [blame] | 625 | BUFSIZE, tmp, buf, buf ) ); |
| 626 | } |
Manuel Pégourié-Gonnard | 2cf5a7c | 2015-04-08 12:49:31 +0200 | [diff] [blame] | 627 | mbedtls_camellia_free( &camellia ); |
Paul Bakker | 38119b1 | 2009-01-10 23:31:23 +0000 | [diff] [blame] | 628 | } |
| 629 | #endif |
| 630 | |
Daniel King | 34b822c | 2016-05-15 17:28:08 -0300 | [diff] [blame] | 631 | #if defined(MBEDTLS_CHACHA20_C) |
| 632 | if ( todo.chacha20 ) |
| 633 | { |
| 634 | TIME_AND_TSC( "ChaCha20", mbedtls_chacha20_crypt( buf, buf, 0U, BUFSIZE, buf, buf ) ); |
| 635 | } |
| 636 | #endif |
| 637 | |
Daniel King | adc32c0 | 2016-05-16 18:25:45 -0300 | [diff] [blame] | 638 | #if defined(MBEDTLS_POLY1305_C) |
| 639 | if ( todo.poly1305 ) |
| 640 | { |
Manuel Pégourié-Gonnard | b1ac5e7 | 2018-05-09 09:25:00 +0200 | [diff] [blame] | 641 | TIME_AND_TSC( "Poly1305", mbedtls_poly1305_mac( buf, buf, BUFSIZE, buf ) ); |
Daniel King | adc32c0 | 2016-05-16 18:25:45 -0300 | [diff] [blame] | 642 | } |
| 643 | #endif |
| 644 | |
Manuel Pégourié-Gonnard | 2cf5a7c | 2015-04-08 12:49:31 +0200 | [diff] [blame] | 645 | #if defined(MBEDTLS_BLOWFISH_C) && defined(MBEDTLS_CIPHER_MODE_CBC) |
Manuel Pégourié-Gonnard | ed7cbe9 | 2013-09-17 15:30:51 +0200 | [diff] [blame] | 646 | if( todo.blowfish ) |
Paul Bakker | 3d58fe8 | 2012-07-04 17:15:31 +0000 | [diff] [blame] | 647 | { |
Manuel Pégourié-Gonnard | 71e75dc | 2014-12-19 18:05:43 +0100 | [diff] [blame] | 648 | int keysize; |
Manuel Pégourié-Gonnard | 2cf5a7c | 2015-04-08 12:49:31 +0200 | [diff] [blame] | 649 | mbedtls_blowfish_context blowfish; |
| 650 | mbedtls_blowfish_init( &blowfish ); |
Paul Bakker | 8cfd9d8 | 2014-06-18 11:16:11 +0200 | [diff] [blame] | 651 | |
Manuel Pégourié-Gonnard | 8271f2f | 2013-09-17 14:57:55 +0200 | [diff] [blame] | 652 | for( keysize = 128; keysize <= 256; keysize += 64 ) |
| 653 | { |
Manuel Pégourié-Gonnard | 2cf5a7c | 2015-04-08 12:49:31 +0200 | [diff] [blame] | 654 | mbedtls_snprintf( title, sizeof( title ), "BLOWFISH-CBC-%d", keysize ); |
Paul Bakker | 3d58fe8 | 2012-07-04 17:15:31 +0000 | [diff] [blame] | 655 | |
Manuel Pégourié-Gonnard | 8271f2f | 2013-09-17 14:57:55 +0200 | [diff] [blame] | 656 | memset( buf, 0, sizeof( buf ) ); |
| 657 | memset( tmp, 0, sizeof( tmp ) ); |
Manuel Pégourié-Gonnard | 2cf5a7c | 2015-04-08 12:49:31 +0200 | [diff] [blame] | 658 | mbedtls_blowfish_setkey( &blowfish, tmp, keysize ); |
Paul Bakker | 3d58fe8 | 2012-07-04 17:15:31 +0000 | [diff] [blame] | 659 | |
Manuel Pégourié-Gonnard | 8271f2f | 2013-09-17 14:57:55 +0200 | [diff] [blame] | 660 | TIME_AND_TSC( title, |
Manuel Pégourié-Gonnard | 2cf5a7c | 2015-04-08 12:49:31 +0200 | [diff] [blame] | 661 | mbedtls_blowfish_crypt_cbc( &blowfish, MBEDTLS_BLOWFISH_ENCRYPT, BUFSIZE, |
Manuel Pégourié-Gonnard | 8271f2f | 2013-09-17 14:57:55 +0200 | [diff] [blame] | 662 | tmp, buf, buf ) ); |
| 663 | } |
Paul Bakker | 8cfd9d8 | 2014-06-18 11:16:11 +0200 | [diff] [blame] | 664 | |
Manuel Pégourié-Gonnard | 2cf5a7c | 2015-04-08 12:49:31 +0200 | [diff] [blame] | 665 | mbedtls_blowfish_free( &blowfish ); |
Paul Bakker | 3d58fe8 | 2012-07-04 17:15:31 +0000 | [diff] [blame] | 666 | } |
| 667 | #endif |
| 668 | |
Manuel Pégourié-Gonnard | 2cf5a7c | 2015-04-08 12:49:31 +0200 | [diff] [blame] | 669 | #if defined(MBEDTLS_HAVEGE_C) |
Manuel Pégourié-Gonnard | ed7cbe9 | 2013-09-17 15:30:51 +0200 | [diff] [blame] | 670 | if( todo.havege ) |
Manuel Pégourié-Gonnard | 8271f2f | 2013-09-17 14:57:55 +0200 | [diff] [blame] | 671 | { |
Manuel Pégourié-Gonnard | 2cf5a7c | 2015-04-08 12:49:31 +0200 | [diff] [blame] | 672 | mbedtls_havege_state hs; |
| 673 | mbedtls_havege_init( &hs ); |
| 674 | TIME_AND_TSC( "HAVEGE", mbedtls_havege_random( &hs, buf, BUFSIZE ) ); |
| 675 | mbedtls_havege_free( &hs ); |
Manuel Pégourié-Gonnard | 8271f2f | 2013-09-17 14:57:55 +0200 | [diff] [blame] | 676 | } |
Paul Bakker | 02faf45 | 2011-11-29 11:23:58 +0000 | [diff] [blame] | 677 | #endif |
| 678 | |
Manuel Pégourié-Gonnard | 2cf5a7c | 2015-04-08 12:49:31 +0200 | [diff] [blame] | 679 | #if defined(MBEDTLS_CTR_DRBG_C) |
Manuel Pégourié-Gonnard | ed7cbe9 | 2013-09-17 15:30:51 +0200 | [diff] [blame] | 680 | if( todo.ctr_drbg ) |
Manuel Pégourié-Gonnard | 8271f2f | 2013-09-17 14:57:55 +0200 | [diff] [blame] | 681 | { |
Manuel Pégourié-Gonnard | 2cf5a7c | 2015-04-08 12:49:31 +0200 | [diff] [blame] | 682 | mbedtls_ctr_drbg_context ctr_drbg; |
Paul Bakker | 02faf45 | 2011-11-29 11:23:58 +0000 | [diff] [blame] | 683 | |
Manuel Pégourié-Gonnard | 8d128ef | 2015-04-28 22:38:08 +0200 | [diff] [blame] | 684 | mbedtls_ctr_drbg_init( &ctr_drbg ); |
| 685 | |
| 686 | if( mbedtls_ctr_drbg_seed( &ctr_drbg, myrand, NULL, NULL, 0 ) != 0 ) |
Manuel Pégourié-Gonnard | 2cf5a7c | 2015-04-08 12:49:31 +0200 | [diff] [blame] | 687 | mbedtls_exit(1); |
Manuel Pégourié-Gonnard | 8271f2f | 2013-09-17 14:57:55 +0200 | [diff] [blame] | 688 | TIME_AND_TSC( "CTR_DRBG (NOPR)", |
Manuel Pégourié-Gonnard | 51d7cfe | 2018-06-25 11:19:51 +0200 | [diff] [blame] | 689 | mbedtls_ctr_drbg_random( &ctr_drbg, buf, BUFSIZE ) ); |
Paul Bakker | 02faf45 | 2011-11-29 11:23:58 +0000 | [diff] [blame] | 690 | |
Manuel Pégourié-Gonnard | 8d128ef | 2015-04-28 22:38:08 +0200 | [diff] [blame] | 691 | if( mbedtls_ctr_drbg_seed( &ctr_drbg, myrand, NULL, NULL, 0 ) != 0 ) |
Manuel Pégourié-Gonnard | 2cf5a7c | 2015-04-08 12:49:31 +0200 | [diff] [blame] | 692 | mbedtls_exit(1); |
| 693 | mbedtls_ctr_drbg_set_prediction_resistance( &ctr_drbg, MBEDTLS_CTR_DRBG_PR_ON ); |
Manuel Pégourié-Gonnard | 8271f2f | 2013-09-17 14:57:55 +0200 | [diff] [blame] | 694 | TIME_AND_TSC( "CTR_DRBG (PR)", |
Manuel Pégourié-Gonnard | 51d7cfe | 2018-06-25 11:19:51 +0200 | [diff] [blame] | 695 | mbedtls_ctr_drbg_random( &ctr_drbg, buf, BUFSIZE ) ); |
Manuel Pégourié-Gonnard | 2cf5a7c | 2015-04-08 12:49:31 +0200 | [diff] [blame] | 696 | mbedtls_ctr_drbg_free( &ctr_drbg ); |
Manuel Pégourié-Gonnard | 8271f2f | 2013-09-17 14:57:55 +0200 | [diff] [blame] | 697 | } |
Paul Bakker | 02faf45 | 2011-11-29 11:23:58 +0000 | [diff] [blame] | 698 | #endif |
| 699 | |
Manuel Pégourié-Gonnard | 2cf5a7c | 2015-04-08 12:49:31 +0200 | [diff] [blame] | 700 | #if defined(MBEDTLS_HMAC_DRBG_C) |
Manuel Pégourié-Gonnard | fef0f8f | 2014-01-30 20:59:00 +0100 | [diff] [blame] | 701 | if( todo.hmac_drbg ) |
| 702 | { |
Manuel Pégourié-Gonnard | 2cf5a7c | 2015-04-08 12:49:31 +0200 | [diff] [blame] | 703 | mbedtls_hmac_drbg_context hmac_drbg; |
| 704 | const mbedtls_md_info_t *md_info; |
Manuel Pégourié-Gonnard | fef0f8f | 2014-01-30 20:59:00 +0100 | [diff] [blame] | 705 | |
Manuel Pégourié-Gonnard | f9e9481 | 2015-04-28 22:07:14 +0200 | [diff] [blame] | 706 | mbedtls_hmac_drbg_init( &hmac_drbg ); |
| 707 | |
Manuel Pégourié-Gonnard | 2cf5a7c | 2015-04-08 12:49:31 +0200 | [diff] [blame] | 708 | #if defined(MBEDTLS_SHA1_C) |
| 709 | if( ( md_info = mbedtls_md_info_from_type( MBEDTLS_MD_SHA1 ) ) == NULL ) |
| 710 | mbedtls_exit(1); |
Manuel Pégourié-Gonnard | fef0f8f | 2014-01-30 20:59:00 +0100 | [diff] [blame] | 711 | |
Manuel Pégourié-Gonnard | f9e9481 | 2015-04-28 22:07:14 +0200 | [diff] [blame] | 712 | if( mbedtls_hmac_drbg_seed( &hmac_drbg, md_info, myrand, NULL, NULL, 0 ) != 0 ) |
Manuel Pégourié-Gonnard | 2cf5a7c | 2015-04-08 12:49:31 +0200 | [diff] [blame] | 713 | mbedtls_exit(1); |
Manuel Pégourié-Gonnard | fef0f8f | 2014-01-30 20:59:00 +0100 | [diff] [blame] | 714 | TIME_AND_TSC( "HMAC_DRBG SHA-1 (NOPR)", |
Manuel Pégourié-Gonnard | 51d7cfe | 2018-06-25 11:19:51 +0200 | [diff] [blame] | 715 | mbedtls_hmac_drbg_random( &hmac_drbg, buf, BUFSIZE ) ); |
Manuel Pégourié-Gonnard | fef0f8f | 2014-01-30 20:59:00 +0100 | [diff] [blame] | 716 | |
Manuel Pégourié-Gonnard | f9e9481 | 2015-04-28 22:07:14 +0200 | [diff] [blame] | 717 | if( mbedtls_hmac_drbg_seed( &hmac_drbg, md_info, myrand, NULL, NULL, 0 ) != 0 ) |
Manuel Pégourié-Gonnard | 2cf5a7c | 2015-04-08 12:49:31 +0200 | [diff] [blame] | 718 | mbedtls_exit(1); |
| 719 | mbedtls_hmac_drbg_set_prediction_resistance( &hmac_drbg, |
| 720 | MBEDTLS_HMAC_DRBG_PR_ON ); |
Manuel Pégourié-Gonnard | fef0f8f | 2014-01-30 20:59:00 +0100 | [diff] [blame] | 721 | TIME_AND_TSC( "HMAC_DRBG SHA-1 (PR)", |
Manuel Pégourié-Gonnard | 51d7cfe | 2018-06-25 11:19:51 +0200 | [diff] [blame] | 722 | mbedtls_hmac_drbg_random( &hmac_drbg, buf, BUFSIZE ) ); |
Manuel Pégourié-Gonnard | fef0f8f | 2014-01-30 20:59:00 +0100 | [diff] [blame] | 723 | #endif |
| 724 | |
Manuel Pégourié-Gonnard | 2cf5a7c | 2015-04-08 12:49:31 +0200 | [diff] [blame] | 725 | #if defined(MBEDTLS_SHA256_C) |
| 726 | if( ( md_info = mbedtls_md_info_from_type( MBEDTLS_MD_SHA256 ) ) == NULL ) |
| 727 | mbedtls_exit(1); |
Manuel Pégourié-Gonnard | fef0f8f | 2014-01-30 20:59:00 +0100 | [diff] [blame] | 728 | |
Manuel Pégourié-Gonnard | f9e9481 | 2015-04-28 22:07:14 +0200 | [diff] [blame] | 729 | if( mbedtls_hmac_drbg_seed( &hmac_drbg, md_info, myrand, NULL, NULL, 0 ) != 0 ) |
Manuel Pégourié-Gonnard | 2cf5a7c | 2015-04-08 12:49:31 +0200 | [diff] [blame] | 730 | mbedtls_exit(1); |
Manuel Pégourié-Gonnard | fef0f8f | 2014-01-30 20:59:00 +0100 | [diff] [blame] | 731 | TIME_AND_TSC( "HMAC_DRBG SHA-256 (NOPR)", |
Manuel Pégourié-Gonnard | 51d7cfe | 2018-06-25 11:19:51 +0200 | [diff] [blame] | 732 | mbedtls_hmac_drbg_random( &hmac_drbg, buf, BUFSIZE ) ); |
Manuel Pégourié-Gonnard | fef0f8f | 2014-01-30 20:59:00 +0100 | [diff] [blame] | 733 | |
Manuel Pégourié-Gonnard | f9e9481 | 2015-04-28 22:07:14 +0200 | [diff] [blame] | 734 | if( mbedtls_hmac_drbg_seed( &hmac_drbg, md_info, myrand, NULL, NULL, 0 ) != 0 ) |
Manuel Pégourié-Gonnard | 2cf5a7c | 2015-04-08 12:49:31 +0200 | [diff] [blame] | 735 | mbedtls_exit(1); |
| 736 | mbedtls_hmac_drbg_set_prediction_resistance( &hmac_drbg, |
| 737 | MBEDTLS_HMAC_DRBG_PR_ON ); |
Manuel Pégourié-Gonnard | fef0f8f | 2014-01-30 20:59:00 +0100 | [diff] [blame] | 738 | TIME_AND_TSC( "HMAC_DRBG SHA-256 (PR)", |
Manuel Pégourié-Gonnard | 51d7cfe | 2018-06-25 11:19:51 +0200 | [diff] [blame] | 739 | mbedtls_hmac_drbg_random( &hmac_drbg, buf, BUFSIZE ) ); |
Manuel Pégourié-Gonnard | fef0f8f | 2014-01-30 20:59:00 +0100 | [diff] [blame] | 740 | #endif |
Ron Eldor | 278af45 | 2018-06-20 18:40:21 +0300 | [diff] [blame] | 741 | mbedtls_hmac_drbg_free( &hmac_drbg ); |
Manuel Pégourié-Gonnard | fef0f8f | 2014-01-30 20:59:00 +0100 | [diff] [blame] | 742 | } |
| 743 | #endif |
| 744 | |
Manuel Pégourié-Gonnard | 2cf5a7c | 2015-04-08 12:49:31 +0200 | [diff] [blame] | 745 | #if defined(MBEDTLS_RSA_C) && defined(MBEDTLS_GENPRIME) |
Manuel Pégourié-Gonnard | ed7cbe9 | 2013-09-17 15:30:51 +0200 | [diff] [blame] | 746 | if( todo.rsa ) |
Paul Bakker | 5121ce5 | 2009-01-03 21:22:43 +0000 | [diff] [blame] | 747 | { |
Manuel Pégourié-Gonnard | 71e75dc | 2014-12-19 18:05:43 +0100 | [diff] [blame] | 748 | int keysize; |
Manuel Pégourié-Gonnard | 2cf5a7c | 2015-04-08 12:49:31 +0200 | [diff] [blame] | 749 | mbedtls_rsa_context rsa; |
Manuel Pégourié-Gonnard | a6dbddc | 2015-07-06 11:20:33 +0200 | [diff] [blame] | 750 | for( keysize = 2048; keysize <= 4096; keysize *= 2 ) |
Manuel Pégourié-Gonnard | 8271f2f | 2013-09-17 14:57:55 +0200 | [diff] [blame] | 751 | { |
Manuel Pégourié-Gonnard | 2cf5a7c | 2015-04-08 12:49:31 +0200 | [diff] [blame] | 752 | mbedtls_snprintf( title, sizeof( title ), "RSA-%d", keysize ); |
Manuel Pégourié-Gonnard | 8271f2f | 2013-09-17 14:57:55 +0200 | [diff] [blame] | 753 | |
Manuel Pégourié-Gonnard | 2cf5a7c | 2015-04-08 12:49:31 +0200 | [diff] [blame] | 754 | mbedtls_rsa_init( &rsa, MBEDTLS_RSA_PKCS_V15, 0 ); |
| 755 | mbedtls_rsa_gen_key( &rsa, myrand, NULL, keysize, 65537 ); |
Manuel Pégourié-Gonnard | 8271f2f | 2013-09-17 14:57:55 +0200 | [diff] [blame] | 756 | |
| 757 | TIME_PUBLIC( title, " public", |
| 758 | buf[0] = 0; |
Manuel Pégourié-Gonnard | 2cf5a7c | 2015-04-08 12:49:31 +0200 | [diff] [blame] | 759 | ret = mbedtls_rsa_public( &rsa, buf, buf ) ); |
Manuel Pégourié-Gonnard | 8271f2f | 2013-09-17 14:57:55 +0200 | [diff] [blame] | 760 | |
| 761 | TIME_PUBLIC( title, "private", |
| 762 | buf[0] = 0; |
Manuel Pégourié-Gonnard | 2cf5a7c | 2015-04-08 12:49:31 +0200 | [diff] [blame] | 763 | ret = mbedtls_rsa_private( &rsa, myrand, NULL, buf, buf ) ); |
Manuel Pégourié-Gonnard | 8271f2f | 2013-09-17 14:57:55 +0200 | [diff] [blame] | 764 | |
Manuel Pégourié-Gonnard | 2cf5a7c | 2015-04-08 12:49:31 +0200 | [diff] [blame] | 765 | mbedtls_rsa_free( &rsa ); |
Manuel Pégourié-Gonnard | 8271f2f | 2013-09-17 14:57:55 +0200 | [diff] [blame] | 766 | } |
Paul Bakker | 5121ce5 | 2009-01-03 21:22:43 +0000 | [diff] [blame] | 767 | } |
Paul Bakker | 5121ce5 | 2009-01-03 21:22:43 +0000 | [diff] [blame] | 768 | #endif |
| 769 | |
Manuel Pégourié-Gonnard | 2cf5a7c | 2015-04-08 12:49:31 +0200 | [diff] [blame] | 770 | #if defined(MBEDTLS_DHM_C) && defined(MBEDTLS_BIGNUM_C) |
Manuel Pégourié-Gonnard | ed7cbe9 | 2013-09-17 15:30:51 +0200 | [diff] [blame] | 771 | if( todo.dhm ) |
Manuel Pégourié-Gonnard | e870c0a | 2012-11-08 11:31:48 +0100 | [diff] [blame] | 772 | { |
Manuel Pégourié-Gonnard | 4f3368e | 2015-07-19 15:01:28 +0200 | [diff] [blame] | 773 | int dhm_sizes[] = { 2048, 3072 }; |
Brendan Shanks | e61514d | 2018-03-08 17:40:56 -0800 | [diff] [blame] | 774 | static const unsigned char dhm_P_2048[] = |
Hanno Becker | b953921 | 2017-10-04 13:13:34 +0100 | [diff] [blame] | 775 | MBEDTLS_DHM_RFC3526_MODP_2048_P_BIN; |
Brendan Shanks | e61514d | 2018-03-08 17:40:56 -0800 | [diff] [blame] | 776 | static const unsigned char dhm_P_3072[] = |
Hanno Becker | b953921 | 2017-10-04 13:13:34 +0100 | [diff] [blame] | 777 | MBEDTLS_DHM_RFC3526_MODP_3072_P_BIN; |
Brendan Shanks | e61514d | 2018-03-08 17:40:56 -0800 | [diff] [blame] | 778 | static const unsigned char dhm_G_2048[] = |
Hanno Becker | b953921 | 2017-10-04 13:13:34 +0100 | [diff] [blame] | 779 | MBEDTLS_DHM_RFC3526_MODP_2048_G_BIN; |
Brendan Shanks | e61514d | 2018-03-08 17:40:56 -0800 | [diff] [blame] | 780 | static const unsigned char dhm_G_3072[] = |
Hanno Becker | b953921 | 2017-10-04 13:13:34 +0100 | [diff] [blame] | 781 | MBEDTLS_DHM_RFC3526_MODP_3072_G_BIN; |
| 782 | |
| 783 | const unsigned char *dhm_P[] = { dhm_P_2048, dhm_P_3072 }; |
| 784 | const size_t dhm_P_size[] = { sizeof( dhm_P_2048 ), |
| 785 | sizeof( dhm_P_3072 ) }; |
| 786 | |
| 787 | const unsigned char *dhm_G[] = { dhm_G_2048, dhm_G_3072 }; |
| 788 | const size_t dhm_G_size[] = { sizeof( dhm_G_2048 ), |
| 789 | sizeof( dhm_G_3072 ) }; |
Manuel Pégourié-Gonnard | 8271f2f | 2013-09-17 14:57:55 +0200 | [diff] [blame] | 790 | |
Manuel Pégourié-Gonnard | 2cf5a7c | 2015-04-08 12:49:31 +0200 | [diff] [blame] | 791 | mbedtls_dhm_context dhm; |
Manuel Pégourié-Gonnard | 8271f2f | 2013-09-17 14:57:55 +0200 | [diff] [blame] | 792 | size_t olen; |
Manuel Pégourié-Gonnard | 4f3368e | 2015-07-19 15:01:28 +0200 | [diff] [blame] | 793 | for( i = 0; (size_t) i < sizeof( dhm_sizes ) / sizeof( dhm_sizes[0] ); i++ ) |
Manuel Pégourié-Gonnard | 8271f2f | 2013-09-17 14:57:55 +0200 | [diff] [blame] | 794 | { |
Manuel Pégourié-Gonnard | 2cf5a7c | 2015-04-08 12:49:31 +0200 | [diff] [blame] | 795 | mbedtls_dhm_init( &dhm ); |
Manuel Pégourié-Gonnard | 8271f2f | 2013-09-17 14:57:55 +0200 | [diff] [blame] | 796 | |
Hanno Becker | b953921 | 2017-10-04 13:13:34 +0100 | [diff] [blame] | 797 | if( mbedtls_mpi_read_binary( &dhm.P, dhm_P[i], |
| 798 | dhm_P_size[i] ) != 0 || |
| 799 | mbedtls_mpi_read_binary( &dhm.G, dhm_G[i], |
| 800 | dhm_G_size[i] ) != 0 ) |
Paul Bakker | cbe3d0d | 2014-04-17 16:00:59 +0200 | [diff] [blame] | 801 | { |
Manuel Pégourié-Gonnard | 2cf5a7c | 2015-04-08 12:49:31 +0200 | [diff] [blame] | 802 | mbedtls_exit( 1 ); |
Paul Bakker | cbe3d0d | 2014-04-17 16:00:59 +0200 | [diff] [blame] | 803 | } |
| 804 | |
Manuel Pégourié-Gonnard | 2cf5a7c | 2015-04-08 12:49:31 +0200 | [diff] [blame] | 805 | dhm.len = mbedtls_mpi_size( &dhm.P ); |
| 806 | mbedtls_dhm_make_public( &dhm, (int) dhm.len, buf, dhm.len, myrand, NULL ); |
| 807 | if( mbedtls_mpi_copy( &dhm.GY, &dhm.GX ) != 0 ) |
| 808 | mbedtls_exit( 1 ); |
Manuel Pégourié-Gonnard | 8271f2f | 2013-09-17 14:57:55 +0200 | [diff] [blame] | 809 | |
Manuel Pégourié-Gonnard | 2cf5a7c | 2015-04-08 12:49:31 +0200 | [diff] [blame] | 810 | mbedtls_snprintf( title, sizeof( title ), "DHE-%d", dhm_sizes[i] ); |
Manuel Pégourié-Gonnard | 8271f2f | 2013-09-17 14:57:55 +0200 | [diff] [blame] | 811 | TIME_PUBLIC( title, "handshake", |
Manuel Pégourié-Gonnard | 2cf5a7c | 2015-04-08 12:49:31 +0200 | [diff] [blame] | 812 | ret |= mbedtls_dhm_make_public( &dhm, (int) dhm.len, buf, dhm.len, |
Manuel Pégourié-Gonnard | 8271f2f | 2013-09-17 14:57:55 +0200 | [diff] [blame] | 813 | myrand, NULL ); |
Manuel Pégourié-Gonnard | 3335205 | 2015-06-02 16:17:08 +0100 | [diff] [blame] | 814 | ret |= mbedtls_dhm_calc_secret( &dhm, buf, sizeof( buf ), &olen, myrand, NULL ) ); |
Manuel Pégourié-Gonnard | 8271f2f | 2013-09-17 14:57:55 +0200 | [diff] [blame] | 815 | |
Manuel Pégourié-Gonnard | 2cf5a7c | 2015-04-08 12:49:31 +0200 | [diff] [blame] | 816 | mbedtls_snprintf( title, sizeof( title ), "DH-%d", dhm_sizes[i] ); |
Manuel Pégourié-Gonnard | 8271f2f | 2013-09-17 14:57:55 +0200 | [diff] [blame] | 817 | TIME_PUBLIC( title, "handshake", |
Manuel Pégourié-Gonnard | 3335205 | 2015-06-02 16:17:08 +0100 | [diff] [blame] | 818 | ret |= mbedtls_dhm_calc_secret( &dhm, buf, sizeof( buf ), &olen, myrand, NULL ) ); |
Manuel Pégourié-Gonnard | 8271f2f | 2013-09-17 14:57:55 +0200 | [diff] [blame] | 819 | |
Manuel Pégourié-Gonnard | 2cf5a7c | 2015-04-08 12:49:31 +0200 | [diff] [blame] | 820 | mbedtls_dhm_free( &dhm ); |
Manuel Pégourié-Gonnard | 8271f2f | 2013-09-17 14:57:55 +0200 | [diff] [blame] | 821 | } |
Manuel Pégourié-Gonnard | e870c0a | 2012-11-08 11:31:48 +0100 | [diff] [blame] | 822 | } |
Manuel Pégourié-Gonnard | e870c0a | 2012-11-08 11:31:48 +0100 | [diff] [blame] | 823 | #endif |
| 824 | |
Manuel Pégourié-Gonnard | 2cf5a7c | 2015-04-08 12:49:31 +0200 | [diff] [blame] | 825 | #if defined(MBEDTLS_ECDSA_C) && defined(MBEDTLS_SHA256_C) |
Manuel Pégourié-Gonnard | cc34f95 | 2013-09-17 16:04:08 +0200 | [diff] [blame] | 826 | if( todo.ecdsa ) |
| 827 | { |
Manuel Pégourié-Gonnard | 2cf5a7c | 2015-04-08 12:49:31 +0200 | [diff] [blame] | 828 | mbedtls_ecdsa_context ecdsa; |
| 829 | const mbedtls_ecp_curve_info *curve_info; |
Manuel Pégourié-Gonnard | cc34f95 | 2013-09-17 16:04:08 +0200 | [diff] [blame] | 830 | size_t sig_len; |
| 831 | |
| 832 | memset( buf, 0x2A, sizeof( buf ) ); |
| 833 | |
Manuel Pégourié-Gonnard | 2cf5a7c | 2015-04-08 12:49:31 +0200 | [diff] [blame] | 834 | for( curve_info = mbedtls_ecp_curve_list(); |
| 835 | curve_info->grp_id != MBEDTLS_ECP_DP_NONE; |
Manuel Pégourié-Gonnard | cc34f95 | 2013-09-17 16:04:08 +0200 | [diff] [blame] | 836 | curve_info++ ) |
| 837 | { |
Manuel Pégourié-Gonnard | 2cf5a7c | 2015-04-08 12:49:31 +0200 | [diff] [blame] | 838 | mbedtls_ecdsa_init( &ecdsa ); |
Manuel Pégourié-Gonnard | cc34f95 | 2013-09-17 16:04:08 +0200 | [diff] [blame] | 839 | |
Manuel Pégourié-Gonnard | 2cf5a7c | 2015-04-08 12:49:31 +0200 | [diff] [blame] | 840 | if( mbedtls_ecdsa_genkey( &ecdsa, curve_info->grp_id, myrand, NULL ) != 0 ) |
| 841 | mbedtls_exit( 1 ); |
Manuel Pégourié-Gonnard | 50da048 | 2014-12-19 12:10:37 +0100 | [diff] [blame] | 842 | ecp_clear_precomputed( &ecdsa.grp ); |
Manuel Pégourié-Gonnard | cc34f95 | 2013-09-17 16:04:08 +0200 | [diff] [blame] | 843 | |
Manuel Pégourié-Gonnard | 2cf5a7c | 2015-04-08 12:49:31 +0200 | [diff] [blame] | 844 | mbedtls_snprintf( title, sizeof( title ), "ECDSA-%s", |
Manuel Pégourié-Gonnard | 56cd319 | 2013-09-17 17:23:07 +0200 | [diff] [blame] | 845 | curve_info->name ); |
Manuel Pégourié-Gonnard | cc34f95 | 2013-09-17 16:04:08 +0200 | [diff] [blame] | 846 | TIME_PUBLIC( title, "sign", |
Manuel Pégourié-Gonnard | 797f48a | 2015-06-18 15:45:05 +0200 | [diff] [blame] | 847 | ret = mbedtls_ecdsa_write_signature( &ecdsa, MBEDTLS_MD_SHA256, buf, curve_info->bit_size, |
Manuel Pégourié-Gonnard | 56cd319 | 2013-09-17 17:23:07 +0200 | [diff] [blame] | 848 | tmp, &sig_len, myrand, NULL ) ); |
| 849 | |
Manuel Pégourié-Gonnard | 2cf5a7c | 2015-04-08 12:49:31 +0200 | [diff] [blame] | 850 | mbedtls_ecdsa_free( &ecdsa ); |
Manuel Pégourié-Gonnard | 50da048 | 2014-12-19 12:10:37 +0100 | [diff] [blame] | 851 | } |
| 852 | |
Manuel Pégourié-Gonnard | 2cf5a7c | 2015-04-08 12:49:31 +0200 | [diff] [blame] | 853 | for( curve_info = mbedtls_ecp_curve_list(); |
| 854 | curve_info->grp_id != MBEDTLS_ECP_DP_NONE; |
Manuel Pégourié-Gonnard | 50da048 | 2014-12-19 12:10:37 +0100 | [diff] [blame] | 855 | curve_info++ ) |
| 856 | { |
Manuel Pégourié-Gonnard | 2cf5a7c | 2015-04-08 12:49:31 +0200 | [diff] [blame] | 857 | mbedtls_ecdsa_init( &ecdsa ); |
Manuel Pégourié-Gonnard | 50da048 | 2014-12-19 12:10:37 +0100 | [diff] [blame] | 858 | |
Manuel Pégourié-Gonnard | 2cf5a7c | 2015-04-08 12:49:31 +0200 | [diff] [blame] | 859 | if( mbedtls_ecdsa_genkey( &ecdsa, curve_info->grp_id, myrand, NULL ) != 0 || |
Manuel Pégourié-Gonnard | 797f48a | 2015-06-18 15:45:05 +0200 | [diff] [blame] | 860 | mbedtls_ecdsa_write_signature( &ecdsa, MBEDTLS_MD_SHA256, buf, curve_info->bit_size, |
Manuel Pégourié-Gonnard | 50da048 | 2014-12-19 12:10:37 +0100 | [diff] [blame] | 861 | tmp, &sig_len, myrand, NULL ) != 0 ) |
| 862 | { |
Manuel Pégourié-Gonnard | 2cf5a7c | 2015-04-08 12:49:31 +0200 | [diff] [blame] | 863 | mbedtls_exit( 1 ); |
Manuel Pégourié-Gonnard | 50da048 | 2014-12-19 12:10:37 +0100 | [diff] [blame] | 864 | } |
| 865 | ecp_clear_precomputed( &ecdsa.grp ); |
| 866 | |
Manuel Pégourié-Gonnard | 2cf5a7c | 2015-04-08 12:49:31 +0200 | [diff] [blame] | 867 | mbedtls_snprintf( title, sizeof( title ), "ECDSA-%s", |
Manuel Pégourié-Gonnard | 50da048 | 2014-12-19 12:10:37 +0100 | [diff] [blame] | 868 | curve_info->name ); |
Manuel Pégourié-Gonnard | 56cd319 | 2013-09-17 17:23:07 +0200 | [diff] [blame] | 869 | TIME_PUBLIC( title, "verify", |
Manuel Pégourié-Gonnard | 797f48a | 2015-06-18 15:45:05 +0200 | [diff] [blame] | 870 | ret = mbedtls_ecdsa_read_signature( &ecdsa, buf, curve_info->bit_size, |
Manuel Pégourié-Gonnard | 56cd319 | 2013-09-17 17:23:07 +0200 | [diff] [blame] | 871 | tmp, sig_len ) ); |
Manuel Pégourié-Gonnard | cc34f95 | 2013-09-17 16:04:08 +0200 | [diff] [blame] | 872 | |
Manuel Pégourié-Gonnard | 2cf5a7c | 2015-04-08 12:49:31 +0200 | [diff] [blame] | 873 | mbedtls_ecdsa_free( &ecdsa ); |
Manuel Pégourié-Gonnard | cc34f95 | 2013-09-17 16:04:08 +0200 | [diff] [blame] | 874 | } |
| 875 | } |
| 876 | #endif |
| 877 | |
Janos Follath | 52735ef | 2018-08-15 10:19:16 +0100 | [diff] [blame] | 878 | #if defined(MBEDTLS_ECDH_C) && defined(MBEDTLS_ECDH_LEGACY_CONTEXT) |
Manuel Pégourié-Gonnard | cc34f95 | 2013-09-17 16:04:08 +0200 | [diff] [blame] | 879 | if( todo.ecdh ) |
| 880 | { |
Manuel Pégourié-Gonnard | 2cf5a7c | 2015-04-08 12:49:31 +0200 | [diff] [blame] | 881 | mbedtls_ecdh_context ecdh; |
Manuel Pégourié-Gonnard | 2cf5a7c | 2015-04-08 12:49:31 +0200 | [diff] [blame] | 882 | mbedtls_mpi z; |
Nicholas Wilson | 08f3ef1 | 2015-11-10 13:10:01 +0000 | [diff] [blame] | 883 | const mbedtls_ecp_curve_info montgomery_curve_list[] = { |
| 884 | #if defined(MBEDTLS_ECP_DP_CURVE25519_ENABLED) |
| 885 | { MBEDTLS_ECP_DP_CURVE25519, 0, 0, "Curve25519" }, |
Manuel Pégourié-Gonnard | 85391f2 | 2015-02-05 09:54:48 +0000 | [diff] [blame] | 886 | #endif |
Nicholas Wilson | 08f3ef1 | 2015-11-10 13:10:01 +0000 | [diff] [blame] | 887 | #if defined(MBEDTLS_ECP_DP_CURVE448_ENABLED) |
| 888 | { MBEDTLS_ECP_DP_CURVE448, 0, 0, "Curve448" }, |
| 889 | #endif |
| 890 | { MBEDTLS_ECP_DP_NONE, 0, 0, 0 } |
| 891 | }; |
Manuel Pégourié-Gonnard | 2cf5a7c | 2015-04-08 12:49:31 +0200 | [diff] [blame] | 892 | const mbedtls_ecp_curve_info *curve_info; |
Manuel Pégourié-Gonnard | cc34f95 | 2013-09-17 16:04:08 +0200 | [diff] [blame] | 893 | size_t olen; |
| 894 | |
Manuel Pégourié-Gonnard | 2cf5a7c | 2015-04-08 12:49:31 +0200 | [diff] [blame] | 895 | for( curve_info = mbedtls_ecp_curve_list(); |
| 896 | curve_info->grp_id != MBEDTLS_ECP_DP_NONE; |
Manuel Pégourié-Gonnard | cc34f95 | 2013-09-17 16:04:08 +0200 | [diff] [blame] | 897 | curve_info++ ) |
| 898 | { |
Manuel Pégourié-Gonnard | 2cf5a7c | 2015-04-08 12:49:31 +0200 | [diff] [blame] | 899 | mbedtls_ecdh_init( &ecdh ); |
Manuel Pégourié-Gonnard | cc34f95 | 2013-09-17 16:04:08 +0200 | [diff] [blame] | 900 | |
Manuel Pégourié-Gonnard | e3a062b | 2015-05-11 18:46:47 +0200 | [diff] [blame] | 901 | if( mbedtls_ecp_group_load( &ecdh.grp, curve_info->grp_id ) != 0 || |
Manuel Pégourié-Gonnard | 2cf5a7c | 2015-04-08 12:49:31 +0200 | [diff] [blame] | 902 | mbedtls_ecdh_make_public( &ecdh, &olen, buf, sizeof( buf), |
Manuel Pégourié-Gonnard | cc34f95 | 2013-09-17 16:04:08 +0200 | [diff] [blame] | 903 | myrand, NULL ) != 0 || |
Manuel Pégourié-Gonnard | 2cf5a7c | 2015-04-08 12:49:31 +0200 | [diff] [blame] | 904 | mbedtls_ecp_copy( &ecdh.Qp, &ecdh.Q ) != 0 ) |
Manuel Pégourié-Gonnard | cc34f95 | 2013-09-17 16:04:08 +0200 | [diff] [blame] | 905 | { |
Manuel Pégourié-Gonnard | 2cf5a7c | 2015-04-08 12:49:31 +0200 | [diff] [blame] | 906 | mbedtls_exit( 1 ); |
Manuel Pégourié-Gonnard | cc34f95 | 2013-09-17 16:04:08 +0200 | [diff] [blame] | 907 | } |
Manuel Pégourié-Gonnard | 50da048 | 2014-12-19 12:10:37 +0100 | [diff] [blame] | 908 | ecp_clear_precomputed( &ecdh.grp ); |
Manuel Pégourié-Gonnard | cc34f95 | 2013-09-17 16:04:08 +0200 | [diff] [blame] | 909 | |
Manuel Pégourié-Gonnard | 2cf5a7c | 2015-04-08 12:49:31 +0200 | [diff] [blame] | 910 | mbedtls_snprintf( title, sizeof( title ), "ECDHE-%s", |
Manuel Pégourié-Gonnard | 56cd319 | 2013-09-17 17:23:07 +0200 | [diff] [blame] | 911 | curve_info->name ); |
Manuel Pégourié-Gonnard | cc34f95 | 2013-09-17 16:04:08 +0200 | [diff] [blame] | 912 | TIME_PUBLIC( title, "handshake", |
Manuel Pégourié-Gonnard | 2cf5a7c | 2015-04-08 12:49:31 +0200 | [diff] [blame] | 913 | ret |= mbedtls_ecdh_make_public( &ecdh, &olen, buf, sizeof( buf), |
Manuel Pégourié-Gonnard | cc34f95 | 2013-09-17 16:04:08 +0200 | [diff] [blame] | 914 | myrand, NULL ); |
Manuel Pégourié-Gonnard | 2cf5a7c | 2015-04-08 12:49:31 +0200 | [diff] [blame] | 915 | ret |= mbedtls_ecdh_calc_secret( &ecdh, &olen, buf, sizeof( buf ), |
Manuel Pégourié-Gonnard | cc34f95 | 2013-09-17 16:04:08 +0200 | [diff] [blame] | 916 | myrand, NULL ) ); |
Manuel Pégourié-Gonnard | 2cf5a7c | 2015-04-08 12:49:31 +0200 | [diff] [blame] | 917 | mbedtls_ecdh_free( &ecdh ); |
Manuel Pégourié-Gonnard | 50da048 | 2014-12-19 12:10:37 +0100 | [diff] [blame] | 918 | } |
| 919 | |
Nicholas Wilson | 08f3ef1 | 2015-11-10 13:10:01 +0000 | [diff] [blame] | 920 | /* Montgomery curves need to be handled separately */ |
| 921 | for ( curve_info = montgomery_curve_list; |
| 922 | curve_info->grp_id != MBEDTLS_ECP_DP_NONE; |
| 923 | curve_info++ ) |
Manuel Pégourié-Gonnard | 85391f2 | 2015-02-05 09:54:48 +0000 | [diff] [blame] | 924 | { |
Nicholas Wilson | 08f3ef1 | 2015-11-10 13:10:01 +0000 | [diff] [blame] | 925 | mbedtls_ecdh_init( &ecdh ); |
| 926 | mbedtls_mpi_init( &z ); |
| 927 | |
| 928 | if( mbedtls_ecp_group_load( &ecdh.grp, curve_info->grp_id ) != 0 || |
| 929 | mbedtls_ecdh_gen_public( &ecdh.grp, &ecdh.d, &ecdh.Qp, myrand, NULL ) != 0 ) |
| 930 | { |
| 931 | mbedtls_exit( 1 ); |
| 932 | } |
| 933 | |
| 934 | mbedtls_snprintf( title, sizeof(title), "ECDHE-%s", |
| 935 | curve_info->name ); |
| 936 | TIME_PUBLIC( title, "handshake", |
| 937 | ret |= mbedtls_ecdh_gen_public( &ecdh.grp, &ecdh.d, &ecdh.Q, |
| 938 | myrand, NULL ); |
| 939 | ret |= mbedtls_ecdh_compute_shared( &ecdh.grp, &z, &ecdh.Qp, &ecdh.d, |
| 940 | myrand, NULL ) ); |
| 941 | |
| 942 | mbedtls_ecdh_free( &ecdh ); |
| 943 | mbedtls_mpi_free( &z ); |
Manuel Pégourié-Gonnard | 85391f2 | 2015-02-05 09:54:48 +0000 | [diff] [blame] | 944 | } |
| 945 | |
Manuel Pégourié-Gonnard | 2cf5a7c | 2015-04-08 12:49:31 +0200 | [diff] [blame] | 946 | for( curve_info = mbedtls_ecp_curve_list(); |
| 947 | curve_info->grp_id != MBEDTLS_ECP_DP_NONE; |
Manuel Pégourié-Gonnard | 50da048 | 2014-12-19 12:10:37 +0100 | [diff] [blame] | 948 | curve_info++ ) |
| 949 | { |
Manuel Pégourié-Gonnard | 2cf5a7c | 2015-04-08 12:49:31 +0200 | [diff] [blame] | 950 | mbedtls_ecdh_init( &ecdh ); |
Manuel Pégourié-Gonnard | 50da048 | 2014-12-19 12:10:37 +0100 | [diff] [blame] | 951 | |
Manuel Pégourié-Gonnard | e3a062b | 2015-05-11 18:46:47 +0200 | [diff] [blame] | 952 | if( mbedtls_ecp_group_load( &ecdh.grp, curve_info->grp_id ) != 0 || |
Manuel Pégourié-Gonnard | 2cf5a7c | 2015-04-08 12:49:31 +0200 | [diff] [blame] | 953 | mbedtls_ecdh_make_public( &ecdh, &olen, buf, sizeof( buf), |
Manuel Pégourié-Gonnard | 50da048 | 2014-12-19 12:10:37 +0100 | [diff] [blame] | 954 | myrand, NULL ) != 0 || |
Manuel Pégourié-Gonnard | 2cf5a7c | 2015-04-08 12:49:31 +0200 | [diff] [blame] | 955 | mbedtls_ecp_copy( &ecdh.Qp, &ecdh.Q ) != 0 || |
| 956 | mbedtls_ecdh_make_public( &ecdh, &olen, buf, sizeof( buf), |
Manuel Pégourié-Gonnard | 50da048 | 2014-12-19 12:10:37 +0100 | [diff] [blame] | 957 | myrand, NULL ) != 0 ) |
| 958 | { |
Manuel Pégourié-Gonnard | 2cf5a7c | 2015-04-08 12:49:31 +0200 | [diff] [blame] | 959 | mbedtls_exit( 1 ); |
Manuel Pégourié-Gonnard | 50da048 | 2014-12-19 12:10:37 +0100 | [diff] [blame] | 960 | } |
| 961 | ecp_clear_precomputed( &ecdh.grp ); |
Manuel Pégourié-Gonnard | cc34f95 | 2013-09-17 16:04:08 +0200 | [diff] [blame] | 962 | |
Manuel Pégourié-Gonnard | 2cf5a7c | 2015-04-08 12:49:31 +0200 | [diff] [blame] | 963 | mbedtls_snprintf( title, sizeof( title ), "ECDH-%s", |
Manuel Pégourié-Gonnard | 56cd319 | 2013-09-17 17:23:07 +0200 | [diff] [blame] | 964 | curve_info->name ); |
Manuel Pégourié-Gonnard | cc34f95 | 2013-09-17 16:04:08 +0200 | [diff] [blame] | 965 | TIME_PUBLIC( title, "handshake", |
Manuel Pégourié-Gonnard | 2cf5a7c | 2015-04-08 12:49:31 +0200 | [diff] [blame] | 966 | ret |= mbedtls_ecdh_calc_secret( &ecdh, &olen, buf, sizeof( buf ), |
Manuel Pégourié-Gonnard | cc34f95 | 2013-09-17 16:04:08 +0200 | [diff] [blame] | 967 | myrand, NULL ) ); |
Manuel Pégourié-Gonnard | 2cf5a7c | 2015-04-08 12:49:31 +0200 | [diff] [blame] | 968 | mbedtls_ecdh_free( &ecdh ); |
Manuel Pégourié-Gonnard | cc34f95 | 2013-09-17 16:04:08 +0200 | [diff] [blame] | 969 | } |
Manuel Pégourié-Gonnard | 85391f2 | 2015-02-05 09:54:48 +0000 | [diff] [blame] | 970 | |
Nicholas Wilson | 08f3ef1 | 2015-11-10 13:10:01 +0000 | [diff] [blame] | 971 | /* Montgomery curves need to be handled separately */ |
| 972 | for ( curve_info = montgomery_curve_list; |
| 973 | curve_info->grp_id != MBEDTLS_ECP_DP_NONE; |
| 974 | curve_info++) |
Manuel Pégourié-Gonnard | 85391f2 | 2015-02-05 09:54:48 +0000 | [diff] [blame] | 975 | { |
Nicholas Wilson | 08f3ef1 | 2015-11-10 13:10:01 +0000 | [diff] [blame] | 976 | mbedtls_ecdh_init( &ecdh ); |
| 977 | mbedtls_mpi_init( &z ); |
| 978 | |
| 979 | if( mbedtls_ecp_group_load( &ecdh.grp, curve_info->grp_id ) != 0 || |
| 980 | mbedtls_ecdh_gen_public( &ecdh.grp, &ecdh.d, &ecdh.Qp, |
| 981 | myrand, NULL ) != 0 || |
| 982 | mbedtls_ecdh_gen_public( &ecdh.grp, &ecdh.d, &ecdh.Q, myrand, NULL ) != 0 ) |
| 983 | { |
| 984 | mbedtls_exit( 1 ); |
| 985 | } |
| 986 | |
| 987 | mbedtls_snprintf( title, sizeof(title), "ECDH-%s", |
| 988 | curve_info->name ); |
| 989 | TIME_PUBLIC( title, "handshake", |
| 990 | ret |= mbedtls_ecdh_compute_shared( &ecdh.grp, &z, &ecdh.Qp, &ecdh.d, |
| 991 | myrand, NULL ) ); |
| 992 | |
| 993 | mbedtls_ecdh_free( &ecdh ); |
| 994 | mbedtls_mpi_free( &z ); |
Manuel Pégourié-Gonnard | 85391f2 | 2015-02-05 09:54:48 +0000 | [diff] [blame] | 995 | } |
Manuel Pégourié-Gonnard | cc34f95 | 2013-09-17 16:04:08 +0200 | [diff] [blame] | 996 | } |
| 997 | #endif |
Manuel Pégourié-Gonnard | 50da048 | 2014-12-19 12:10:37 +0100 | [diff] [blame] | 998 | |
Christoph M. Wintersteiger | c3cbdde | 2018-12-14 11:03:02 +0000 | [diff] [blame] | 999 | #if defined(MBEDTLS_ECDH_C) |
Christoph M. Wintersteiger | 696deda | 2018-10-25 12:47:18 +0100 | [diff] [blame] | 1000 | if( todo.ecdh ) |
| 1001 | { |
| 1002 | mbedtls_ecdh_context ecdh_srv, ecdh_cli; |
| 1003 | unsigned char buf_srv[BUFSIZE], buf_cli[BUFSIZE]; |
| 1004 | const mbedtls_ecp_curve_info * curve_list = mbedtls_ecp_curve_list(); |
| 1005 | const mbedtls_ecp_curve_info *curve_info; |
| 1006 | size_t olen; |
| 1007 | |
| 1008 | for( curve_info = curve_list; |
| 1009 | curve_info->grp_id != MBEDTLS_ECP_DP_NONE; |
| 1010 | curve_info++ ) |
| 1011 | { |
| 1012 | mbedtls_ecdh_init( &ecdh_srv ); |
| 1013 | mbedtls_ecdh_init( &ecdh_cli ); |
Christoph M. Wintersteiger | 3c44962 | 2018-12-14 11:54:59 +0000 | [diff] [blame^] | 1014 | check( mbedtls_ecdh_setup( &ecdh_srv, curve_info->grp_id ) ); |
| 1015 | check( mbedtls_ecdh_setup( &ecdh_cli, curve_info->grp_id ) ); |
Christoph M. Wintersteiger | 696deda | 2018-10-25 12:47:18 +0100 | [diff] [blame] | 1016 | |
Christoph M. Wintersteiger | 79acf95 | 2018-12-07 13:32:59 +0000 | [diff] [blame] | 1017 | #if defined(MBEDTLS_ECDH_LEGACY_CONTEXT) |
| 1018 | if (mbedtls_ecp_group_load(&ecdh_srv.grp, curve_info->grp_id) != 0 || |
| 1019 | mbedtls_ecdh_gen_public(&ecdh_srv.grp, |
| 1020 | &ecdh_srv.d, |
| 1021 | &ecdh_srv.Q, myrand, NULL) != 0) |
| 1022 | #else |
Christoph M. Wintersteiger | 696deda | 2018-10-25 12:47:18 +0100 | [diff] [blame] | 1023 | if( ecdh_srv.var == MBEDTLS_ECDH_VARIANT_MBEDTLS_2_0 && ( |
| 1024 | mbedtls_ecp_group_load( &ecdh_srv.ctx.mbed_ecdh.grp, curve_info->grp_id ) != 0 || |
| 1025 | mbedtls_ecdh_gen_public( &ecdh_srv.ctx.mbed_ecdh.grp, |
| 1026 | &ecdh_srv.ctx.mbed_ecdh.d, |
| 1027 | &ecdh_srv.ctx.mbed_ecdh.Q, myrand, NULL ) != 0 )) |
Christoph M. Wintersteiger | 79acf95 | 2018-12-07 13:32:59 +0000 | [diff] [blame] | 1028 | #endif |
Christoph M. Wintersteiger | 696deda | 2018-10-25 12:47:18 +0100 | [diff] [blame] | 1029 | mbedtls_exit( 1 ); |
| 1030 | |
| 1031 | mbedtls_snprintf( title, sizeof( title ), "ECDHE-%s", curve_info->name ); |
Christoph M. Wintersteiger | 65bab97 | 2018-12-06 17:15:12 +0000 | [diff] [blame] | 1032 | TIME_PUBLIC( title, "full handshake", |
Christoph M. Wintersteiger | 696deda | 2018-10-25 12:47:18 +0100 | [diff] [blame] | 1033 | const unsigned char * p_srv = buf_srv; |
Christoph M. Wintersteiger | 3c44962 | 2018-12-14 11:54:59 +0000 | [diff] [blame^] | 1034 | check( mbedtls_ecdh_make_params( &ecdh_srv, &olen, buf_srv, sizeof( buf_srv ), myrand, NULL ) ); |
Christoph M. Wintersteiger | 696deda | 2018-10-25 12:47:18 +0100 | [diff] [blame] | 1035 | |
Christoph M. Wintersteiger | 3c44962 | 2018-12-14 11:54:59 +0000 | [diff] [blame^] | 1036 | check( mbedtls_ecdh_read_params( &ecdh_cli, &p_srv, p_srv + olen ) ); |
| 1037 | check( mbedtls_ecdh_make_public( &ecdh_cli, &olen, buf_cli, sizeof( buf_cli ), myrand, NULL ) ); |
Christoph M. Wintersteiger | 696deda | 2018-10-25 12:47:18 +0100 | [diff] [blame] | 1038 | |
Christoph M. Wintersteiger | 3c44962 | 2018-12-14 11:54:59 +0000 | [diff] [blame^] | 1039 | check( mbedtls_ecdh_read_public( &ecdh_srv, buf_cli, olen ) ); |
| 1040 | check( mbedtls_ecdh_calc_secret( &ecdh_srv, &olen, buf_srv, sizeof( buf_srv ), myrand, NULL ) ); |
Christoph M. Wintersteiger | 696deda | 2018-10-25 12:47:18 +0100 | [diff] [blame] | 1041 | |
Christoph M. Wintersteiger | 3c44962 | 2018-12-14 11:54:59 +0000 | [diff] [blame^] | 1042 | check( mbedtls_ecdh_calc_secret( &ecdh_cli, &olen, buf_cli, sizeof( buf_cli ), myrand, NULL ) ); |
Christoph M. Wintersteiger | 696deda | 2018-10-25 12:47:18 +0100 | [diff] [blame] | 1043 | ); |
| 1044 | |
| 1045 | mbedtls_ecdh_free( &ecdh_srv ); |
| 1046 | mbedtls_ecdh_free( &ecdh_cli ); |
| 1047 | } |
| 1048 | } |
| 1049 | #endif |
| 1050 | |
Manuel Pégourié-Gonnard | 2cf5a7c | 2015-04-08 12:49:31 +0200 | [diff] [blame] | 1051 | mbedtls_printf( "\n" ); |
Paul Bakker | 1d4da2e | 2009-10-25 12:36:53 +0000 | [diff] [blame] | 1052 | |
Manuel Pégourié-Gonnard | 2cf5a7c | 2015-04-08 12:49:31 +0200 | [diff] [blame] | 1053 | #if defined(MBEDTLS_MEMORY_BUFFER_ALLOC_C) |
| 1054 | mbedtls_memory_buffer_alloc_free(); |
Manuel Pégourié-Gonnard | 128657d | 2014-12-18 16:35:52 +0000 | [diff] [blame] | 1055 | #endif |
| 1056 | |
Paul Bakker | cce9d77 | 2011-11-18 14:26:47 +0000 | [diff] [blame] | 1057 | #if defined(_WIN32) |
Manuel Pégourié-Gonnard | 2cf5a7c | 2015-04-08 12:49:31 +0200 | [diff] [blame] | 1058 | mbedtls_printf( " Press Enter to exit this program.\n" ); |
Paul Bakker | 5121ce5 | 2009-01-03 21:22:43 +0000 | [diff] [blame] | 1059 | fflush( stdout ); getchar(); |
| 1060 | #endif |
| 1061 | |
| 1062 | return( 0 ); |
| 1063 | } |
Manuel Pégourié-Gonnard | 8271f2f | 2013-09-17 14:57:55 +0200 | [diff] [blame] | 1064 | |
Manuel Pégourié-Gonnard | 2cf5a7c | 2015-04-08 12:49:31 +0200 | [diff] [blame] | 1065 | #endif /* MBEDTLS_TIMING_C */ |