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