Paul Bakker | 5121ce5 | 2009-01-03 21:22:43 +0000 | [diff] [blame] | 1 | /* |
| 2 | * Benchmark demonstration program |
| 3 | * |
Manuel Pégourié-Gonnard | a658a40 | 2015-01-23 09:45:19 +0000 | [diff] [blame] | 4 | * Copyright (C) 2006-2013, ARM Limited, All Rights Reserved |
Paul Bakker | b96f154 | 2010-07-18 20:36:00 +0000 | [diff] [blame] | 5 | * |
Manuel Pégourié-Gonnard | fe44643 | 2015-03-06 13:17:10 +0000 | [diff] [blame] | 6 | * This file is part of mbed TLS (https://tls.mbed.org) |
Paul Bakker | b96f154 | 2010-07-18 20:36:00 +0000 | [diff] [blame] | 7 | * |
Paul Bakker | 5121ce5 | 2009-01-03 21:22:43 +0000 | [diff] [blame] | 8 | * This program is free software; you can redistribute it and/or modify |
| 9 | * it under the terms of the GNU General Public License as published by |
| 10 | * the Free Software Foundation; either version 2 of the License, or |
| 11 | * (at your option) any later version. |
| 12 | * |
| 13 | * This program is distributed in the hope that it will be useful, |
| 14 | * but WITHOUT ANY WARRANTY; without even the implied warranty of |
| 15 | * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the |
| 16 | * GNU General Public License for more details. |
| 17 | * |
| 18 | * You should have received a copy of the GNU General Public License along |
| 19 | * with this program; if not, write to the Free Software Foundation, Inc., |
| 20 | * 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA. |
| 21 | */ |
| 22 | |
Manuel Pégourié-Gonnard | 2cf5a7c | 2015-04-08 12:49:31 +0200 | [diff] [blame^] | 23 | #if !defined(MBEDTLS_CONFIG_FILE) |
Manuel Pégourié-Gonnard | 7f80997 | 2015-03-09 17:05:11 +0000 | [diff] [blame] | 24 | #include "mbedtls/config.h" |
Manuel Pégourié-Gonnard | cef4ad2 | 2014-04-29 12:39:06 +0200 | [diff] [blame] | 25 | #else |
Manuel Pégourié-Gonnard | 2cf5a7c | 2015-04-08 12:49:31 +0200 | [diff] [blame^] | 26 | #include MBEDTLS_CONFIG_FILE |
Manuel Pégourié-Gonnard | cef4ad2 | 2014-04-29 12:39:06 +0200 | [diff] [blame] | 27 | #endif |
Paul Bakker | 5121ce5 | 2009-01-03 21:22:43 +0000 | [diff] [blame] | 28 | |
Manuel Pégourié-Gonnard | 2cf5a7c | 2015-04-08 12:49:31 +0200 | [diff] [blame^] | 29 | #if defined(MBEDTLS_PLATFORM_C) |
Manuel Pégourié-Gonnard | 7f80997 | 2015-03-09 17:05:11 +0000 | [diff] [blame] | 30 | #include "mbedtls/platform.h" |
Rich Evans | f90016a | 2015-01-19 14:26:37 +0000 | [diff] [blame] | 31 | #else |
Rich Evans | 18b78c7 | 2015-02-11 14:06:19 +0000 | [diff] [blame] | 32 | #include <stdio.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 |
Rich Evans | f90016a | 2015-01-19 14:26:37 +0000 | [diff] [blame] | 37 | #endif |
| 38 | |
Manuel Pégourié-Gonnard | 2cf5a7c | 2015-04-08 12:49:31 +0200 | [diff] [blame^] | 39 | #if !defined(MBEDTLS_TIMING_C) |
Manuel Pégourié-Gonnard | 714929b | 2015-02-16 17:32:47 +0000 | [diff] [blame] | 40 | int main( void ) |
| 41 | { |
Manuel Pégourié-Gonnard | 2cf5a7c | 2015-04-08 12:49:31 +0200 | [diff] [blame^] | 42 | mbedtls_printf("MBEDTLS_TIMING_C not defined.\n"); |
Manuel Pégourié-Gonnard | 714929b | 2015-02-16 17:32:47 +0000 | [diff] [blame] | 43 | return( 0 ); |
| 44 | } |
| 45 | #else |
Manuel Pégourié-Gonnard | 50da048 | 2014-12-19 12:10:37 +0100 | [diff] [blame] | 46 | |
Manuel Pégourié-Gonnard | 714929b | 2015-02-16 17:32:47 +0000 | [diff] [blame] | 47 | #include <string.h> |
Manuel Pégourié-Gonnard | 50da048 | 2014-12-19 12:10:37 +0100 | [diff] [blame] | 48 | |
Manuel Pégourié-Gonnard | 7f80997 | 2015-03-09 17:05:11 +0000 | [diff] [blame] | 49 | #include "mbedtls/timing.h" |
Paul Bakker | 5121ce5 | 2009-01-03 21:22:43 +0000 | [diff] [blame] | 50 | |
Manuel Pégourié-Gonnard | 7f80997 | 2015-03-09 17:05:11 +0000 | [diff] [blame] | 51 | #include "mbedtls/md4.h" |
| 52 | #include "mbedtls/md5.h" |
| 53 | #include "mbedtls/ripemd160.h" |
| 54 | #include "mbedtls/sha1.h" |
| 55 | #include "mbedtls/sha256.h" |
| 56 | #include "mbedtls/sha512.h" |
| 57 | #include "mbedtls/arc4.h" |
| 58 | #include "mbedtls/des.h" |
| 59 | #include "mbedtls/aes.h" |
| 60 | #include "mbedtls/blowfish.h" |
| 61 | #include "mbedtls/camellia.h" |
| 62 | #include "mbedtls/gcm.h" |
| 63 | #include "mbedtls/ccm.h" |
| 64 | #include "mbedtls/havege.h" |
| 65 | #include "mbedtls/ctr_drbg.h" |
| 66 | #include "mbedtls/hmac_drbg.h" |
| 67 | #include "mbedtls/rsa.h" |
| 68 | #include "mbedtls/dhm.h" |
| 69 | #include "mbedtls/ecdsa.h" |
| 70 | #include "mbedtls/ecdh.h" |
| 71 | #include "mbedtls/error.h" |
Paul Bakker | 5121ce5 | 2009-01-03 21:22:43 +0000 | [diff] [blame] | 72 | |
Manuel Pégourié-Gonnard | 2cf5a7c | 2015-04-08 12:49:31 +0200 | [diff] [blame^] | 73 | #if defined(MBEDTLS_MEMORY_BUFFER_ALLOC_C) |
Manuel Pégourié-Gonnard | 7f80997 | 2015-03-09 17:05:11 +0000 | [diff] [blame] | 74 | #include "mbedtls/memory_buffer_alloc.h" |
Rich Evans | 18b78c7 | 2015-02-11 14:06:19 +0000 | [diff] [blame] | 75 | #endif |
| 76 | |
Manuel Pégourié-Gonnard | 2f77ce3 | 2013-10-03 11:59:57 +0200 | [diff] [blame] | 77 | #if defined _MSC_VER && !defined snprintf |
| 78 | #define snprintf _snprintf |
| 79 | #endif |
| 80 | |
Manuel Pégourié-Gonnard | 714929b | 2015-02-16 17:32:47 +0000 | [diff] [blame] | 81 | /* |
| 82 | * For heap usage estimates, we need an estimate of the overhead per allocated |
| 83 | * block. ptmalloc2/3 (used in gnu libc for instance) uses 2 size_t per block, |
| 84 | * so use that as our baseline. |
| 85 | */ |
| 86 | #define MEM_BLOCK_OVERHEAD ( 2 * sizeof( size_t ) ) |
| 87 | |
| 88 | /* |
| 89 | * Size to use for the malloc buffer if MEMORY_BUFFER_ALLOC_C is defined. |
| 90 | */ |
| 91 | #define HEAP_SIZE (1u << 16) // 64k |
| 92 | |
Paul Bakker | 02faf45 | 2011-11-29 11:23:58 +0000 | [diff] [blame] | 93 | #define BUFSIZE 1024 |
Manuel Pégourié-Gonnard | fef0f8f | 2014-01-30 20:59:00 +0100 | [diff] [blame] | 94 | #define HEADER_FORMAT " %-24s : " |
Gergely Budai | a5d336b | 2014-01-27 23:27:06 +0100 | [diff] [blame] | 95 | #define TITLE_LEN 25 |
Manuel Pégourié-Gonnard | 6c5abfa | 2015-02-13 14:12:07 +0000 | [diff] [blame] | 96 | |
Rich Evans | 85b05ec | 2015-02-12 11:37:29 +0000 | [diff] [blame] | 97 | #define DHM_SIZES 3 |
| 98 | |
| 99 | #define OPTIONS \ |
Manuel Pégourié-Gonnard | 2cf5a7c | 2015-04-08 12:49:31 +0200 | [diff] [blame^] | 100 | "mbedtls_md4, mbedtls_md5, mbedtls_ripemd160, mbedtls_sha1, mbedtls_sha256, mbedtls_sha512,\n" \ |
Rich Evans | 85b05ec | 2015-02-12 11:37:29 +0000 | [diff] [blame] | 101 | "arc4, des3, des, aes_cbc, aes_gcm, aes_ccm, camellia, blowfish,\n" \ |
| 102 | "havege, ctr_drbg, hmac_drbg\n" \ |
| 103 | "rsa, dhm, ecdsa, ecdh.\n" |
| 104 | |
Manuel Pégourié-Gonnard | 2cf5a7c | 2015-04-08 12:49:31 +0200 | [diff] [blame^] | 105 | #if defined(MBEDTLS_ERROR_C) |
Rich Evans | 85b05ec | 2015-02-12 11:37:29 +0000 | [diff] [blame] | 106 | #define PRINT_ERROR \ |
Manuel Pégourié-Gonnard | 2cf5a7c | 2015-04-08 12:49:31 +0200 | [diff] [blame^] | 107 | mbedtls_strerror( ret, ( char * )tmp, sizeof( tmp ) ); \ |
| 108 | mbedtls_printf( "FAILED: %s\n", tmp ); |
Rich Evans | 85b05ec | 2015-02-12 11:37:29 +0000 | [diff] [blame] | 109 | #else |
| 110 | #define PRINT_ERROR \ |
Manuel Pégourié-Gonnard | 2cf5a7c | 2015-04-08 12:49:31 +0200 | [diff] [blame^] | 111 | mbedtls_printf( "FAILED: -0x%04x\n", -ret ); |
Rich Evans | 85b05ec | 2015-02-12 11:37:29 +0000 | [diff] [blame] | 112 | #endif |
| 113 | |
| 114 | #define TIME_AND_TSC( TITLE, CODE ) \ |
| 115 | do { \ |
| 116 | unsigned long i, j, tsc; \ |
| 117 | \ |
Manuel Pégourié-Gonnard | 2cf5a7c | 2015-04-08 12:49:31 +0200 | [diff] [blame^] | 118 | mbedtls_printf( HEADER_FORMAT, TITLE ); \ |
Rich Evans | 85b05ec | 2015-02-12 11:37:29 +0000 | [diff] [blame] | 119 | fflush( stdout ); \ |
| 120 | \ |
Manuel Pégourié-Gonnard | 2cf5a7c | 2015-04-08 12:49:31 +0200 | [diff] [blame^] | 121 | mbedtls_set_alarm( 1 ); \ |
| 122 | for( i = 1; ! mbedtls_timing_alarmed; i++ ) \ |
Rich Evans | 85b05ec | 2015-02-12 11:37:29 +0000 | [diff] [blame] | 123 | { \ |
| 124 | CODE; \ |
| 125 | } \ |
| 126 | \ |
Manuel Pégourié-Gonnard | 2cf5a7c | 2015-04-08 12:49:31 +0200 | [diff] [blame^] | 127 | tsc = mbedtls_timing_hardclock(); \ |
Rich Evans | 85b05ec | 2015-02-12 11:37:29 +0000 | [diff] [blame] | 128 | for( j = 0; j < 1024; j++ ) \ |
| 129 | { \ |
| 130 | CODE; \ |
| 131 | } \ |
| 132 | \ |
Manuel Pégourié-Gonnard | 2cf5a7c | 2015-04-08 12:49:31 +0200 | [diff] [blame^] | 133 | mbedtls_printf( "%9lu Kb/s, %9lu cycles/byte\n", \ |
Manuel Pégourié-Gonnard | 7defc77 | 2015-02-05 11:42:42 +0100 | [diff] [blame] | 134 | i * BUFSIZE / 1024, \ |
Manuel Pégourié-Gonnard | 2cf5a7c | 2015-04-08 12:49:31 +0200 | [diff] [blame^] | 135 | ( mbedtls_timing_hardclock() - tsc ) / ( j * BUFSIZE ) ); \ |
Rich Evans | 85b05ec | 2015-02-12 11:37:29 +0000 | [diff] [blame] | 136 | } while( 0 ) |
| 137 | |
Manuel Pégourié-Gonnard | 2cf5a7c | 2015-04-08 12:49:31 +0200 | [diff] [blame^] | 138 | #if defined(MBEDTLS_ERROR_C) |
Manuel Pégourié-Gonnard | 50da048 | 2014-12-19 12:10:37 +0100 | [diff] [blame] | 139 | #define PRINT_ERROR \ |
Manuel Pégourié-Gonnard | 2cf5a7c | 2015-04-08 12:49:31 +0200 | [diff] [blame^] | 140 | mbedtls_strerror( ret, ( char * )tmp, sizeof( tmp ) ); \ |
| 141 | mbedtls_printf( "FAILED: %s\n", tmp ); |
Manuel Pégourié-Gonnard | 50da048 | 2014-12-19 12:10:37 +0100 | [diff] [blame] | 142 | #else |
| 143 | #define PRINT_ERROR \ |
Manuel Pégourié-Gonnard | 2cf5a7c | 2015-04-08 12:49:31 +0200 | [diff] [blame^] | 144 | mbedtls_printf( "FAILED: -0x%04x\n", -ret ); |
Manuel Pégourié-Gonnard | 50da048 | 2014-12-19 12:10:37 +0100 | [diff] [blame] | 145 | #endif |
| 146 | |
Manuel Pégourié-Gonnard | 2cf5a7c | 2015-04-08 12:49:31 +0200 | [diff] [blame^] | 147 | #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] | 148 | |
| 149 | #define MEMORY_MEASURE_INIT \ |
| 150 | size_t max_used, max_blocks, max_bytes; \ |
| 151 | size_t prv_used, prv_blocks; \ |
Manuel Pégourié-Gonnard | 2cf5a7c | 2015-04-08 12:49:31 +0200 | [diff] [blame^] | 152 | mbedtls_memory_buffer_alloc_cur_get( &prv_used, &prv_blocks ); \ |
| 153 | mbedtls_memory_buffer_alloc_max_reset( ); |
Manuel Pégourié-Gonnard | 50da048 | 2014-12-19 12:10:37 +0100 | [diff] [blame] | 154 | |
| 155 | #define MEMORY_MEASURE_PRINT( title_len ) \ |
Manuel Pégourié-Gonnard | 2cf5a7c | 2015-04-08 12:49:31 +0200 | [diff] [blame^] | 156 | mbedtls_memory_buffer_alloc_max_get( &max_used, &max_blocks ); \ |
| 157 | for( i = 12 - title_len; i != 0; i-- ) mbedtls_printf( " " ); \ |
Manuel Pégourié-Gonnard | 50da048 | 2014-12-19 12:10:37 +0100 | [diff] [blame] | 158 | max_used -= prv_used; \ |
| 159 | max_blocks -= prv_blocks; \ |
| 160 | max_bytes = max_used + MEM_BLOCK_OVERHEAD * max_blocks; \ |
Manuel Pégourié-Gonnard | 2cf5a7c | 2015-04-08 12:49:31 +0200 | [diff] [blame^] | 161 | mbedtls_printf( "%6u heap bytes", (unsigned) max_bytes ); |
Manuel Pégourié-Gonnard | 50da048 | 2014-12-19 12:10:37 +0100 | [diff] [blame] | 162 | |
| 163 | #else |
Manuel Pégourié-Gonnard | e579dab | 2015-01-29 16:28:44 +0000 | [diff] [blame] | 164 | #define MEMORY_MEASURE_INIT |
| 165 | #define MEMORY_MEASURE_PRINT( title_len ) |
Manuel Pégourié-Gonnard | 50da048 | 2014-12-19 12:10:37 +0100 | [diff] [blame] | 166 | #endif |
| 167 | |
Rich Evans | 85b05ec | 2015-02-12 11:37:29 +0000 | [diff] [blame] | 168 | #define TIME_PUBLIC( TITLE, TYPE, CODE ) \ |
| 169 | do { \ |
| 170 | unsigned long i; \ |
| 171 | int ret; \ |
Manuel Pégourié-Gonnard | 50da048 | 2014-12-19 12:10:37 +0100 | [diff] [blame] | 172 | MEMORY_MEASURE_INIT; \ |
Rich Evans | 85b05ec | 2015-02-12 11:37:29 +0000 | [diff] [blame] | 173 | \ |
Manuel Pégourié-Gonnard | 2cf5a7c | 2015-04-08 12:49:31 +0200 | [diff] [blame^] | 174 | mbedtls_printf( HEADER_FORMAT, TITLE ); \ |
Rich Evans | 85b05ec | 2015-02-12 11:37:29 +0000 | [diff] [blame] | 175 | fflush( stdout ); \ |
Manuel Pégourié-Gonnard | 2cf5a7c | 2015-04-08 12:49:31 +0200 | [diff] [blame^] | 176 | mbedtls_set_alarm( 3 ); \ |
Rich Evans | 85b05ec | 2015-02-12 11:37:29 +0000 | [diff] [blame] | 177 | \ |
| 178 | ret = 0; \ |
Manuel Pégourié-Gonnard | 2cf5a7c | 2015-04-08 12:49:31 +0200 | [diff] [blame^] | 179 | for( i = 1; ! mbedtls_timing_alarmed && ! ret ; i++ ) \ |
Rich Evans | 85b05ec | 2015-02-12 11:37:29 +0000 | [diff] [blame] | 180 | { \ |
| 181 | CODE; \ |
| 182 | } \ |
| 183 | \ |
| 184 | if( ret != 0 ) \ |
| 185 | { \ |
Manuel Pégourié-Gonnard | 50da048 | 2014-12-19 12:10:37 +0100 | [diff] [blame] | 186 | PRINT_ERROR; \ |
Rich Evans | 85b05ec | 2015-02-12 11:37:29 +0000 | [diff] [blame] | 187 | } \ |
| 188 | else \ |
Manuel Pégourié-Gonnard | 50da048 | 2014-12-19 12:10:37 +0100 | [diff] [blame] | 189 | { \ |
Manuel Pégourié-Gonnard | 2cf5a7c | 2015-04-08 12:49:31 +0200 | [diff] [blame^] | 190 | mbedtls_printf( "%6lu " TYPE "/s", i / 3 ); \ |
Manuel Pégourié-Gonnard | 50da048 | 2014-12-19 12:10:37 +0100 | [diff] [blame] | 191 | MEMORY_MEASURE_PRINT( sizeof( TYPE ) + 1 ); \ |
Manuel Pégourié-Gonnard | 2cf5a7c | 2015-04-08 12:49:31 +0200 | [diff] [blame^] | 192 | mbedtls_printf( "\n" ); \ |
Manuel Pégourié-Gonnard | 50da048 | 2014-12-19 12:10:37 +0100 | [diff] [blame] | 193 | } \ |
Rich Evans | 85b05ec | 2015-02-12 11:37:29 +0000 | [diff] [blame] | 194 | } while( 0 ) |
Paul Bakker | 5121ce5 | 2009-01-03 21:22:43 +0000 | [diff] [blame] | 195 | |
Paul Bakker | a3d195c | 2011-11-27 21:07:34 +0000 | [diff] [blame] | 196 | static int myrand( void *rng_state, unsigned char *output, size_t len ) |
Paul Bakker | 5121ce5 | 2009-01-03 21:22:43 +0000 | [diff] [blame] | 197 | { |
Paul Bakker | a3d195c | 2011-11-27 21:07:34 +0000 | [diff] [blame] | 198 | size_t use_len; |
| 199 | int rnd; |
| 200 | |
Paul Bakker | 5121ce5 | 2009-01-03 21:22:43 +0000 | [diff] [blame] | 201 | if( rng_state != NULL ) |
| 202 | rng_state = NULL; |
| 203 | |
Paul Bakker | a3d195c | 2011-11-27 21:07:34 +0000 | [diff] [blame] | 204 | while( len > 0 ) |
| 205 | { |
| 206 | use_len = len; |
| 207 | if( use_len > sizeof(int) ) |
| 208 | use_len = sizeof(int); |
| 209 | |
| 210 | rnd = rand(); |
| 211 | memcpy( output, &rnd, use_len ); |
| 212 | output += use_len; |
| 213 | len -= use_len; |
| 214 | } |
| 215 | |
| 216 | return( 0 ); |
Paul Bakker | 5121ce5 | 2009-01-03 21:22:43 +0000 | [diff] [blame] | 217 | } |
| 218 | |
Manuel Pégourié-Gonnard | 50da048 | 2014-12-19 12:10:37 +0100 | [diff] [blame] | 219 | /* |
| 220 | * Clear some memory that was used to prepare the context |
| 221 | */ |
Manuel Pégourié-Gonnard | 2cf5a7c | 2015-04-08 12:49:31 +0200 | [diff] [blame^] | 222 | #if defined(MBEDTLS_ECP_C) |
| 223 | void ecp_clear_precomputed( mbedtls_ecp_group *grp ) |
Manuel Pégourié-Gonnard | 50da048 | 2014-12-19 12:10:37 +0100 | [diff] [blame] | 224 | { |
| 225 | if( grp->T != NULL ) |
| 226 | { |
| 227 | size_t i; |
| 228 | for( i = 0; i < grp->T_size; i++ ) |
Manuel Pégourié-Gonnard | 2cf5a7c | 2015-04-08 12:49:31 +0200 | [diff] [blame^] | 229 | mbedtls_ecp_point_free( &grp->T[i] ); |
| 230 | mbedtls_free( grp->T ); |
Manuel Pégourié-Gonnard | 50da048 | 2014-12-19 12:10:37 +0100 | [diff] [blame] | 231 | } |
| 232 | grp->T = NULL; |
| 233 | grp->T_size = 0; |
| 234 | } |
| 235 | #else |
| 236 | #define ecp_clear_precomputed( g ) |
| 237 | #endif |
| 238 | |
Paul Bakker | 5121ce5 | 2009-01-03 21:22:43 +0000 | [diff] [blame] | 239 | unsigned char buf[BUFSIZE]; |
| 240 | |
Manuel Pégourié-Gonnard | ed7cbe9 | 2013-09-17 15:30:51 +0200 | [diff] [blame] | 241 | typedef struct { |
Manuel Pégourié-Gonnard | 2cf5a7c | 2015-04-08 12:49:31 +0200 | [diff] [blame^] | 242 | char mbedtls_md4, mbedtls_md5, mbedtls_ripemd160, mbedtls_sha1, mbedtls_sha256, mbedtls_sha512, |
Manuel Pégourié-Gonnard | 58d78a8 | 2014-05-07 12:03:02 +0200 | [diff] [blame] | 243 | arc4, des3, des, aes_cbc, aes_gcm, aes_ccm, camellia, blowfish, |
Manuel Pégourié-Gonnard | fef0f8f | 2014-01-30 20:59:00 +0100 | [diff] [blame] | 244 | havege, ctr_drbg, hmac_drbg, |
Manuel Pégourié-Gonnard | cc34f95 | 2013-09-17 16:04:08 +0200 | [diff] [blame] | 245 | rsa, dhm, ecdsa, ecdh; |
Manuel Pégourié-Gonnard | ed7cbe9 | 2013-09-17 15:30:51 +0200 | [diff] [blame] | 246 | } todo_list; |
| 247 | |
Paul Bakker | cce9d77 | 2011-11-18 14:26:47 +0000 | [diff] [blame] | 248 | int main( int argc, char *argv[] ) |
Paul Bakker | 5690efc | 2011-05-26 13:16:06 +0000 | [diff] [blame] | 249 | { |
Manuel Pégourié-Gonnard | 71e75dc | 2014-12-19 18:05:43 +0100 | [diff] [blame] | 250 | int i; |
Manuel Pégourié-Gonnard | cc34f95 | 2013-09-17 16:04:08 +0200 | [diff] [blame] | 251 | unsigned char tmp[200]; |
Manuel Pégourié-Gonnard | 8271f2f | 2013-09-17 14:57:55 +0200 | [diff] [blame] | 252 | char title[TITLE_LEN]; |
Manuel Pégourié-Gonnard | ed7cbe9 | 2013-09-17 15:30:51 +0200 | [diff] [blame] | 253 | todo_list todo; |
Manuel Pégourié-Gonnard | 2cf5a7c | 2015-04-08 12:49:31 +0200 | [diff] [blame^] | 254 | #if defined(MBEDTLS_MEMORY_BUFFER_ALLOC_C) |
Manuel Pégourié-Gonnard | 50da048 | 2014-12-19 12:10:37 +0100 | [diff] [blame] | 255 | unsigned char malloc_buf[HEAP_SIZE] = { 0 }; |
Manuel Pégourié-Gonnard | 128657d | 2014-12-18 16:35:52 +0000 | [diff] [blame] | 256 | #endif |
Paul Bakker | cce9d77 | 2011-11-18 14:26:47 +0000 | [diff] [blame] | 257 | |
Manuel Pégourié-Gonnard | c439e7b | 2015-03-03 13:12:00 +0000 | [diff] [blame] | 258 | if( argc <= 1 ) |
| 259 | { |
Manuel Pégourié-Gonnard | ed7cbe9 | 2013-09-17 15:30:51 +0200 | [diff] [blame] | 260 | memset( &todo, 1, sizeof( todo ) ); |
Manuel Pégourié-Gonnard | c439e7b | 2015-03-03 13:12:00 +0000 | [diff] [blame] | 261 | } |
Manuel Pégourié-Gonnard | ed7cbe9 | 2013-09-17 15:30:51 +0200 | [diff] [blame] | 262 | else |
| 263 | { |
| 264 | memset( &todo, 0, sizeof( todo ) ); |
| 265 | |
| 266 | for( i = 1; i < argc; i++ ) |
| 267 | { |
Manuel Pégourié-Gonnard | 2cf5a7c | 2015-04-08 12:49:31 +0200 | [diff] [blame^] | 268 | if( strcmp( argv[i], "mbedtls_md4" ) == 0 ) |
| 269 | todo.mbedtls_md4 = 1; |
| 270 | else if( strcmp( argv[i], "mbedtls_md5" ) == 0 ) |
| 271 | todo.mbedtls_md5 = 1; |
| 272 | else if( strcmp( argv[i], "mbedtls_ripemd160" ) == 0 ) |
| 273 | todo.mbedtls_ripemd160 = 1; |
| 274 | else if( strcmp( argv[i], "mbedtls_sha1" ) == 0 ) |
| 275 | todo.mbedtls_sha1 = 1; |
| 276 | else if( strcmp( argv[i], "mbedtls_sha256" ) == 0 ) |
| 277 | todo.mbedtls_sha256 = 1; |
| 278 | else if( strcmp( argv[i], "mbedtls_sha512" ) == 0 ) |
| 279 | todo.mbedtls_sha512 = 1; |
Manuel Pégourié-Gonnard | ed7cbe9 | 2013-09-17 15:30:51 +0200 | [diff] [blame] | 280 | else if( strcmp( argv[i], "arc4" ) == 0 ) |
| 281 | todo.arc4 = 1; |
| 282 | else if( strcmp( argv[i], "des3" ) == 0 ) |
| 283 | todo.des3 = 1; |
| 284 | else if( strcmp( argv[i], "des" ) == 0 ) |
| 285 | todo.des = 1; |
| 286 | else if( strcmp( argv[i], "aes_cbc" ) == 0 ) |
| 287 | todo.aes_cbc = 1; |
| 288 | else if( strcmp( argv[i], "aes_gcm" ) == 0 ) |
| 289 | todo.aes_gcm = 1; |
Manuel Pégourié-Gonnard | 58d78a8 | 2014-05-07 12:03:02 +0200 | [diff] [blame] | 290 | else if( strcmp( argv[i], "aes_ccm" ) == 0 ) |
| 291 | todo.aes_ccm = 1; |
Manuel Pégourié-Gonnard | ed7cbe9 | 2013-09-17 15:30:51 +0200 | [diff] [blame] | 292 | else if( strcmp( argv[i], "camellia" ) == 0 ) |
| 293 | todo.camellia = 1; |
| 294 | else if( strcmp( argv[i], "blowfish" ) == 0 ) |
| 295 | todo.blowfish = 1; |
| 296 | else if( strcmp( argv[i], "havege" ) == 0 ) |
| 297 | todo.havege = 1; |
| 298 | else if( strcmp( argv[i], "ctr_drbg" ) == 0 ) |
| 299 | todo.ctr_drbg = 1; |
Manuel Pégourié-Gonnard | fef0f8f | 2014-01-30 20:59:00 +0100 | [diff] [blame] | 300 | else if( strcmp( argv[i], "hmac_drbg" ) == 0 ) |
| 301 | todo.hmac_drbg = 1; |
Manuel Pégourié-Gonnard | ed7cbe9 | 2013-09-17 15:30:51 +0200 | [diff] [blame] | 302 | else if( strcmp( argv[i], "rsa" ) == 0 ) |
| 303 | todo.rsa = 1; |
| 304 | else if( strcmp( argv[i], "dhm" ) == 0 ) |
| 305 | todo.dhm = 1; |
Manuel Pégourié-Gonnard | cc34f95 | 2013-09-17 16:04:08 +0200 | [diff] [blame] | 306 | else if( strcmp( argv[i], "ecdsa" ) == 0 ) |
| 307 | todo.ecdsa = 1; |
| 308 | else if( strcmp( argv[i], "ecdh" ) == 0 ) |
| 309 | todo.ecdh = 1; |
Manuel Pégourié-Gonnard | ed7cbe9 | 2013-09-17 15:30:51 +0200 | [diff] [blame] | 310 | else |
| 311 | { |
Manuel Pégourié-Gonnard | 2cf5a7c | 2015-04-08 12:49:31 +0200 | [diff] [blame^] | 312 | mbedtls_printf( "Unrecognized option: %s\n", argv[i] ); |
| 313 | mbedtls_printf( "Available options: " OPTIONS ); |
Manuel Pégourié-Gonnard | ed7cbe9 | 2013-09-17 15:30:51 +0200 | [diff] [blame] | 314 | } |
| 315 | } |
| 316 | } |
Paul Bakker | 5121ce5 | 2009-01-03 21:22:43 +0000 | [diff] [blame] | 317 | |
Manuel Pégourié-Gonnard | 2cf5a7c | 2015-04-08 12:49:31 +0200 | [diff] [blame^] | 318 | mbedtls_printf( "\n" ); |
Paul Bakker | 5121ce5 | 2009-01-03 21:22:43 +0000 | [diff] [blame] | 319 | |
Manuel Pégourié-Gonnard | 2cf5a7c | 2015-04-08 12:49:31 +0200 | [diff] [blame^] | 320 | #if defined(MBEDTLS_MEMORY_BUFFER_ALLOC_C) |
| 321 | mbedtls_memory_buffer_alloc_init( malloc_buf, sizeof( malloc_buf ) ); |
Manuel Pégourié-Gonnard | 128657d | 2014-12-18 16:35:52 +0000 | [diff] [blame] | 322 | #endif |
Manuel Pégourié-Gonnard | ed7cbe9 | 2013-09-17 15:30:51 +0200 | [diff] [blame] | 323 | memset( buf, 0xAA, sizeof( buf ) ); |
Paul Bakker | df71dd1 | 2014-04-17 16:03:48 +0200 | [diff] [blame] | 324 | memset( tmp, 0xBB, sizeof( tmp ) ); |
Manuel Pégourié-Gonnard | ed7cbe9 | 2013-09-17 15:30:51 +0200 | [diff] [blame] | 325 | |
Manuel Pégourié-Gonnard | 2cf5a7c | 2015-04-08 12:49:31 +0200 | [diff] [blame^] | 326 | #if defined(MBEDTLS_MD4_C) |
| 327 | if( todo.mbedtls_md4 ) |
| 328 | TIME_AND_TSC( "MD4", mbedtls_md4( buf, BUFSIZE, tmp ) ); |
Paul Bakker | 5121ce5 | 2009-01-03 21:22:43 +0000 | [diff] [blame] | 329 | #endif |
| 330 | |
Manuel Pégourié-Gonnard | 2cf5a7c | 2015-04-08 12:49:31 +0200 | [diff] [blame^] | 331 | #if defined(MBEDTLS_MD5_C) |
| 332 | if( todo.mbedtls_md5 ) |
| 333 | TIME_AND_TSC( "MD5", mbedtls_md5( buf, BUFSIZE, tmp ) ); |
Paul Bakker | 5121ce5 | 2009-01-03 21:22:43 +0000 | [diff] [blame] | 334 | #endif |
| 335 | |
Manuel Pégourié-Gonnard | 2cf5a7c | 2015-04-08 12:49:31 +0200 | [diff] [blame^] | 336 | #if defined(MBEDTLS_RIPEMD160_C) |
| 337 | if( todo.mbedtls_ripemd160 ) |
| 338 | TIME_AND_TSC( "RIPEMD160", mbedtls_ripemd160( buf, BUFSIZE, tmp ) ); |
Manuel Pégourié-Gonnard | 01b0b38 | 2014-01-17 14:29:46 +0100 | [diff] [blame] | 339 | #endif |
| 340 | |
Manuel Pégourié-Gonnard | 2cf5a7c | 2015-04-08 12:49:31 +0200 | [diff] [blame^] | 341 | #if defined(MBEDTLS_SHA1_C) |
| 342 | if( todo.mbedtls_sha1 ) |
| 343 | TIME_AND_TSC( "SHA-1", mbedtls_sha1( buf, BUFSIZE, tmp ) ); |
Paul Bakker | 5121ce5 | 2009-01-03 21:22:43 +0000 | [diff] [blame] | 344 | #endif |
| 345 | |
Manuel Pégourié-Gonnard | 2cf5a7c | 2015-04-08 12:49:31 +0200 | [diff] [blame^] | 346 | #if defined(MBEDTLS_SHA256_C) |
| 347 | if( todo.mbedtls_sha256 ) |
| 348 | TIME_AND_TSC( "SHA-256", mbedtls_sha256( buf, BUFSIZE, tmp, 0 ) ); |
Paul Bakker | 5121ce5 | 2009-01-03 21:22:43 +0000 | [diff] [blame] | 349 | #endif |
| 350 | |
Manuel Pégourié-Gonnard | 2cf5a7c | 2015-04-08 12:49:31 +0200 | [diff] [blame^] | 351 | #if defined(MBEDTLS_SHA512_C) |
| 352 | if( todo.mbedtls_sha512 ) |
| 353 | TIME_AND_TSC( "SHA-512", mbedtls_sha512( buf, BUFSIZE, tmp, 0 ) ); |
Paul Bakker | 3a3c3c2 | 2009-02-09 22:33:30 +0000 | [diff] [blame] | 354 | #endif |
| 355 | |
Manuel Pégourié-Gonnard | 2cf5a7c | 2015-04-08 12:49:31 +0200 | [diff] [blame^] | 356 | #if defined(MBEDTLS_ARC4_C) |
Manuel Pégourié-Gonnard | ed7cbe9 | 2013-09-17 15:30:51 +0200 | [diff] [blame] | 357 | if( todo.arc4 ) |
Manuel Pégourié-Gonnard | 8271f2f | 2013-09-17 14:57:55 +0200 | [diff] [blame] | 358 | { |
Manuel Pégourié-Gonnard | 2cf5a7c | 2015-04-08 12:49:31 +0200 | [diff] [blame^] | 359 | mbedtls_arc4_context arc4; |
| 360 | mbedtls_arc4_init( &arc4 ); |
| 361 | mbedtls_arc4_setup( &arc4, tmp, 32 ); |
| 362 | TIME_AND_TSC( "ARC4", mbedtls_arc4_crypt( &arc4, BUFSIZE, buf, buf ) ); |
| 363 | mbedtls_arc4_free( &arc4 ); |
Manuel Pégourié-Gonnard | 8271f2f | 2013-09-17 14:57:55 +0200 | [diff] [blame] | 364 | } |
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_DES_C) && defined(MBEDTLS_CIPHER_MODE_CBC) |
Manuel Pégourié-Gonnard | ed7cbe9 | 2013-09-17 15:30:51 +0200 | [diff] [blame] | 368 | if( todo.des3 ) |
Manuel Pégourié-Gonnard | 8271f2f | 2013-09-17 14:57:55 +0200 | [diff] [blame] | 369 | { |
Manuel Pégourié-Gonnard | 2cf5a7c | 2015-04-08 12:49:31 +0200 | [diff] [blame^] | 370 | mbedtls_des3_context des3; |
| 371 | mbedtls_des3_init( &des3 ); |
| 372 | mbedtls_des3_set3key_enc( &des3, tmp ); |
Manuel Pégourié-Gonnard | 8271f2f | 2013-09-17 14:57:55 +0200 | [diff] [blame] | 373 | TIME_AND_TSC( "3DES", |
Manuel Pégourié-Gonnard | 2cf5a7c | 2015-04-08 12:49:31 +0200 | [diff] [blame^] | 374 | mbedtls_des3_crypt_cbc( &des3, MBEDTLS_DES_ENCRYPT, BUFSIZE, tmp, buf, buf ) ); |
| 375 | mbedtls_des3_free( &des3 ); |
Manuel Pégourié-Gonnard | 8271f2f | 2013-09-17 14:57:55 +0200 | [diff] [blame] | 376 | } |
Paul Bakker | 5121ce5 | 2009-01-03 21:22:43 +0000 | [diff] [blame] | 377 | |
Manuel Pégourié-Gonnard | ed7cbe9 | 2013-09-17 15:30:51 +0200 | [diff] [blame] | 378 | if( todo.des ) |
Manuel Pégourié-Gonnard | 8271f2f | 2013-09-17 14:57:55 +0200 | [diff] [blame] | 379 | { |
Manuel Pégourié-Gonnard | 2cf5a7c | 2015-04-08 12:49:31 +0200 | [diff] [blame^] | 380 | mbedtls_des_context des; |
| 381 | mbedtls_des_init( &des ); |
| 382 | mbedtls_des_setkey_enc( &des, tmp ); |
Manuel Pégourié-Gonnard | 8271f2f | 2013-09-17 14:57:55 +0200 | [diff] [blame] | 383 | TIME_AND_TSC( "DES", |
Manuel Pégourié-Gonnard | 2cf5a7c | 2015-04-08 12:49:31 +0200 | [diff] [blame^] | 384 | mbedtls_des_crypt_cbc( &des, MBEDTLS_DES_ENCRYPT, BUFSIZE, tmp, buf, buf ) ); |
| 385 | mbedtls_des_free( &des ); |
Manuel Pégourié-Gonnard | 8271f2f | 2013-09-17 14:57:55 +0200 | [diff] [blame] | 386 | } |
Paul Bakker | 5121ce5 | 2009-01-03 21:22:43 +0000 | [diff] [blame] | 387 | #endif |
| 388 | |
Manuel Pégourié-Gonnard | 2cf5a7c | 2015-04-08 12:49:31 +0200 | [diff] [blame^] | 389 | #if defined(MBEDTLS_AES_C) |
| 390 | #if defined(MBEDTLS_CIPHER_MODE_CBC) |
Manuel Pégourié-Gonnard | ed7cbe9 | 2013-09-17 15:30:51 +0200 | [diff] [blame] | 391 | if( todo.aes_cbc ) |
Paul Bakker | 5121ce5 | 2009-01-03 21:22:43 +0000 | [diff] [blame] | 392 | { |
Manuel Pégourié-Gonnard | 71e75dc | 2014-12-19 18:05:43 +0100 | [diff] [blame] | 393 | int keysize; |
Manuel Pégourié-Gonnard | 2cf5a7c | 2015-04-08 12:49:31 +0200 | [diff] [blame^] | 394 | mbedtls_aes_context aes; |
| 395 | mbedtls_aes_init( &aes ); |
Manuel Pégourié-Gonnard | 8271f2f | 2013-09-17 14:57:55 +0200 | [diff] [blame] | 396 | for( keysize = 128; keysize <= 256; keysize += 64 ) |
| 397 | { |
Manuel Pégourié-Gonnard | 2cf5a7c | 2015-04-08 12:49:31 +0200 | [diff] [blame^] | 398 | mbedtls_snprintf( title, sizeof( title ), "AES-CBC-%d", keysize ); |
Paul Bakker | 5121ce5 | 2009-01-03 21:22:43 +0000 | [diff] [blame] | 399 | |
Manuel Pégourié-Gonnard | 8271f2f | 2013-09-17 14:57:55 +0200 | [diff] [blame] | 400 | memset( buf, 0, sizeof( buf ) ); |
| 401 | memset( tmp, 0, sizeof( tmp ) ); |
Manuel Pégourié-Gonnard | 2cf5a7c | 2015-04-08 12:49:31 +0200 | [diff] [blame^] | 402 | mbedtls_aes_setkey_enc( &aes, tmp, keysize ); |
Paul Bakker | 5121ce5 | 2009-01-03 21:22:43 +0000 | [diff] [blame] | 403 | |
Manuel Pégourié-Gonnard | 8271f2f | 2013-09-17 14:57:55 +0200 | [diff] [blame] | 404 | TIME_AND_TSC( title, |
Manuel Pégourié-Gonnard | 2cf5a7c | 2015-04-08 12:49:31 +0200 | [diff] [blame^] | 405 | 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] | 406 | } |
Manuel Pégourié-Gonnard | 2cf5a7c | 2015-04-08 12:49:31 +0200 | [diff] [blame^] | 407 | mbedtls_aes_free( &aes ); |
Paul Bakker | 5121ce5 | 2009-01-03 21:22:43 +0000 | [diff] [blame] | 408 | } |
Manuel Pégourié-Gonnard | 8271f2f | 2013-09-17 14:57:55 +0200 | [diff] [blame] | 409 | #endif |
Manuel Pégourié-Gonnard | 2cf5a7c | 2015-04-08 12:49:31 +0200 | [diff] [blame^] | 410 | #if defined(MBEDTLS_GCM_C) |
Manuel Pégourié-Gonnard | ed7cbe9 | 2013-09-17 15:30:51 +0200 | [diff] [blame] | 411 | if( todo.aes_gcm ) |
Paul Bakker | 89e80c9 | 2012-03-20 13:50:09 +0000 | [diff] [blame] | 412 | { |
Manuel Pégourié-Gonnard | 71e75dc | 2014-12-19 18:05:43 +0100 | [diff] [blame] | 413 | int keysize; |
Manuel Pégourié-Gonnard | 2cf5a7c | 2015-04-08 12:49:31 +0200 | [diff] [blame^] | 414 | mbedtls_gcm_context gcm; |
Manuel Pégourié-Gonnard | 8271f2f | 2013-09-17 14:57:55 +0200 | [diff] [blame] | 415 | for( keysize = 128; keysize <= 256; keysize += 64 ) |
| 416 | { |
Manuel Pégourié-Gonnard | 2cf5a7c | 2015-04-08 12:49:31 +0200 | [diff] [blame^] | 417 | mbedtls_snprintf( title, sizeof( title ), "AES-GCM-%d", keysize ); |
Paul Bakker | 89e80c9 | 2012-03-20 13:50:09 +0000 | [diff] [blame] | 418 | |
Manuel Pégourié-Gonnard | 8271f2f | 2013-09-17 14:57:55 +0200 | [diff] [blame] | 419 | memset( buf, 0, sizeof( buf ) ); |
| 420 | memset( tmp, 0, sizeof( tmp ) ); |
Manuel Pégourié-Gonnard | 2cf5a7c | 2015-04-08 12:49:31 +0200 | [diff] [blame^] | 421 | mbedtls_gcm_init( &gcm, MBEDTLS_CIPHER_ID_AES, tmp, keysize ); |
Paul Bakker | 89e80c9 | 2012-03-20 13:50:09 +0000 | [diff] [blame] | 422 | |
Manuel Pégourié-Gonnard | 8271f2f | 2013-09-17 14:57:55 +0200 | [diff] [blame] | 423 | TIME_AND_TSC( title, |
Manuel Pégourié-Gonnard | 2cf5a7c | 2015-04-08 12:49:31 +0200 | [diff] [blame^] | 424 | 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] | 425 | 12, NULL, 0, buf, buf, 16, tmp ) ); |
Paul Bakker | f70fe81 | 2013-12-16 16:43:10 +0100 | [diff] [blame] | 426 | |
Manuel Pégourié-Gonnard | 2cf5a7c | 2015-04-08 12:49:31 +0200 | [diff] [blame^] | 427 | mbedtls_gcm_free( &gcm ); |
Manuel Pégourié-Gonnard | 8271f2f | 2013-09-17 14:57:55 +0200 | [diff] [blame] | 428 | } |
Paul Bakker | 89e80c9 | 2012-03-20 13:50:09 +0000 | [diff] [blame] | 429 | } |
| 430 | #endif |
Manuel Pégourié-Gonnard | 2cf5a7c | 2015-04-08 12:49:31 +0200 | [diff] [blame^] | 431 | #if defined(MBEDTLS_CCM_C) |
Manuel Pégourié-Gonnard | 58d78a8 | 2014-05-07 12:03:02 +0200 | [diff] [blame] | 432 | if( todo.aes_ccm ) |
| 433 | { |
Manuel Pégourié-Gonnard | 71e75dc | 2014-12-19 18:05:43 +0100 | [diff] [blame] | 434 | int keysize; |
Manuel Pégourié-Gonnard | 2cf5a7c | 2015-04-08 12:49:31 +0200 | [diff] [blame^] | 435 | mbedtls_ccm_context ccm; |
Manuel Pégourié-Gonnard | 58d78a8 | 2014-05-07 12:03:02 +0200 | [diff] [blame] | 436 | for( keysize = 128; keysize <= 256; keysize += 64 ) |
| 437 | { |
Manuel Pégourié-Gonnard | 2cf5a7c | 2015-04-08 12:49:31 +0200 | [diff] [blame^] | 438 | mbedtls_snprintf( title, sizeof( title ), "AES-CCM-%d", keysize ); |
Manuel Pégourié-Gonnard | 58d78a8 | 2014-05-07 12:03:02 +0200 | [diff] [blame] | 439 | |
| 440 | memset( buf, 0, sizeof( buf ) ); |
| 441 | memset( tmp, 0, sizeof( tmp ) ); |
Manuel Pégourié-Gonnard | 2cf5a7c | 2015-04-08 12:49:31 +0200 | [diff] [blame^] | 442 | mbedtls_ccm_init( &ccm, MBEDTLS_CIPHER_ID_AES, tmp, keysize ); |
Manuel Pégourié-Gonnard | 58d78a8 | 2014-05-07 12:03:02 +0200 | [diff] [blame] | 443 | |
| 444 | TIME_AND_TSC( title, |
Manuel Pégourié-Gonnard | 2cf5a7c | 2015-04-08 12:49:31 +0200 | [diff] [blame^] | 445 | mbedtls_ccm_encrypt_and_tag( &ccm, BUFSIZE, tmp, |
Manuel Pégourié-Gonnard | 58d78a8 | 2014-05-07 12:03:02 +0200 | [diff] [blame] | 446 | 12, NULL, 0, buf, buf, tmp, 16 ) ); |
| 447 | |
Manuel Pégourié-Gonnard | 2cf5a7c | 2015-04-08 12:49:31 +0200 | [diff] [blame^] | 448 | mbedtls_ccm_free( &ccm ); |
Manuel Pégourié-Gonnard | 58d78a8 | 2014-05-07 12:03:02 +0200 | [diff] [blame] | 449 | } |
| 450 | } |
| 451 | #endif |
Paul Bakker | 5121ce5 | 2009-01-03 21:22:43 +0000 | [diff] [blame] | 452 | #endif |
| 453 | |
Manuel Pégourié-Gonnard | 2cf5a7c | 2015-04-08 12:49:31 +0200 | [diff] [blame^] | 454 | #if defined(MBEDTLS_CAMELLIA_C) && defined(MBEDTLS_CIPHER_MODE_CBC) |
Manuel Pégourié-Gonnard | ed7cbe9 | 2013-09-17 15:30:51 +0200 | [diff] [blame] | 455 | if( todo.camellia ) |
Paul Bakker | 38119b1 | 2009-01-10 23:31:23 +0000 | [diff] [blame] | 456 | { |
Manuel Pégourié-Gonnard | 71e75dc | 2014-12-19 18:05:43 +0100 | [diff] [blame] | 457 | int keysize; |
Manuel Pégourié-Gonnard | 2cf5a7c | 2015-04-08 12:49:31 +0200 | [diff] [blame^] | 458 | mbedtls_camellia_context camellia; |
| 459 | mbedtls_camellia_init( &camellia ); |
Manuel Pégourié-Gonnard | 8271f2f | 2013-09-17 14:57:55 +0200 | [diff] [blame] | 460 | for( keysize = 128; keysize <= 256; keysize += 64 ) |
| 461 | { |
Manuel Pégourié-Gonnard | 2cf5a7c | 2015-04-08 12:49:31 +0200 | [diff] [blame^] | 462 | mbedtls_snprintf( title, sizeof( title ), "CAMELLIA-CBC-%d", keysize ); |
Paul Bakker | 38119b1 | 2009-01-10 23:31:23 +0000 | [diff] [blame] | 463 | |
Manuel Pégourié-Gonnard | 8271f2f | 2013-09-17 14:57:55 +0200 | [diff] [blame] | 464 | memset( buf, 0, sizeof( buf ) ); |
| 465 | memset( tmp, 0, sizeof( tmp ) ); |
Manuel Pégourié-Gonnard | 2cf5a7c | 2015-04-08 12:49:31 +0200 | [diff] [blame^] | 466 | mbedtls_camellia_setkey_enc( &camellia, tmp, keysize ); |
Paul Bakker | 38119b1 | 2009-01-10 23:31:23 +0000 | [diff] [blame] | 467 | |
Manuel Pégourié-Gonnard | 8271f2f | 2013-09-17 14:57:55 +0200 | [diff] [blame] | 468 | TIME_AND_TSC( title, |
Manuel Pégourié-Gonnard | 2cf5a7c | 2015-04-08 12:49:31 +0200 | [diff] [blame^] | 469 | mbedtls_camellia_crypt_cbc( &camellia, MBEDTLS_CAMELLIA_ENCRYPT, |
Manuel Pégourié-Gonnard | 8271f2f | 2013-09-17 14:57:55 +0200 | [diff] [blame] | 470 | BUFSIZE, tmp, buf, buf ) ); |
| 471 | } |
Manuel Pégourié-Gonnard | 2cf5a7c | 2015-04-08 12:49:31 +0200 | [diff] [blame^] | 472 | mbedtls_camellia_free( &camellia ); |
Paul Bakker | 38119b1 | 2009-01-10 23:31:23 +0000 | [diff] [blame] | 473 | } |
| 474 | #endif |
| 475 | |
Manuel Pégourié-Gonnard | 2cf5a7c | 2015-04-08 12:49:31 +0200 | [diff] [blame^] | 476 | #if defined(MBEDTLS_BLOWFISH_C) && defined(MBEDTLS_CIPHER_MODE_CBC) |
Manuel Pégourié-Gonnard | ed7cbe9 | 2013-09-17 15:30:51 +0200 | [diff] [blame] | 477 | if( todo.blowfish ) |
Paul Bakker | 3d58fe8 | 2012-07-04 17:15:31 +0000 | [diff] [blame] | 478 | { |
Manuel Pégourié-Gonnard | 71e75dc | 2014-12-19 18:05:43 +0100 | [diff] [blame] | 479 | int keysize; |
Manuel Pégourié-Gonnard | 2cf5a7c | 2015-04-08 12:49:31 +0200 | [diff] [blame^] | 480 | mbedtls_blowfish_context blowfish; |
| 481 | mbedtls_blowfish_init( &blowfish ); |
Paul Bakker | 8cfd9d8 | 2014-06-18 11:16:11 +0200 | [diff] [blame] | 482 | |
Manuel Pégourié-Gonnard | 8271f2f | 2013-09-17 14:57:55 +0200 | [diff] [blame] | 483 | for( keysize = 128; keysize <= 256; keysize += 64 ) |
| 484 | { |
Manuel Pégourié-Gonnard | 2cf5a7c | 2015-04-08 12:49:31 +0200 | [diff] [blame^] | 485 | mbedtls_snprintf( title, sizeof( title ), "BLOWFISH-CBC-%d", keysize ); |
Paul Bakker | 3d58fe8 | 2012-07-04 17:15:31 +0000 | [diff] [blame] | 486 | |
Manuel Pégourié-Gonnard | 8271f2f | 2013-09-17 14:57:55 +0200 | [diff] [blame] | 487 | memset( buf, 0, sizeof( buf ) ); |
| 488 | memset( tmp, 0, sizeof( tmp ) ); |
Manuel Pégourié-Gonnard | 2cf5a7c | 2015-04-08 12:49:31 +0200 | [diff] [blame^] | 489 | mbedtls_blowfish_setkey( &blowfish, tmp, keysize ); |
Paul Bakker | 3d58fe8 | 2012-07-04 17:15:31 +0000 | [diff] [blame] | 490 | |
Manuel Pégourié-Gonnard | 8271f2f | 2013-09-17 14:57:55 +0200 | [diff] [blame] | 491 | TIME_AND_TSC( title, |
Manuel Pégourié-Gonnard | 2cf5a7c | 2015-04-08 12:49:31 +0200 | [diff] [blame^] | 492 | mbedtls_blowfish_crypt_cbc( &blowfish, MBEDTLS_BLOWFISH_ENCRYPT, BUFSIZE, |
Manuel Pégourié-Gonnard | 8271f2f | 2013-09-17 14:57:55 +0200 | [diff] [blame] | 493 | tmp, buf, buf ) ); |
| 494 | } |
Paul Bakker | 8cfd9d8 | 2014-06-18 11:16:11 +0200 | [diff] [blame] | 495 | |
Manuel Pégourié-Gonnard | 2cf5a7c | 2015-04-08 12:49:31 +0200 | [diff] [blame^] | 496 | mbedtls_blowfish_free( &blowfish ); |
Paul Bakker | 3d58fe8 | 2012-07-04 17:15:31 +0000 | [diff] [blame] | 497 | } |
| 498 | #endif |
| 499 | |
Manuel Pégourié-Gonnard | 2cf5a7c | 2015-04-08 12:49:31 +0200 | [diff] [blame^] | 500 | #if defined(MBEDTLS_HAVEGE_C) |
Manuel Pégourié-Gonnard | ed7cbe9 | 2013-09-17 15:30:51 +0200 | [diff] [blame] | 501 | if( todo.havege ) |
Manuel Pégourié-Gonnard | 8271f2f | 2013-09-17 14:57:55 +0200 | [diff] [blame] | 502 | { |
Manuel Pégourié-Gonnard | 2cf5a7c | 2015-04-08 12:49:31 +0200 | [diff] [blame^] | 503 | mbedtls_havege_state hs; |
| 504 | mbedtls_havege_init( &hs ); |
| 505 | TIME_AND_TSC( "HAVEGE", mbedtls_havege_random( &hs, buf, BUFSIZE ) ); |
| 506 | mbedtls_havege_free( &hs ); |
Manuel Pégourié-Gonnard | 8271f2f | 2013-09-17 14:57:55 +0200 | [diff] [blame] | 507 | } |
Paul Bakker | 02faf45 | 2011-11-29 11:23:58 +0000 | [diff] [blame] | 508 | #endif |
| 509 | |
Manuel Pégourié-Gonnard | 2cf5a7c | 2015-04-08 12:49:31 +0200 | [diff] [blame^] | 510 | #if defined(MBEDTLS_CTR_DRBG_C) |
Manuel Pégourié-Gonnard | ed7cbe9 | 2013-09-17 15:30:51 +0200 | [diff] [blame] | 511 | if( todo.ctr_drbg ) |
Manuel Pégourié-Gonnard | 8271f2f | 2013-09-17 14:57:55 +0200 | [diff] [blame] | 512 | { |
Manuel Pégourié-Gonnard | 2cf5a7c | 2015-04-08 12:49:31 +0200 | [diff] [blame^] | 513 | mbedtls_ctr_drbg_context ctr_drbg; |
Paul Bakker | 02faf45 | 2011-11-29 11:23:58 +0000 | [diff] [blame] | 514 | |
Manuel Pégourié-Gonnard | 2cf5a7c | 2015-04-08 12:49:31 +0200 | [diff] [blame^] | 515 | if( mbedtls_ctr_drbg_init( &ctr_drbg, myrand, NULL, NULL, 0 ) != 0 ) |
| 516 | mbedtls_exit(1); |
Manuel Pégourié-Gonnard | 8271f2f | 2013-09-17 14:57:55 +0200 | [diff] [blame] | 517 | TIME_AND_TSC( "CTR_DRBG (NOPR)", |
Manuel Pégourié-Gonnard | 2cf5a7c | 2015-04-08 12:49:31 +0200 | [diff] [blame^] | 518 | if( mbedtls_ctr_drbg_random( &ctr_drbg, buf, BUFSIZE ) != 0 ) |
| 519 | mbedtls_exit(1) ); |
Paul Bakker | 02faf45 | 2011-11-29 11:23:58 +0000 | [diff] [blame] | 520 | |
Manuel Pégourié-Gonnard | 2cf5a7c | 2015-04-08 12:49:31 +0200 | [diff] [blame^] | 521 | if( mbedtls_ctr_drbg_init( &ctr_drbg, myrand, NULL, NULL, 0 ) != 0 ) |
| 522 | mbedtls_exit(1); |
| 523 | 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] | 524 | TIME_AND_TSC( "CTR_DRBG (PR)", |
Manuel Pégourié-Gonnard | 2cf5a7c | 2015-04-08 12:49:31 +0200 | [diff] [blame^] | 525 | if( mbedtls_ctr_drbg_random( &ctr_drbg, buf, BUFSIZE ) != 0 ) |
| 526 | mbedtls_exit(1) ); |
| 527 | mbedtls_ctr_drbg_free( &ctr_drbg ); |
Manuel Pégourié-Gonnard | 8271f2f | 2013-09-17 14:57:55 +0200 | [diff] [blame] | 528 | } |
Paul Bakker | 02faf45 | 2011-11-29 11:23:58 +0000 | [diff] [blame] | 529 | #endif |
| 530 | |
Manuel Pégourié-Gonnard | 2cf5a7c | 2015-04-08 12:49:31 +0200 | [diff] [blame^] | 531 | #if defined(MBEDTLS_HMAC_DRBG_C) |
Manuel Pégourié-Gonnard | fef0f8f | 2014-01-30 20:59:00 +0100 | [diff] [blame] | 532 | if( todo.hmac_drbg ) |
| 533 | { |
Manuel Pégourié-Gonnard | 2cf5a7c | 2015-04-08 12:49:31 +0200 | [diff] [blame^] | 534 | mbedtls_hmac_drbg_context hmac_drbg; |
| 535 | const mbedtls_md_info_t *md_info; |
Manuel Pégourié-Gonnard | fef0f8f | 2014-01-30 20:59:00 +0100 | [diff] [blame] | 536 | |
Manuel Pégourié-Gonnard | 2cf5a7c | 2015-04-08 12:49:31 +0200 | [diff] [blame^] | 537 | #if defined(MBEDTLS_SHA1_C) |
| 538 | if( ( md_info = mbedtls_md_info_from_type( MBEDTLS_MD_SHA1 ) ) == NULL ) |
| 539 | mbedtls_exit(1); |
Manuel Pégourié-Gonnard | fef0f8f | 2014-01-30 20:59:00 +0100 | [diff] [blame] | 540 | |
Manuel Pégourié-Gonnard | 2cf5a7c | 2015-04-08 12:49:31 +0200 | [diff] [blame^] | 541 | if( mbedtls_hmac_drbg_init( &hmac_drbg, md_info, myrand, NULL, NULL, 0 ) != 0 ) |
| 542 | mbedtls_exit(1); |
Manuel Pégourié-Gonnard | fef0f8f | 2014-01-30 20:59:00 +0100 | [diff] [blame] | 543 | TIME_AND_TSC( "HMAC_DRBG SHA-1 (NOPR)", |
Manuel Pégourié-Gonnard | 2cf5a7c | 2015-04-08 12:49:31 +0200 | [diff] [blame^] | 544 | if( mbedtls_hmac_drbg_random( &hmac_drbg, buf, BUFSIZE ) != 0 ) |
| 545 | mbedtls_exit(1) ); |
| 546 | mbedtls_hmac_drbg_free( &hmac_drbg ); |
Manuel Pégourié-Gonnard | fef0f8f | 2014-01-30 20:59:00 +0100 | [diff] [blame] | 547 | |
Manuel Pégourié-Gonnard | 2cf5a7c | 2015-04-08 12:49:31 +0200 | [diff] [blame^] | 548 | if( mbedtls_hmac_drbg_init( &hmac_drbg, md_info, myrand, NULL, NULL, 0 ) != 0 ) |
| 549 | mbedtls_exit(1); |
| 550 | mbedtls_hmac_drbg_set_prediction_resistance( &hmac_drbg, |
| 551 | MBEDTLS_HMAC_DRBG_PR_ON ); |
Manuel Pégourié-Gonnard | fef0f8f | 2014-01-30 20:59:00 +0100 | [diff] [blame] | 552 | TIME_AND_TSC( "HMAC_DRBG SHA-1 (PR)", |
Manuel Pégourié-Gonnard | 2cf5a7c | 2015-04-08 12:49:31 +0200 | [diff] [blame^] | 553 | if( mbedtls_hmac_drbg_random( &hmac_drbg, buf, BUFSIZE ) != 0 ) |
| 554 | mbedtls_exit(1) ); |
| 555 | mbedtls_hmac_drbg_free( &hmac_drbg ); |
Manuel Pégourié-Gonnard | fef0f8f | 2014-01-30 20:59:00 +0100 | [diff] [blame] | 556 | #endif |
| 557 | |
Manuel Pégourié-Gonnard | 2cf5a7c | 2015-04-08 12:49:31 +0200 | [diff] [blame^] | 558 | #if defined(MBEDTLS_SHA256_C) |
| 559 | if( ( md_info = mbedtls_md_info_from_type( MBEDTLS_MD_SHA256 ) ) == NULL ) |
| 560 | mbedtls_exit(1); |
Manuel Pégourié-Gonnard | fef0f8f | 2014-01-30 20:59:00 +0100 | [diff] [blame] | 561 | |
Manuel Pégourié-Gonnard | 2cf5a7c | 2015-04-08 12:49:31 +0200 | [diff] [blame^] | 562 | if( mbedtls_hmac_drbg_init( &hmac_drbg, md_info, myrand, NULL, NULL, 0 ) != 0 ) |
| 563 | mbedtls_exit(1); |
Manuel Pégourié-Gonnard | fef0f8f | 2014-01-30 20:59:00 +0100 | [diff] [blame] | 564 | TIME_AND_TSC( "HMAC_DRBG SHA-256 (NOPR)", |
Manuel Pégourié-Gonnard | 2cf5a7c | 2015-04-08 12:49:31 +0200 | [diff] [blame^] | 565 | if( mbedtls_hmac_drbg_random( &hmac_drbg, buf, BUFSIZE ) != 0 ) |
| 566 | mbedtls_exit(1) ); |
| 567 | mbedtls_hmac_drbg_free( &hmac_drbg ); |
Manuel Pégourié-Gonnard | fef0f8f | 2014-01-30 20:59:00 +0100 | [diff] [blame] | 568 | |
Manuel Pégourié-Gonnard | 2cf5a7c | 2015-04-08 12:49:31 +0200 | [diff] [blame^] | 569 | if( mbedtls_hmac_drbg_init( &hmac_drbg, md_info, myrand, NULL, NULL, 0 ) != 0 ) |
| 570 | mbedtls_exit(1); |
| 571 | mbedtls_hmac_drbg_set_prediction_resistance( &hmac_drbg, |
| 572 | MBEDTLS_HMAC_DRBG_PR_ON ); |
Manuel Pégourié-Gonnard | fef0f8f | 2014-01-30 20:59:00 +0100 | [diff] [blame] | 573 | TIME_AND_TSC( "HMAC_DRBG SHA-256 (PR)", |
Manuel Pégourié-Gonnard | 2cf5a7c | 2015-04-08 12:49:31 +0200 | [diff] [blame^] | 574 | if( mbedtls_hmac_drbg_random( &hmac_drbg, buf, BUFSIZE ) != 0 ) |
| 575 | mbedtls_exit(1) ); |
| 576 | mbedtls_hmac_drbg_free( &hmac_drbg ); |
Manuel Pégourié-Gonnard | fef0f8f | 2014-01-30 20:59:00 +0100 | [diff] [blame] | 577 | #endif |
| 578 | } |
| 579 | #endif |
| 580 | |
Manuel Pégourié-Gonnard | 2cf5a7c | 2015-04-08 12:49:31 +0200 | [diff] [blame^] | 581 | #if defined(MBEDTLS_RSA_C) && defined(MBEDTLS_GENPRIME) |
Manuel Pégourié-Gonnard | ed7cbe9 | 2013-09-17 15:30:51 +0200 | [diff] [blame] | 582 | if( todo.rsa ) |
Paul Bakker | 5121ce5 | 2009-01-03 21:22:43 +0000 | [diff] [blame] | 583 | { |
Manuel Pégourié-Gonnard | 71e75dc | 2014-12-19 18:05:43 +0100 | [diff] [blame] | 584 | int keysize; |
Manuel Pégourié-Gonnard | 2cf5a7c | 2015-04-08 12:49:31 +0200 | [diff] [blame^] | 585 | mbedtls_rsa_context rsa; |
Manuel Pégourié-Gonnard | 8271f2f | 2013-09-17 14:57:55 +0200 | [diff] [blame] | 586 | for( keysize = 1024; keysize <= 4096; keysize *= 2 ) |
| 587 | { |
Manuel Pégourié-Gonnard | 2cf5a7c | 2015-04-08 12:49:31 +0200 | [diff] [blame^] | 588 | mbedtls_snprintf( title, sizeof( title ), "RSA-%d", keysize ); |
Manuel Pégourié-Gonnard | 8271f2f | 2013-09-17 14:57:55 +0200 | [diff] [blame] | 589 | |
Manuel Pégourié-Gonnard | 2cf5a7c | 2015-04-08 12:49:31 +0200 | [diff] [blame^] | 590 | mbedtls_rsa_init( &rsa, MBEDTLS_RSA_PKCS_V15, 0 ); |
| 591 | mbedtls_rsa_gen_key( &rsa, myrand, NULL, keysize, 65537 ); |
Manuel Pégourié-Gonnard | 8271f2f | 2013-09-17 14:57:55 +0200 | [diff] [blame] | 592 | |
| 593 | TIME_PUBLIC( title, " public", |
| 594 | buf[0] = 0; |
Manuel Pégourié-Gonnard | 2cf5a7c | 2015-04-08 12:49:31 +0200 | [diff] [blame^] | 595 | ret = mbedtls_rsa_public( &rsa, buf, buf ) ); |
Manuel Pégourié-Gonnard | 8271f2f | 2013-09-17 14:57:55 +0200 | [diff] [blame] | 596 | |
| 597 | TIME_PUBLIC( title, "private", |
| 598 | buf[0] = 0; |
Manuel Pégourié-Gonnard | 2cf5a7c | 2015-04-08 12:49:31 +0200 | [diff] [blame^] | 599 | ret = mbedtls_rsa_private( &rsa, myrand, NULL, buf, buf ) ); |
Manuel Pégourié-Gonnard | 8271f2f | 2013-09-17 14:57:55 +0200 | [diff] [blame] | 600 | |
Manuel Pégourié-Gonnard | 2cf5a7c | 2015-04-08 12:49:31 +0200 | [diff] [blame^] | 601 | mbedtls_rsa_free( &rsa ); |
Manuel Pégourié-Gonnard | 8271f2f | 2013-09-17 14:57:55 +0200 | [diff] [blame] | 602 | } |
Paul Bakker | 5121ce5 | 2009-01-03 21:22:43 +0000 | [diff] [blame] | 603 | } |
Paul Bakker | 5121ce5 | 2009-01-03 21:22:43 +0000 | [diff] [blame] | 604 | #endif |
| 605 | |
Manuel Pégourié-Gonnard | 2cf5a7c | 2015-04-08 12:49:31 +0200 | [diff] [blame^] | 606 | #if defined(MBEDTLS_DHM_C) && defined(MBEDTLS_BIGNUM_C) |
Manuel Pégourié-Gonnard | ed7cbe9 | 2013-09-17 15:30:51 +0200 | [diff] [blame] | 607 | if( todo.dhm ) |
Manuel Pégourié-Gonnard | e870c0a | 2012-11-08 11:31:48 +0100 | [diff] [blame] | 608 | { |
Manuel Pégourié-Gonnard | ed7cbe9 | 2013-09-17 15:30:51 +0200 | [diff] [blame] | 609 | int dhm_sizes[DHM_SIZES] = { 1024, 2048, 3072 }; |
Manuel Pégourié-Gonnard | 8271f2f | 2013-09-17 14:57:55 +0200 | [diff] [blame] | 610 | const char *dhm_P[DHM_SIZES] = { |
Manuel Pégourié-Gonnard | 2cf5a7c | 2015-04-08 12:49:31 +0200 | [diff] [blame^] | 611 | MBEDTLS_DHM_RFC5114_MODP_1024_P, |
| 612 | MBEDTLS_DHM_RFC3526_MODP_2048_P, |
| 613 | MBEDTLS_DHM_RFC3526_MODP_3072_P, |
Manuel Pégourié-Gonnard | 8271f2f | 2013-09-17 14:57:55 +0200 | [diff] [blame] | 614 | }; |
| 615 | const char *dhm_G[DHM_SIZES] = { |
Manuel Pégourié-Gonnard | 2cf5a7c | 2015-04-08 12:49:31 +0200 | [diff] [blame^] | 616 | MBEDTLS_DHM_RFC5114_MODP_1024_G, |
| 617 | MBEDTLS_DHM_RFC3526_MODP_2048_G, |
| 618 | MBEDTLS_DHM_RFC3526_MODP_3072_G, |
Manuel Pégourié-Gonnard | 8271f2f | 2013-09-17 14:57:55 +0200 | [diff] [blame] | 619 | }; |
| 620 | |
Manuel Pégourié-Gonnard | 2cf5a7c | 2015-04-08 12:49:31 +0200 | [diff] [blame^] | 621 | mbedtls_dhm_context dhm; |
Manuel Pégourié-Gonnard | 8271f2f | 2013-09-17 14:57:55 +0200 | [diff] [blame] | 622 | size_t olen; |
Manuel Pégourié-Gonnard | ed7cbe9 | 2013-09-17 15:30:51 +0200 | [diff] [blame] | 623 | for( i = 0; i < DHM_SIZES; i++ ) |
Manuel Pégourié-Gonnard | 8271f2f | 2013-09-17 14:57:55 +0200 | [diff] [blame] | 624 | { |
Manuel Pégourié-Gonnard | 2cf5a7c | 2015-04-08 12:49:31 +0200 | [diff] [blame^] | 625 | mbedtls_dhm_init( &dhm ); |
Manuel Pégourié-Gonnard | 8271f2f | 2013-09-17 14:57:55 +0200 | [diff] [blame] | 626 | |
Manuel Pégourié-Gonnard | 2cf5a7c | 2015-04-08 12:49:31 +0200 | [diff] [blame^] | 627 | if( mbedtls_mpi_read_string( &dhm.P, 16, dhm_P[i] ) != 0 || |
| 628 | mbedtls_mpi_read_string( &dhm.G, 16, dhm_G[i] ) != 0 ) |
Paul Bakker | cbe3d0d | 2014-04-17 16:00:59 +0200 | [diff] [blame] | 629 | { |
Manuel Pégourié-Gonnard | 2cf5a7c | 2015-04-08 12:49:31 +0200 | [diff] [blame^] | 630 | mbedtls_exit( 1 ); |
Paul Bakker | cbe3d0d | 2014-04-17 16:00:59 +0200 | [diff] [blame] | 631 | } |
| 632 | |
Manuel Pégourié-Gonnard | 2cf5a7c | 2015-04-08 12:49:31 +0200 | [diff] [blame^] | 633 | dhm.len = mbedtls_mpi_size( &dhm.P ); |
| 634 | mbedtls_dhm_make_public( &dhm, (int) dhm.len, buf, dhm.len, myrand, NULL ); |
| 635 | if( mbedtls_mpi_copy( &dhm.GY, &dhm.GX ) != 0 ) |
| 636 | mbedtls_exit( 1 ); |
Manuel Pégourié-Gonnard | 8271f2f | 2013-09-17 14:57:55 +0200 | [diff] [blame] | 637 | |
Manuel Pégourié-Gonnard | 2cf5a7c | 2015-04-08 12:49:31 +0200 | [diff] [blame^] | 638 | mbedtls_snprintf( title, sizeof( title ), "DHE-%d", dhm_sizes[i] ); |
Manuel Pégourié-Gonnard | 8271f2f | 2013-09-17 14:57:55 +0200 | [diff] [blame] | 639 | TIME_PUBLIC( title, "handshake", |
| 640 | olen = sizeof( buf ); |
Manuel Pégourié-Gonnard | 2cf5a7c | 2015-04-08 12:49:31 +0200 | [diff] [blame^] | 641 | 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] | 642 | myrand, NULL ); |
Manuel Pégourié-Gonnard | 2cf5a7c | 2015-04-08 12:49:31 +0200 | [diff] [blame^] | 643 | ret |= mbedtls_dhm_calc_secret( &dhm, buf, &olen, myrand, NULL ) ); |
Manuel Pégourié-Gonnard | 8271f2f | 2013-09-17 14:57:55 +0200 | [diff] [blame] | 644 | |
Manuel Pégourié-Gonnard | 2cf5a7c | 2015-04-08 12:49:31 +0200 | [diff] [blame^] | 645 | mbedtls_snprintf( title, sizeof( title ), "DH-%d", dhm_sizes[i] ); |
Manuel Pégourié-Gonnard | 8271f2f | 2013-09-17 14:57:55 +0200 | [diff] [blame] | 646 | TIME_PUBLIC( title, "handshake", |
| 647 | olen = sizeof( buf ); |
Manuel Pégourié-Gonnard | 2cf5a7c | 2015-04-08 12:49:31 +0200 | [diff] [blame^] | 648 | ret |= mbedtls_dhm_calc_secret( &dhm, buf, &olen, myrand, NULL ) ); |
Manuel Pégourié-Gonnard | 8271f2f | 2013-09-17 14:57:55 +0200 | [diff] [blame] | 649 | |
Manuel Pégourié-Gonnard | 2cf5a7c | 2015-04-08 12:49:31 +0200 | [diff] [blame^] | 650 | mbedtls_dhm_free( &dhm ); |
Manuel Pégourié-Gonnard | 8271f2f | 2013-09-17 14:57:55 +0200 | [diff] [blame] | 651 | } |
Manuel Pégourié-Gonnard | e870c0a | 2012-11-08 11:31:48 +0100 | [diff] [blame] | 652 | } |
Manuel Pégourié-Gonnard | e870c0a | 2012-11-08 11:31:48 +0100 | [diff] [blame] | 653 | #endif |
| 654 | |
Manuel Pégourié-Gonnard | 2cf5a7c | 2015-04-08 12:49:31 +0200 | [diff] [blame^] | 655 | #if defined(MBEDTLS_ECDSA_C) && defined(MBEDTLS_SHA256_C) |
Manuel Pégourié-Gonnard | cc34f95 | 2013-09-17 16:04:08 +0200 | [diff] [blame] | 656 | if( todo.ecdsa ) |
| 657 | { |
Manuel Pégourié-Gonnard | 2cf5a7c | 2015-04-08 12:49:31 +0200 | [diff] [blame^] | 658 | mbedtls_ecdsa_context ecdsa; |
| 659 | const mbedtls_ecp_curve_info *curve_info; |
Manuel Pégourié-Gonnard | cc34f95 | 2013-09-17 16:04:08 +0200 | [diff] [blame] | 660 | size_t sig_len; |
| 661 | |
| 662 | memset( buf, 0x2A, sizeof( buf ) ); |
| 663 | |
Manuel Pégourié-Gonnard | 2cf5a7c | 2015-04-08 12:49:31 +0200 | [diff] [blame^] | 664 | for( curve_info = mbedtls_ecp_curve_list(); |
| 665 | curve_info->grp_id != MBEDTLS_ECP_DP_NONE; |
Manuel Pégourié-Gonnard | cc34f95 | 2013-09-17 16:04:08 +0200 | [diff] [blame] | 666 | curve_info++ ) |
| 667 | { |
Manuel Pégourié-Gonnard | 2cf5a7c | 2015-04-08 12:49:31 +0200 | [diff] [blame^] | 668 | mbedtls_ecdsa_init( &ecdsa ); |
Manuel Pégourié-Gonnard | cc34f95 | 2013-09-17 16:04:08 +0200 | [diff] [blame] | 669 | |
Manuel Pégourié-Gonnard | 2cf5a7c | 2015-04-08 12:49:31 +0200 | [diff] [blame^] | 670 | if( mbedtls_ecdsa_genkey( &ecdsa, curve_info->grp_id, myrand, NULL ) != 0 ) |
| 671 | mbedtls_exit( 1 ); |
Manuel Pégourié-Gonnard | 50da048 | 2014-12-19 12:10:37 +0100 | [diff] [blame] | 672 | ecp_clear_precomputed( &ecdsa.grp ); |
Manuel Pégourié-Gonnard | cc34f95 | 2013-09-17 16:04:08 +0200 | [diff] [blame] | 673 | |
Manuel Pégourié-Gonnard | 2cf5a7c | 2015-04-08 12:49:31 +0200 | [diff] [blame^] | 674 | mbedtls_snprintf( title, sizeof( title ), "ECDSA-%s", |
Manuel Pégourié-Gonnard | 56cd319 | 2013-09-17 17:23:07 +0200 | [diff] [blame] | 675 | curve_info->name ); |
Manuel Pégourié-Gonnard | cc34f95 | 2013-09-17 16:04:08 +0200 | [diff] [blame] | 676 | TIME_PUBLIC( title, "sign", |
Manuel Pégourié-Gonnard | 2cf5a7c | 2015-04-08 12:49:31 +0200 | [diff] [blame^] | 677 | ret = mbedtls_ecdsa_write_signature( &ecdsa, MBEDTLS_MD_SHA256, buf, curve_info->size, |
Manuel Pégourié-Gonnard | 56cd319 | 2013-09-17 17:23:07 +0200 | [diff] [blame] | 678 | tmp, &sig_len, myrand, NULL ) ); |
| 679 | |
Manuel Pégourié-Gonnard | 2cf5a7c | 2015-04-08 12:49:31 +0200 | [diff] [blame^] | 680 | mbedtls_ecdsa_free( &ecdsa ); |
Manuel Pégourié-Gonnard | 50da048 | 2014-12-19 12:10:37 +0100 | [diff] [blame] | 681 | } |
| 682 | |
Manuel Pégourié-Gonnard | 2cf5a7c | 2015-04-08 12:49:31 +0200 | [diff] [blame^] | 683 | for( curve_info = mbedtls_ecp_curve_list(); |
| 684 | curve_info->grp_id != MBEDTLS_ECP_DP_NONE; |
Manuel Pégourié-Gonnard | 50da048 | 2014-12-19 12:10:37 +0100 | [diff] [blame] | 685 | curve_info++ ) |
| 686 | { |
Manuel Pégourié-Gonnard | 2cf5a7c | 2015-04-08 12:49:31 +0200 | [diff] [blame^] | 687 | mbedtls_ecdsa_init( &ecdsa ); |
Manuel Pégourié-Gonnard | 50da048 | 2014-12-19 12:10:37 +0100 | [diff] [blame] | 688 | |
Manuel Pégourié-Gonnard | 2cf5a7c | 2015-04-08 12:49:31 +0200 | [diff] [blame^] | 689 | if( mbedtls_ecdsa_genkey( &ecdsa, curve_info->grp_id, myrand, NULL ) != 0 || |
| 690 | mbedtls_ecdsa_write_signature( &ecdsa, MBEDTLS_MD_SHA256, buf, curve_info->size, |
Manuel Pégourié-Gonnard | 50da048 | 2014-12-19 12:10:37 +0100 | [diff] [blame] | 691 | tmp, &sig_len, myrand, NULL ) != 0 ) |
| 692 | { |
Manuel Pégourié-Gonnard | 2cf5a7c | 2015-04-08 12:49:31 +0200 | [diff] [blame^] | 693 | mbedtls_exit( 1 ); |
Manuel Pégourié-Gonnard | 50da048 | 2014-12-19 12:10:37 +0100 | [diff] [blame] | 694 | } |
| 695 | ecp_clear_precomputed( &ecdsa.grp ); |
| 696 | |
Manuel Pégourié-Gonnard | 2cf5a7c | 2015-04-08 12:49:31 +0200 | [diff] [blame^] | 697 | mbedtls_snprintf( title, sizeof( title ), "ECDSA-%s", |
Manuel Pégourié-Gonnard | 50da048 | 2014-12-19 12:10:37 +0100 | [diff] [blame] | 698 | curve_info->name ); |
Manuel Pégourié-Gonnard | 56cd319 | 2013-09-17 17:23:07 +0200 | [diff] [blame] | 699 | TIME_PUBLIC( title, "verify", |
Manuel Pégourié-Gonnard | 2cf5a7c | 2015-04-08 12:49:31 +0200 | [diff] [blame^] | 700 | ret = mbedtls_ecdsa_read_signature( &ecdsa, buf, curve_info->size, |
Manuel Pégourié-Gonnard | 56cd319 | 2013-09-17 17:23:07 +0200 | [diff] [blame] | 701 | tmp, sig_len ) ); |
Manuel Pégourié-Gonnard | cc34f95 | 2013-09-17 16:04:08 +0200 | [diff] [blame] | 702 | |
Manuel Pégourié-Gonnard | 2cf5a7c | 2015-04-08 12:49:31 +0200 | [diff] [blame^] | 703 | mbedtls_ecdsa_free( &ecdsa ); |
Manuel Pégourié-Gonnard | cc34f95 | 2013-09-17 16:04:08 +0200 | [diff] [blame] | 704 | } |
| 705 | } |
| 706 | #endif |
| 707 | |
Manuel Pégourié-Gonnard | 2cf5a7c | 2015-04-08 12:49:31 +0200 | [diff] [blame^] | 708 | #if defined(MBEDTLS_ECDH_C) |
Manuel Pégourié-Gonnard | cc34f95 | 2013-09-17 16:04:08 +0200 | [diff] [blame] | 709 | if( todo.ecdh ) |
| 710 | { |
Manuel Pégourié-Gonnard | 2cf5a7c | 2015-04-08 12:49:31 +0200 | [diff] [blame^] | 711 | mbedtls_ecdh_context ecdh; |
| 712 | #if defined(MBEDTLS_ECP_DP_M255_ENABLED) |
| 713 | mbedtls_mpi z; |
Manuel Pégourié-Gonnard | 85391f2 | 2015-02-05 09:54:48 +0000 | [diff] [blame] | 714 | #endif |
Manuel Pégourié-Gonnard | 2cf5a7c | 2015-04-08 12:49:31 +0200 | [diff] [blame^] | 715 | const mbedtls_ecp_curve_info *curve_info; |
Manuel Pégourié-Gonnard | cc34f95 | 2013-09-17 16:04:08 +0200 | [diff] [blame] | 716 | size_t olen; |
| 717 | |
Manuel Pégourié-Gonnard | 2cf5a7c | 2015-04-08 12:49:31 +0200 | [diff] [blame^] | 718 | for( curve_info = mbedtls_ecp_curve_list(); |
| 719 | curve_info->grp_id != MBEDTLS_ECP_DP_NONE; |
Manuel Pégourié-Gonnard | cc34f95 | 2013-09-17 16:04:08 +0200 | [diff] [blame] | 720 | curve_info++ ) |
| 721 | { |
Manuel Pégourié-Gonnard | 2cf5a7c | 2015-04-08 12:49:31 +0200 | [diff] [blame^] | 722 | mbedtls_ecdh_init( &ecdh ); |
Manuel Pégourié-Gonnard | cc34f95 | 2013-09-17 16:04:08 +0200 | [diff] [blame] | 723 | |
Manuel Pégourié-Gonnard | 2cf5a7c | 2015-04-08 12:49:31 +0200 | [diff] [blame^] | 724 | if( mbedtls_ecp_use_known_dp( &ecdh.grp, curve_info->grp_id ) != 0 || |
| 725 | mbedtls_ecdh_make_public( &ecdh, &olen, buf, sizeof( buf), |
Manuel Pégourié-Gonnard | cc34f95 | 2013-09-17 16:04:08 +0200 | [diff] [blame] | 726 | myrand, NULL ) != 0 || |
Manuel Pégourié-Gonnard | 2cf5a7c | 2015-04-08 12:49:31 +0200 | [diff] [blame^] | 727 | mbedtls_ecp_copy( &ecdh.Qp, &ecdh.Q ) != 0 ) |
Manuel Pégourié-Gonnard | cc34f95 | 2013-09-17 16:04:08 +0200 | [diff] [blame] | 728 | { |
Manuel Pégourié-Gonnard | 2cf5a7c | 2015-04-08 12:49:31 +0200 | [diff] [blame^] | 729 | mbedtls_exit( 1 ); |
Manuel Pégourié-Gonnard | cc34f95 | 2013-09-17 16:04:08 +0200 | [diff] [blame] | 730 | } |
Manuel Pégourié-Gonnard | 50da048 | 2014-12-19 12:10:37 +0100 | [diff] [blame] | 731 | ecp_clear_precomputed( &ecdh.grp ); |
Manuel Pégourié-Gonnard | cc34f95 | 2013-09-17 16:04:08 +0200 | [diff] [blame] | 732 | |
Manuel Pégourié-Gonnard | 2cf5a7c | 2015-04-08 12:49:31 +0200 | [diff] [blame^] | 733 | mbedtls_snprintf( title, sizeof( title ), "ECDHE-%s", |
Manuel Pégourié-Gonnard | 56cd319 | 2013-09-17 17:23:07 +0200 | [diff] [blame] | 734 | curve_info->name ); |
Manuel Pégourié-Gonnard | cc34f95 | 2013-09-17 16:04:08 +0200 | [diff] [blame] | 735 | TIME_PUBLIC( title, "handshake", |
Manuel Pégourié-Gonnard | 2cf5a7c | 2015-04-08 12:49:31 +0200 | [diff] [blame^] | 736 | ret |= mbedtls_ecdh_make_public( &ecdh, &olen, buf, sizeof( buf), |
Manuel Pégourié-Gonnard | cc34f95 | 2013-09-17 16:04:08 +0200 | [diff] [blame] | 737 | myrand, NULL ); |
Manuel Pégourié-Gonnard | 2cf5a7c | 2015-04-08 12:49:31 +0200 | [diff] [blame^] | 738 | ret |= mbedtls_ecdh_calc_secret( &ecdh, &olen, buf, sizeof( buf ), |
Manuel Pégourié-Gonnard | cc34f95 | 2013-09-17 16:04:08 +0200 | [diff] [blame] | 739 | myrand, NULL ) ); |
Manuel Pégourié-Gonnard | 2cf5a7c | 2015-04-08 12:49:31 +0200 | [diff] [blame^] | 740 | mbedtls_ecdh_free( &ecdh ); |
Manuel Pégourié-Gonnard | 50da048 | 2014-12-19 12:10:37 +0100 | [diff] [blame] | 741 | } |
| 742 | |
Manuel Pégourié-Gonnard | 85391f2 | 2015-02-05 09:54:48 +0000 | [diff] [blame] | 743 | /* Curve25519 needs to be handled separately */ |
Manuel Pégourié-Gonnard | 2cf5a7c | 2015-04-08 12:49:31 +0200 | [diff] [blame^] | 744 | #if defined(MBEDTLS_ECP_DP_M255_ENABLED) |
| 745 | mbedtls_ecdh_init( &ecdh ); |
| 746 | mbedtls_mpi_init( &z ); |
Manuel Pégourié-Gonnard | 85391f2 | 2015-02-05 09:54:48 +0000 | [diff] [blame] | 747 | |
Manuel Pégourié-Gonnard | 2cf5a7c | 2015-04-08 12:49:31 +0200 | [diff] [blame^] | 748 | if( mbedtls_ecp_use_known_dp( &ecdh.grp, MBEDTLS_ECP_DP_M255 ) != 0 || |
| 749 | mbedtls_ecdh_gen_public( &ecdh.grp, &ecdh.d, &ecdh.Qp, myrand, NULL ) != 0 ) |
Manuel Pégourié-Gonnard | 85391f2 | 2015-02-05 09:54:48 +0000 | [diff] [blame] | 750 | { |
Manuel Pégourié-Gonnard | 2cf5a7c | 2015-04-08 12:49:31 +0200 | [diff] [blame^] | 751 | mbedtls_exit( 1 ); |
Manuel Pégourié-Gonnard | 85391f2 | 2015-02-05 09:54:48 +0000 | [diff] [blame] | 752 | } |
| 753 | |
| 754 | TIME_PUBLIC( "ECDHE-Curve25519", "handshake", |
Manuel Pégourié-Gonnard | 2cf5a7c | 2015-04-08 12:49:31 +0200 | [diff] [blame^] | 755 | ret |= mbedtls_ecdh_gen_public( &ecdh.grp, &ecdh.d, &ecdh.Q, |
Manuel Pégourié-Gonnard | 85391f2 | 2015-02-05 09:54:48 +0000 | [diff] [blame] | 756 | myrand, NULL ); |
Manuel Pégourié-Gonnard | 2cf5a7c | 2015-04-08 12:49:31 +0200 | [diff] [blame^] | 757 | ret |= mbedtls_ecdh_compute_shared( &ecdh.grp, &z, &ecdh.Qp, &ecdh.d, |
Manuel Pégourié-Gonnard | 85391f2 | 2015-02-05 09:54:48 +0000 | [diff] [blame] | 758 | myrand, NULL ) ); |
| 759 | |
Manuel Pégourié-Gonnard | 2cf5a7c | 2015-04-08 12:49:31 +0200 | [diff] [blame^] | 760 | mbedtls_ecdh_free( &ecdh ); |
| 761 | mbedtls_mpi_free( &z ); |
Manuel Pégourié-Gonnard | 85391f2 | 2015-02-05 09:54:48 +0000 | [diff] [blame] | 762 | #endif |
| 763 | |
Manuel Pégourié-Gonnard | 2cf5a7c | 2015-04-08 12:49:31 +0200 | [diff] [blame^] | 764 | for( curve_info = mbedtls_ecp_curve_list(); |
| 765 | curve_info->grp_id != MBEDTLS_ECP_DP_NONE; |
Manuel Pégourié-Gonnard | 50da048 | 2014-12-19 12:10:37 +0100 | [diff] [blame] | 766 | curve_info++ ) |
| 767 | { |
Manuel Pégourié-Gonnard | 2cf5a7c | 2015-04-08 12:49:31 +0200 | [diff] [blame^] | 768 | mbedtls_ecdh_init( &ecdh ); |
Manuel Pégourié-Gonnard | 50da048 | 2014-12-19 12:10:37 +0100 | [diff] [blame] | 769 | |
Manuel Pégourié-Gonnard | 2cf5a7c | 2015-04-08 12:49:31 +0200 | [diff] [blame^] | 770 | if( mbedtls_ecp_use_known_dp( &ecdh.grp, curve_info->grp_id ) != 0 || |
| 771 | mbedtls_ecdh_make_public( &ecdh, &olen, buf, sizeof( buf), |
Manuel Pégourié-Gonnard | 50da048 | 2014-12-19 12:10:37 +0100 | [diff] [blame] | 772 | myrand, NULL ) != 0 || |
Manuel Pégourié-Gonnard | 2cf5a7c | 2015-04-08 12:49:31 +0200 | [diff] [blame^] | 773 | mbedtls_ecp_copy( &ecdh.Qp, &ecdh.Q ) != 0 || |
| 774 | mbedtls_ecdh_make_public( &ecdh, &olen, buf, sizeof( buf), |
Manuel Pégourié-Gonnard | 50da048 | 2014-12-19 12:10:37 +0100 | [diff] [blame] | 775 | myrand, NULL ) != 0 ) |
| 776 | { |
Manuel Pégourié-Gonnard | 2cf5a7c | 2015-04-08 12:49:31 +0200 | [diff] [blame^] | 777 | mbedtls_exit( 1 ); |
Manuel Pégourié-Gonnard | 50da048 | 2014-12-19 12:10:37 +0100 | [diff] [blame] | 778 | } |
| 779 | ecp_clear_precomputed( &ecdh.grp ); |
Manuel Pégourié-Gonnard | cc34f95 | 2013-09-17 16:04:08 +0200 | [diff] [blame] | 780 | |
Manuel Pégourié-Gonnard | 2cf5a7c | 2015-04-08 12:49:31 +0200 | [diff] [blame^] | 781 | mbedtls_snprintf( title, sizeof( title ), "ECDH-%s", |
Manuel Pégourié-Gonnard | 56cd319 | 2013-09-17 17:23:07 +0200 | [diff] [blame] | 782 | curve_info->name ); |
Manuel Pégourié-Gonnard | cc34f95 | 2013-09-17 16:04:08 +0200 | [diff] [blame] | 783 | TIME_PUBLIC( title, "handshake", |
Manuel Pégourié-Gonnard | 2cf5a7c | 2015-04-08 12:49:31 +0200 | [diff] [blame^] | 784 | ret |= mbedtls_ecdh_calc_secret( &ecdh, &olen, buf, sizeof( buf ), |
Manuel Pégourié-Gonnard | cc34f95 | 2013-09-17 16:04:08 +0200 | [diff] [blame] | 785 | myrand, NULL ) ); |
Manuel Pégourié-Gonnard | 2cf5a7c | 2015-04-08 12:49:31 +0200 | [diff] [blame^] | 786 | mbedtls_ecdh_free( &ecdh ); |
Manuel Pégourié-Gonnard | cc34f95 | 2013-09-17 16:04:08 +0200 | [diff] [blame] | 787 | } |
Manuel Pégourié-Gonnard | 85391f2 | 2015-02-05 09:54:48 +0000 | [diff] [blame] | 788 | |
| 789 | /* Curve25519 needs to be handled separately */ |
Manuel Pégourié-Gonnard | 2cf5a7c | 2015-04-08 12:49:31 +0200 | [diff] [blame^] | 790 | #if defined(MBEDTLS_ECP_DP_M255_ENABLED) |
| 791 | mbedtls_ecdh_init( &ecdh ); |
| 792 | mbedtls_mpi_init( &z ); |
Manuel Pégourié-Gonnard | 85391f2 | 2015-02-05 09:54:48 +0000 | [diff] [blame] | 793 | |
Manuel Pégourié-Gonnard | 2cf5a7c | 2015-04-08 12:49:31 +0200 | [diff] [blame^] | 794 | if( mbedtls_ecp_use_known_dp( &ecdh.grp, MBEDTLS_ECP_DP_M255 ) != 0 || |
| 795 | mbedtls_ecdh_gen_public( &ecdh.grp, &ecdh.d, &ecdh.Qp, |
Manuel Pégourié-Gonnard | 85391f2 | 2015-02-05 09:54:48 +0000 | [diff] [blame] | 796 | myrand, NULL ) != 0 || |
Manuel Pégourié-Gonnard | 2cf5a7c | 2015-04-08 12:49:31 +0200 | [diff] [blame^] | 797 | mbedtls_ecdh_gen_public( &ecdh.grp, &ecdh.d, &ecdh.Q, myrand, NULL ) != 0 ) |
Manuel Pégourié-Gonnard | 85391f2 | 2015-02-05 09:54:48 +0000 | [diff] [blame] | 798 | { |
Manuel Pégourié-Gonnard | 2cf5a7c | 2015-04-08 12:49:31 +0200 | [diff] [blame^] | 799 | mbedtls_exit( 1 ); |
Manuel Pégourié-Gonnard | 85391f2 | 2015-02-05 09:54:48 +0000 | [diff] [blame] | 800 | } |
| 801 | |
| 802 | TIME_PUBLIC( "ECDH-Curve25519", "handshake", |
Manuel Pégourié-Gonnard | 2cf5a7c | 2015-04-08 12:49:31 +0200 | [diff] [blame^] | 803 | ret |= mbedtls_ecdh_compute_shared( &ecdh.grp, &z, &ecdh.Qp, &ecdh.d, |
Manuel Pégourié-Gonnard | 85391f2 | 2015-02-05 09:54:48 +0000 | [diff] [blame] | 804 | myrand, NULL ) ); |
| 805 | |
Manuel Pégourié-Gonnard | 2cf5a7c | 2015-04-08 12:49:31 +0200 | [diff] [blame^] | 806 | mbedtls_ecdh_free( &ecdh ); |
| 807 | mbedtls_mpi_free( &z ); |
Manuel Pégourié-Gonnard | 85391f2 | 2015-02-05 09:54:48 +0000 | [diff] [blame] | 808 | #endif |
Manuel Pégourié-Gonnard | cc34f95 | 2013-09-17 16:04:08 +0200 | [diff] [blame] | 809 | } |
| 810 | #endif |
Manuel Pégourié-Gonnard | 50da048 | 2014-12-19 12:10:37 +0100 | [diff] [blame] | 811 | |
Manuel Pégourié-Gonnard | 2cf5a7c | 2015-04-08 12:49:31 +0200 | [diff] [blame^] | 812 | mbedtls_printf( "\n" ); |
Paul Bakker | 1d4da2e | 2009-10-25 12:36:53 +0000 | [diff] [blame] | 813 | |
Manuel Pégourié-Gonnard | 2cf5a7c | 2015-04-08 12:49:31 +0200 | [diff] [blame^] | 814 | #if defined(MBEDTLS_MEMORY_BUFFER_ALLOC_C) |
| 815 | mbedtls_memory_buffer_alloc_free(); |
Manuel Pégourié-Gonnard | 128657d | 2014-12-18 16:35:52 +0000 | [diff] [blame] | 816 | #endif |
| 817 | |
Paul Bakker | cce9d77 | 2011-11-18 14:26:47 +0000 | [diff] [blame] | 818 | #if defined(_WIN32) |
Manuel Pégourié-Gonnard | 2cf5a7c | 2015-04-08 12:49:31 +0200 | [diff] [blame^] | 819 | mbedtls_printf( " Press Enter to exit this program.\n" ); |
Paul Bakker | 5121ce5 | 2009-01-03 21:22:43 +0000 | [diff] [blame] | 820 | fflush( stdout ); getchar(); |
| 821 | #endif |
| 822 | |
| 823 | return( 0 ); |
| 824 | } |
Manuel Pégourié-Gonnard | 8271f2f | 2013-09-17 14:57:55 +0200 | [diff] [blame] | 825 | |
Manuel Pégourié-Gonnard | 2cf5a7c | 2015-04-08 12:49:31 +0200 | [diff] [blame^] | 826 | #endif /* MBEDTLS_TIMING_C */ |