Paul Bakker | 5121ce5 | 2009-01-03 21:22:43 +0000 | [diff] [blame] | 1 | /* |
| 2 | * Benchmark demonstration program |
| 3 | * |
Paul Bakker | d2681d8 | 2013-06-30 14:49:12 +0200 | [diff] [blame] | 4 | * Copyright (C) 2006-2013, Brainspark B.V. |
Paul Bakker | b96f154 | 2010-07-18 20:36:00 +0000 | [diff] [blame] | 5 | * |
| 6 | * This file is part of PolarSSL (http://www.polarssl.org) |
Paul Bakker | 84f12b7 | 2010-07-18 10:13:04 +0000 | [diff] [blame] | 7 | * Lead Maintainer: Paul Bakker <polarssl_maintainer at polarssl.org> |
Paul Bakker | b96f154 | 2010-07-18 20:36:00 +0000 | [diff] [blame] | 8 | * |
Paul Bakker | 77b385e | 2009-07-28 17:23:11 +0000 | [diff] [blame] | 9 | * All rights reserved. |
Paul Bakker | e0ccd0a | 2009-01-04 16:27:10 +0000 | [diff] [blame] | 10 | * |
Paul Bakker | 5121ce5 | 2009-01-03 21:22:43 +0000 | [diff] [blame] | 11 | * This program is free software; you can redistribute it and/or modify |
| 12 | * it under the terms of the GNU General Public License as published by |
| 13 | * the Free Software Foundation; either version 2 of the License, or |
| 14 | * (at your option) any later version. |
| 15 | * |
| 16 | * This program is distributed in the hope that it will be useful, |
| 17 | * but WITHOUT ANY WARRANTY; without even the implied warranty of |
| 18 | * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the |
| 19 | * GNU General Public License for more details. |
| 20 | * |
| 21 | * You should have received a copy of the GNU General Public License along |
| 22 | * with this program; if not, write to the Free Software Foundation, Inc., |
| 23 | * 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA. |
| 24 | */ |
| 25 | |
Manuel Pégourié-Gonnard | cef4ad2 | 2014-04-29 12:39:06 +0200 | [diff] [blame^] | 26 | #if !defined(POLARSSL_CONFIG_FILE) |
Manuel Pégourié-Gonnard | abd6e02 | 2013-09-20 13:30:43 +0200 | [diff] [blame] | 27 | #include "polarssl/config.h" |
Manuel Pégourié-Gonnard | cef4ad2 | 2014-04-29 12:39:06 +0200 | [diff] [blame^] | 28 | #else |
| 29 | #include POLARSSL_CONFIG_FILE |
| 30 | #endif |
Paul Bakker | 5121ce5 | 2009-01-03 21:22:43 +0000 | [diff] [blame] | 31 | |
| 32 | #include <string.h> |
| 33 | #include <stdlib.h> |
| 34 | #include <stdio.h> |
| 35 | |
Manuel Pégourié-Gonnard | 8271f2f | 2013-09-17 14:57:55 +0200 | [diff] [blame] | 36 | #include "polarssl/timing.h" |
Paul Bakker | 5121ce5 | 2009-01-03 21:22:43 +0000 | [diff] [blame] | 37 | |
Paul Bakker | 40e4694 | 2009-01-03 21:51:57 +0000 | [diff] [blame] | 38 | #include "polarssl/md4.h" |
| 39 | #include "polarssl/md5.h" |
Paul Bakker | 61b699e | 2014-01-22 13:35:29 +0100 | [diff] [blame] | 40 | #include "polarssl/ripemd160.h" |
Paul Bakker | 40e4694 | 2009-01-03 21:51:57 +0000 | [diff] [blame] | 41 | #include "polarssl/sha1.h" |
Paul Bakker | d2681d8 | 2013-06-30 14:49:12 +0200 | [diff] [blame] | 42 | #include "polarssl/sha256.h" |
| 43 | #include "polarssl/sha512.h" |
Paul Bakker | 40e4694 | 2009-01-03 21:51:57 +0000 | [diff] [blame] | 44 | #include "polarssl/arc4.h" |
| 45 | #include "polarssl/des.h" |
| 46 | #include "polarssl/aes.h" |
Paul Bakker | 3d58fe8 | 2012-07-04 17:15:31 +0000 | [diff] [blame] | 47 | #include "polarssl/blowfish.h" |
Paul Bakker | 38119b1 | 2009-01-10 23:31:23 +0000 | [diff] [blame] | 48 | #include "polarssl/camellia.h" |
Paul Bakker | 89e80c9 | 2012-03-20 13:50:09 +0000 | [diff] [blame] | 49 | #include "polarssl/gcm.h" |
Manuel Pégourié-Gonnard | cc34f95 | 2013-09-17 16:04:08 +0200 | [diff] [blame] | 50 | #include "polarssl/havege.h" |
Manuel Pégourié-Gonnard | 8271f2f | 2013-09-17 14:57:55 +0200 | [diff] [blame] | 51 | #include "polarssl/ctr_drbg.h" |
Manuel Pégourié-Gonnard | fef0f8f | 2014-01-30 20:59:00 +0100 | [diff] [blame] | 52 | #include "polarssl/hmac_drbg.h" |
Paul Bakker | 40e4694 | 2009-01-03 21:51:57 +0000 | [diff] [blame] | 53 | #include "polarssl/rsa.h" |
Manuel Pégourié-Gonnard | e870c0a | 2012-11-08 11:31:48 +0100 | [diff] [blame] | 54 | #include "polarssl/dhm.h" |
Manuel Pégourié-Gonnard | cc34f95 | 2013-09-17 16:04:08 +0200 | [diff] [blame] | 55 | #include "polarssl/ecdsa.h" |
| 56 | #include "polarssl/ecdh.h" |
Gergely Budai | a5d336b | 2014-01-27 23:27:06 +0100 | [diff] [blame] | 57 | #include "polarssl/error.h" |
Paul Bakker | 5121ce5 | 2009-01-03 21:22:43 +0000 | [diff] [blame] | 58 | |
Manuel Pégourié-Gonnard | 2f77ce3 | 2013-10-03 11:59:57 +0200 | [diff] [blame] | 59 | #if defined _MSC_VER && !defined snprintf |
| 60 | #define snprintf _snprintf |
| 61 | #endif |
| 62 | |
Paul Bakker | 02faf45 | 2011-11-29 11:23:58 +0000 | [diff] [blame] | 63 | #define BUFSIZE 1024 |
Manuel Pégourié-Gonnard | fef0f8f | 2014-01-30 20:59:00 +0100 | [diff] [blame] | 64 | #define HEADER_FORMAT " %-24s : " |
Gergely Budai | a5d336b | 2014-01-27 23:27:06 +0100 | [diff] [blame] | 65 | #define TITLE_LEN 25 |
Paul Bakker | 5121ce5 | 2009-01-03 21:22:43 +0000 | [diff] [blame] | 66 | |
Manuel Pégourié-Gonnard | 8271f2f | 2013-09-17 14:57:55 +0200 | [diff] [blame] | 67 | #if !defined(POLARSSL_TIMING_C) |
| 68 | int main( int argc, char *argv[] ) |
| 69 | { |
| 70 | ((void) argc); |
| 71 | ((void) argv); |
| 72 | |
| 73 | printf("POLARSSL_TIMING_C not defined.\n"); |
| 74 | return( 0 ); |
| 75 | } |
| 76 | #else |
| 77 | |
Paul Bakker | a3d195c | 2011-11-27 21:07:34 +0000 | [diff] [blame] | 78 | static int myrand( void *rng_state, unsigned char *output, size_t len ) |
Paul Bakker | 5121ce5 | 2009-01-03 21:22:43 +0000 | [diff] [blame] | 79 | { |
Paul Bakker | a3d195c | 2011-11-27 21:07:34 +0000 | [diff] [blame] | 80 | size_t use_len; |
| 81 | int rnd; |
| 82 | |
Paul Bakker | 5121ce5 | 2009-01-03 21:22:43 +0000 | [diff] [blame] | 83 | if( rng_state != NULL ) |
| 84 | rng_state = NULL; |
| 85 | |
Paul Bakker | a3d195c | 2011-11-27 21:07:34 +0000 | [diff] [blame] | 86 | while( len > 0 ) |
| 87 | { |
| 88 | use_len = len; |
| 89 | if( use_len > sizeof(int) ) |
| 90 | use_len = sizeof(int); |
| 91 | |
| 92 | rnd = rand(); |
| 93 | memcpy( output, &rnd, use_len ); |
| 94 | output += use_len; |
| 95 | len -= use_len; |
| 96 | } |
| 97 | |
| 98 | return( 0 ); |
Paul Bakker | 5121ce5 | 2009-01-03 21:22:43 +0000 | [diff] [blame] | 99 | } |
| 100 | |
Manuel Pégourié-Gonnard | 8271f2f | 2013-09-17 14:57:55 +0200 | [diff] [blame] | 101 | #define TIME_AND_TSC( TITLE, CODE ) \ |
| 102 | do { \ |
| 103 | unsigned long i, j, tsc; \ |
| 104 | \ |
| 105 | printf( HEADER_FORMAT, TITLE ); \ |
| 106 | fflush( stdout ); \ |
| 107 | \ |
| 108 | set_alarm( 1 ); \ |
| 109 | for( i = 1; ! alarmed; i++ ) \ |
| 110 | { \ |
| 111 | CODE; \ |
| 112 | } \ |
| 113 | \ |
| 114 | tsc = hardclock(); \ |
| 115 | for( j = 0; j < 1024; j++ ) \ |
| 116 | { \ |
| 117 | CODE; \ |
| 118 | } \ |
| 119 | \ |
| 120 | printf( "%9lu Kb/s, %9lu cycles/byte\n", i * BUFSIZE / 1024, \ |
| 121 | ( hardclock() - tsc ) / ( j * BUFSIZE ) ); \ |
| 122 | } while( 0 ) |
| 123 | |
| 124 | #define TIME_PUBLIC( TITLE, TYPE, CODE ) \ |
| 125 | do { \ |
| 126 | unsigned long i; \ |
| 127 | int ret; \ |
| 128 | \ |
| 129 | printf( HEADER_FORMAT, TITLE ); \ |
| 130 | fflush( stdout ); \ |
| 131 | set_alarm( 3 ); \ |
| 132 | \ |
| 133 | ret = 0; \ |
| 134 | for( i = 1; ! alarmed && ! ret ; i++ ) \ |
| 135 | { \ |
| 136 | CODE; \ |
| 137 | } \ |
| 138 | \ |
| 139 | if( ret != 0 ) \ |
Gergely Budai | a5d336b | 2014-01-27 23:27:06 +0100 | [diff] [blame] | 140 | { \ |
| 141 | polarssl_strerror( ret, ( char * )tmp, sizeof( tmp ) ); \ |
| 142 | printf( "FAILED: %s\n", tmp ); \ |
| 143 | } \ |
Manuel Pégourié-Gonnard | 8271f2f | 2013-09-17 14:57:55 +0200 | [diff] [blame] | 144 | else \ |
Manuel Pégourié-Gonnard | 01b0b38 | 2014-01-17 14:29:46 +0100 | [diff] [blame] | 145 | printf( "%9lu " TYPE "/s\n", i / 3 ); \ |
Manuel Pégourié-Gonnard | 8271f2f | 2013-09-17 14:57:55 +0200 | [diff] [blame] | 146 | } while( 0 ) |
| 147 | |
Paul Bakker | 5121ce5 | 2009-01-03 21:22:43 +0000 | [diff] [blame] | 148 | unsigned char buf[BUFSIZE]; |
| 149 | |
Manuel Pégourié-Gonnard | ed7cbe9 | 2013-09-17 15:30:51 +0200 | [diff] [blame] | 150 | typedef struct { |
Paul Bakker | 61b699e | 2014-01-22 13:35:29 +0100 | [diff] [blame] | 151 | char md4, md5, ripemd160, sha1, sha256, sha512, |
Manuel Pégourié-Gonnard | ed7cbe9 | 2013-09-17 15:30:51 +0200 | [diff] [blame] | 152 | arc4, des3, des, aes_cbc, aes_gcm, camellia, blowfish, |
Manuel Pégourié-Gonnard | fef0f8f | 2014-01-30 20:59:00 +0100 | [diff] [blame] | 153 | havege, ctr_drbg, hmac_drbg, |
Manuel Pégourié-Gonnard | cc34f95 | 2013-09-17 16:04:08 +0200 | [diff] [blame] | 154 | rsa, dhm, ecdsa, ecdh; |
Manuel Pégourié-Gonnard | ed7cbe9 | 2013-09-17 15:30:51 +0200 | [diff] [blame] | 155 | } todo_list; |
| 156 | |
| 157 | #define OPTIONS \ |
Paul Bakker | 61b699e | 2014-01-22 13:35:29 +0100 | [diff] [blame] | 158 | "md4, md5, ripemd160, sha1, sha256, sha512,\n" \ |
Manuel Pégourié-Gonnard | ed7cbe9 | 2013-09-17 15:30:51 +0200 | [diff] [blame] | 159 | "arc4, des3, des, aes_cbc, aes_gcm, camellia, blowfish,\n" \ |
Manuel Pégourié-Gonnard | fef0f8f | 2014-01-30 20:59:00 +0100 | [diff] [blame] | 160 | "havege, ctr_drbg, hmac_drbg\n" \ |
Manuel Pégourié-Gonnard | cc34f95 | 2013-09-17 16:04:08 +0200 | [diff] [blame] | 161 | "rsa, dhm, ecdsa, ecdh.\n" |
Manuel Pégourié-Gonnard | ed7cbe9 | 2013-09-17 15:30:51 +0200 | [diff] [blame] | 162 | |
Paul Bakker | cce9d77 | 2011-11-18 14:26:47 +0000 | [diff] [blame] | 163 | int main( int argc, char *argv[] ) |
Paul Bakker | 5690efc | 2011-05-26 13:16:06 +0000 | [diff] [blame] | 164 | { |
Manuel Pégourié-Gonnard | ed7cbe9 | 2013-09-17 15:30:51 +0200 | [diff] [blame] | 165 | int keysize, i; |
Manuel Pégourié-Gonnard | cc34f95 | 2013-09-17 16:04:08 +0200 | [diff] [blame] | 166 | unsigned char tmp[200]; |
Manuel Pégourié-Gonnard | 8271f2f | 2013-09-17 14:57:55 +0200 | [diff] [blame] | 167 | char title[TITLE_LEN]; |
Manuel Pégourié-Gonnard | ed7cbe9 | 2013-09-17 15:30:51 +0200 | [diff] [blame] | 168 | todo_list todo; |
Paul Bakker | cce9d77 | 2011-11-18 14:26:47 +0000 | [diff] [blame] | 169 | |
Manuel Pégourié-Gonnard | ed7cbe9 | 2013-09-17 15:30:51 +0200 | [diff] [blame] | 170 | if( argc == 1 ) |
| 171 | memset( &todo, 1, sizeof( todo ) ); |
| 172 | else |
| 173 | { |
| 174 | memset( &todo, 0, sizeof( todo ) ); |
| 175 | |
| 176 | for( i = 1; i < argc; i++ ) |
| 177 | { |
| 178 | if( strcmp( argv[i], "md4" ) == 0 ) |
| 179 | todo.md4 = 1; |
| 180 | else if( strcmp( argv[i], "md5" ) == 0 ) |
| 181 | todo.md5 = 1; |
Paul Bakker | 61b699e | 2014-01-22 13:35:29 +0100 | [diff] [blame] | 182 | else if( strcmp( argv[i], "ripemd160" ) == 0 ) |
| 183 | todo.ripemd160 = 1; |
Manuel Pégourié-Gonnard | ed7cbe9 | 2013-09-17 15:30:51 +0200 | [diff] [blame] | 184 | else if( strcmp( argv[i], "sha1" ) == 0 ) |
| 185 | todo.sha1 = 1; |
| 186 | else if( strcmp( argv[i], "sha256" ) == 0 ) |
| 187 | todo.sha256 = 1; |
| 188 | else if( strcmp( argv[i], "sha512" ) == 0 ) |
| 189 | todo.sha512 = 1; |
| 190 | else if( strcmp( argv[i], "arc4" ) == 0 ) |
| 191 | todo.arc4 = 1; |
| 192 | else if( strcmp( argv[i], "des3" ) == 0 ) |
| 193 | todo.des3 = 1; |
| 194 | else if( strcmp( argv[i], "des" ) == 0 ) |
| 195 | todo.des = 1; |
| 196 | else if( strcmp( argv[i], "aes_cbc" ) == 0 ) |
| 197 | todo.aes_cbc = 1; |
| 198 | else if( strcmp( argv[i], "aes_gcm" ) == 0 ) |
| 199 | todo.aes_gcm = 1; |
| 200 | else if( strcmp( argv[i], "camellia" ) == 0 ) |
| 201 | todo.camellia = 1; |
| 202 | else if( strcmp( argv[i], "blowfish" ) == 0 ) |
| 203 | todo.blowfish = 1; |
| 204 | else if( strcmp( argv[i], "havege" ) == 0 ) |
| 205 | todo.havege = 1; |
| 206 | else if( strcmp( argv[i], "ctr_drbg" ) == 0 ) |
| 207 | todo.ctr_drbg = 1; |
Manuel Pégourié-Gonnard | fef0f8f | 2014-01-30 20:59:00 +0100 | [diff] [blame] | 208 | else if( strcmp( argv[i], "hmac_drbg" ) == 0 ) |
| 209 | todo.hmac_drbg = 1; |
Manuel Pégourié-Gonnard | ed7cbe9 | 2013-09-17 15:30:51 +0200 | [diff] [blame] | 210 | else if( strcmp( argv[i], "rsa" ) == 0 ) |
| 211 | todo.rsa = 1; |
| 212 | else if( strcmp( argv[i], "dhm" ) == 0 ) |
| 213 | todo.dhm = 1; |
Manuel Pégourié-Gonnard | cc34f95 | 2013-09-17 16:04:08 +0200 | [diff] [blame] | 214 | else if( strcmp( argv[i], "ecdsa" ) == 0 ) |
| 215 | todo.ecdsa = 1; |
| 216 | else if( strcmp( argv[i], "ecdh" ) == 0 ) |
| 217 | todo.ecdh = 1; |
Manuel Pégourié-Gonnard | ed7cbe9 | 2013-09-17 15:30:51 +0200 | [diff] [blame] | 218 | else |
| 219 | { |
| 220 | printf( "Unrecognized option: %s\n", argv[i] ); |
| 221 | printf( "Available options:" OPTIONS ); |
| 222 | } |
| 223 | } |
| 224 | } |
Paul Bakker | 5121ce5 | 2009-01-03 21:22:43 +0000 | [diff] [blame] | 225 | |
| 226 | printf( "\n" ); |
| 227 | |
Manuel Pégourié-Gonnard | ed7cbe9 | 2013-09-17 15:30:51 +0200 | [diff] [blame] | 228 | memset( buf, 0xAA, sizeof( buf ) ); |
Paul Bakker | df71dd1 | 2014-04-17 16:03:48 +0200 | [diff] [blame] | 229 | memset( tmp, 0xBB, sizeof( tmp ) ); |
Manuel Pégourié-Gonnard | ed7cbe9 | 2013-09-17 15:30:51 +0200 | [diff] [blame] | 230 | |
Paul Bakker | 40e4694 | 2009-01-03 21:51:57 +0000 | [diff] [blame] | 231 | #if defined(POLARSSL_MD4_C) |
Manuel Pégourié-Gonnard | ed7cbe9 | 2013-09-17 15:30:51 +0200 | [diff] [blame] | 232 | if( todo.md4 ) |
| 233 | TIME_AND_TSC( "MD4", md4( buf, BUFSIZE, tmp ) ); |
Paul Bakker | 5121ce5 | 2009-01-03 21:22:43 +0000 | [diff] [blame] | 234 | #endif |
| 235 | |
Paul Bakker | 40e4694 | 2009-01-03 21:51:57 +0000 | [diff] [blame] | 236 | #if defined(POLARSSL_MD5_C) |
Manuel Pégourié-Gonnard | ed7cbe9 | 2013-09-17 15:30:51 +0200 | [diff] [blame] | 237 | if( todo.md5 ) |
| 238 | TIME_AND_TSC( "MD5", md5( buf, BUFSIZE, tmp ) ); |
Paul Bakker | 5121ce5 | 2009-01-03 21:22:43 +0000 | [diff] [blame] | 239 | #endif |
| 240 | |
Paul Bakker | 61b699e | 2014-01-22 13:35:29 +0100 | [diff] [blame] | 241 | #if defined(POLARSSL_RIPEMD160_C) |
| 242 | if( todo.ripemd160 ) |
| 243 | TIME_AND_TSC( "RIPEMD160", ripemd160( buf, BUFSIZE, tmp ) ); |
Manuel Pégourié-Gonnard | 01b0b38 | 2014-01-17 14:29:46 +0100 | [diff] [blame] | 244 | #endif |
| 245 | |
Paul Bakker | 40e4694 | 2009-01-03 21:51:57 +0000 | [diff] [blame] | 246 | #if defined(POLARSSL_SHA1_C) |
Manuel Pégourié-Gonnard | ed7cbe9 | 2013-09-17 15:30:51 +0200 | [diff] [blame] | 247 | if( todo.sha1 ) |
| 248 | TIME_AND_TSC( "SHA-1", sha1( buf, BUFSIZE, tmp ) ); |
Paul Bakker | 5121ce5 | 2009-01-03 21:22:43 +0000 | [diff] [blame] | 249 | #endif |
| 250 | |
Paul Bakker | 9e36f04 | 2013-06-30 14:34:05 +0200 | [diff] [blame] | 251 | #if defined(POLARSSL_SHA256_C) |
Manuel Pégourié-Gonnard | ed7cbe9 | 2013-09-17 15:30:51 +0200 | [diff] [blame] | 252 | if( todo.sha256 ) |
| 253 | TIME_AND_TSC( "SHA-256", sha256( buf, BUFSIZE, tmp, 0 ) ); |
Paul Bakker | 5121ce5 | 2009-01-03 21:22:43 +0000 | [diff] [blame] | 254 | #endif |
| 255 | |
Paul Bakker | 9e36f04 | 2013-06-30 14:34:05 +0200 | [diff] [blame] | 256 | #if defined(POLARSSL_SHA512_C) |
Manuel Pégourié-Gonnard | ed7cbe9 | 2013-09-17 15:30:51 +0200 | [diff] [blame] | 257 | if( todo.sha512 ) |
| 258 | TIME_AND_TSC( "SHA-512", sha512( buf, BUFSIZE, tmp, 0 ) ); |
Paul Bakker | 3a3c3c2 | 2009-02-09 22:33:30 +0000 | [diff] [blame] | 259 | #endif |
| 260 | |
Paul Bakker | 40e4694 | 2009-01-03 21:51:57 +0000 | [diff] [blame] | 261 | #if defined(POLARSSL_ARC4_C) |
Manuel Pégourié-Gonnard | ed7cbe9 | 2013-09-17 15:30:51 +0200 | [diff] [blame] | 262 | if( todo.arc4 ) |
Manuel Pégourié-Gonnard | 8271f2f | 2013-09-17 14:57:55 +0200 | [diff] [blame] | 263 | { |
| 264 | arc4_context arc4; |
| 265 | arc4_setup( &arc4, tmp, 32 ); |
| 266 | TIME_AND_TSC( "ARC4", arc4_crypt( &arc4, BUFSIZE, buf, buf ) ); |
| 267 | } |
Paul Bakker | 5121ce5 | 2009-01-03 21:22:43 +0000 | [diff] [blame] | 268 | #endif |
| 269 | |
Manuel Pégourié-Gonnard | 92cb1d3 | 2013-09-13 16:24:20 +0200 | [diff] [blame] | 270 | #if defined(POLARSSL_DES_C) && defined(POLARSSL_CIPHER_MODE_CBC) |
Manuel Pégourié-Gonnard | ed7cbe9 | 2013-09-17 15:30:51 +0200 | [diff] [blame] | 271 | if( todo.des3 ) |
Manuel Pégourié-Gonnard | 8271f2f | 2013-09-17 14:57:55 +0200 | [diff] [blame] | 272 | { |
| 273 | des3_context des3; |
| 274 | des3_set3key_enc( &des3, tmp ); |
| 275 | TIME_AND_TSC( "3DES", |
| 276 | des3_crypt_cbc( &des3, DES_ENCRYPT, BUFSIZE, tmp, buf, buf ) ); |
| 277 | } |
Paul Bakker | 5121ce5 | 2009-01-03 21:22:43 +0000 | [diff] [blame] | 278 | |
Manuel Pégourié-Gonnard | ed7cbe9 | 2013-09-17 15:30:51 +0200 | [diff] [blame] | 279 | if( todo.des ) |
Manuel Pégourié-Gonnard | 8271f2f | 2013-09-17 14:57:55 +0200 | [diff] [blame] | 280 | { |
| 281 | des_context des; |
| 282 | des_setkey_enc( &des, tmp ); |
| 283 | TIME_AND_TSC( "DES", |
| 284 | des_crypt_cbc( &des, DES_ENCRYPT, BUFSIZE, tmp, buf, buf ) ); |
| 285 | } |
Paul Bakker | 5121ce5 | 2009-01-03 21:22:43 +0000 | [diff] [blame] | 286 | #endif |
| 287 | |
Paul Bakker | 40e4694 | 2009-01-03 21:51:57 +0000 | [diff] [blame] | 288 | #if defined(POLARSSL_AES_C) |
Manuel Pégourié-Gonnard | 92cb1d3 | 2013-09-13 16:24:20 +0200 | [diff] [blame] | 289 | #if defined(POLARSSL_CIPHER_MODE_CBC) |
Manuel Pégourié-Gonnard | ed7cbe9 | 2013-09-17 15:30:51 +0200 | [diff] [blame] | 290 | if( todo.aes_cbc ) |
Paul Bakker | 5121ce5 | 2009-01-03 21:22:43 +0000 | [diff] [blame] | 291 | { |
Manuel Pégourié-Gonnard | 8271f2f | 2013-09-17 14:57:55 +0200 | [diff] [blame] | 292 | aes_context aes; |
| 293 | for( keysize = 128; keysize <= 256; keysize += 64 ) |
| 294 | { |
| 295 | snprintf( title, sizeof( title ), "AES-CBC-%d", keysize ); |
Paul Bakker | 5121ce5 | 2009-01-03 21:22:43 +0000 | [diff] [blame] | 296 | |
Manuel Pégourié-Gonnard | 8271f2f | 2013-09-17 14:57:55 +0200 | [diff] [blame] | 297 | memset( buf, 0, sizeof( buf ) ); |
| 298 | memset( tmp, 0, sizeof( tmp ) ); |
| 299 | aes_setkey_enc( &aes, tmp, keysize ); |
Paul Bakker | 5121ce5 | 2009-01-03 21:22:43 +0000 | [diff] [blame] | 300 | |
Manuel Pégourié-Gonnard | 8271f2f | 2013-09-17 14:57:55 +0200 | [diff] [blame] | 301 | TIME_AND_TSC( title, |
Manuel Pégourié-Gonnard | ed7cbe9 | 2013-09-17 15:30:51 +0200 | [diff] [blame] | 302 | aes_crypt_cbc( &aes, AES_ENCRYPT, BUFSIZE, tmp, buf, buf ) ); |
Manuel Pégourié-Gonnard | 8271f2f | 2013-09-17 14:57:55 +0200 | [diff] [blame] | 303 | } |
Paul Bakker | 5121ce5 | 2009-01-03 21:22:43 +0000 | [diff] [blame] | 304 | } |
Manuel Pégourié-Gonnard | 8271f2f | 2013-09-17 14:57:55 +0200 | [diff] [blame] | 305 | #endif |
Paul Bakker | 89e80c9 | 2012-03-20 13:50:09 +0000 | [diff] [blame] | 306 | #if defined(POLARSSL_GCM_C) |
Manuel Pégourié-Gonnard | ed7cbe9 | 2013-09-17 15:30:51 +0200 | [diff] [blame] | 307 | if( todo.aes_gcm ) |
Paul Bakker | 89e80c9 | 2012-03-20 13:50:09 +0000 | [diff] [blame] | 308 | { |
Manuel Pégourié-Gonnard | 8271f2f | 2013-09-17 14:57:55 +0200 | [diff] [blame] | 309 | gcm_context gcm; |
| 310 | for( keysize = 128; keysize <= 256; keysize += 64 ) |
| 311 | { |
| 312 | snprintf( title, sizeof( title ), "AES-GCM-%d", keysize ); |
Paul Bakker | 89e80c9 | 2012-03-20 13:50:09 +0000 | [diff] [blame] | 313 | |
Manuel Pégourié-Gonnard | 8271f2f | 2013-09-17 14:57:55 +0200 | [diff] [blame] | 314 | memset( buf, 0, sizeof( buf ) ); |
| 315 | memset( tmp, 0, sizeof( tmp ) ); |
| 316 | gcm_init( &gcm, POLARSSL_CIPHER_ID_AES, tmp, keysize ); |
Paul Bakker | 89e80c9 | 2012-03-20 13:50:09 +0000 | [diff] [blame] | 317 | |
Manuel Pégourié-Gonnard | 8271f2f | 2013-09-17 14:57:55 +0200 | [diff] [blame] | 318 | TIME_AND_TSC( title, |
| 319 | gcm_crypt_and_tag( &gcm, GCM_ENCRYPT, BUFSIZE, tmp, |
| 320 | 12, NULL, 0, buf, buf, 16, tmp ) ); |
Paul Bakker | f70fe81 | 2013-12-16 16:43:10 +0100 | [diff] [blame] | 321 | |
| 322 | gcm_free( &gcm ); |
Manuel Pégourié-Gonnard | 8271f2f | 2013-09-17 14:57:55 +0200 | [diff] [blame] | 323 | } |
Paul Bakker | 89e80c9 | 2012-03-20 13:50:09 +0000 | [diff] [blame] | 324 | } |
| 325 | #endif |
Paul Bakker | 5121ce5 | 2009-01-03 21:22:43 +0000 | [diff] [blame] | 326 | #endif |
| 327 | |
Manuel Pégourié-Gonnard | 92cb1d3 | 2013-09-13 16:24:20 +0200 | [diff] [blame] | 328 | #if defined(POLARSSL_CAMELLIA_C) && defined(POLARSSL_CIPHER_MODE_CBC) |
Manuel Pégourié-Gonnard | ed7cbe9 | 2013-09-17 15:30:51 +0200 | [diff] [blame] | 329 | if( todo.camellia ) |
Paul Bakker | 38119b1 | 2009-01-10 23:31:23 +0000 | [diff] [blame] | 330 | { |
Manuel Pégourié-Gonnard | 8271f2f | 2013-09-17 14:57:55 +0200 | [diff] [blame] | 331 | camellia_context camellia; |
| 332 | for( keysize = 128; keysize <= 256; keysize += 64 ) |
| 333 | { |
| 334 | snprintf( title, sizeof( title ), "CAMELLIA-CBC-%d", keysize ); |
Paul Bakker | 38119b1 | 2009-01-10 23:31:23 +0000 | [diff] [blame] | 335 | |
Manuel Pégourié-Gonnard | 8271f2f | 2013-09-17 14:57:55 +0200 | [diff] [blame] | 336 | memset( buf, 0, sizeof( buf ) ); |
| 337 | memset( tmp, 0, sizeof( tmp ) ); |
| 338 | camellia_setkey_enc( &camellia, tmp, keysize ); |
Paul Bakker | 38119b1 | 2009-01-10 23:31:23 +0000 | [diff] [blame] | 339 | |
Manuel Pégourié-Gonnard | 8271f2f | 2013-09-17 14:57:55 +0200 | [diff] [blame] | 340 | TIME_AND_TSC( title, |
| 341 | camellia_crypt_cbc( &camellia, CAMELLIA_ENCRYPT, |
| 342 | BUFSIZE, tmp, buf, buf ) ); |
| 343 | } |
Paul Bakker | 38119b1 | 2009-01-10 23:31:23 +0000 | [diff] [blame] | 344 | } |
| 345 | #endif |
| 346 | |
Manuel Pégourié-Gonnard | 92cb1d3 | 2013-09-13 16:24:20 +0200 | [diff] [blame] | 347 | #if defined(POLARSSL_BLOWFISH_C) && defined(POLARSSL_CIPHER_MODE_CBC) |
Manuel Pégourié-Gonnard | ed7cbe9 | 2013-09-17 15:30:51 +0200 | [diff] [blame] | 348 | if( todo.blowfish ) |
Paul Bakker | 3d58fe8 | 2012-07-04 17:15:31 +0000 | [diff] [blame] | 349 | { |
Manuel Pégourié-Gonnard | 8271f2f | 2013-09-17 14:57:55 +0200 | [diff] [blame] | 350 | blowfish_context blowfish; |
| 351 | for( keysize = 128; keysize <= 256; keysize += 64 ) |
| 352 | { |
| 353 | snprintf( title, sizeof( title ), "BLOWFISH-CBC-%d", keysize ); |
Paul Bakker | 3d58fe8 | 2012-07-04 17:15:31 +0000 | [diff] [blame] | 354 | |
Manuel Pégourié-Gonnard | 8271f2f | 2013-09-17 14:57:55 +0200 | [diff] [blame] | 355 | memset( buf, 0, sizeof( buf ) ); |
| 356 | memset( tmp, 0, sizeof( tmp ) ); |
| 357 | blowfish_setkey( &blowfish, tmp, keysize ); |
Paul Bakker | 3d58fe8 | 2012-07-04 17:15:31 +0000 | [diff] [blame] | 358 | |
Manuel Pégourié-Gonnard | 8271f2f | 2013-09-17 14:57:55 +0200 | [diff] [blame] | 359 | TIME_AND_TSC( title, |
| 360 | blowfish_crypt_cbc( &blowfish, BLOWFISH_ENCRYPT, BUFSIZE, |
| 361 | tmp, buf, buf ) ); |
| 362 | } |
Paul Bakker | 3d58fe8 | 2012-07-04 17:15:31 +0000 | [diff] [blame] | 363 | } |
| 364 | #endif |
| 365 | |
Paul Bakker | 02faf45 | 2011-11-29 11:23:58 +0000 | [diff] [blame] | 366 | #if defined(POLARSSL_HAVEGE_C) |
Manuel Pégourié-Gonnard | ed7cbe9 | 2013-09-17 15:30:51 +0200 | [diff] [blame] | 367 | if( todo.havege ) |
Manuel Pégourié-Gonnard | 8271f2f | 2013-09-17 14:57:55 +0200 | [diff] [blame] | 368 | { |
| 369 | havege_state hs; |
| 370 | havege_init( &hs ); |
| 371 | TIME_AND_TSC( "HAVEGE", havege_random( &hs, buf, BUFSIZE ) ); |
| 372 | } |
Paul Bakker | 02faf45 | 2011-11-29 11:23:58 +0000 | [diff] [blame] | 373 | #endif |
| 374 | |
| 375 | #if defined(POLARSSL_CTR_DRBG_C) |
Manuel Pégourié-Gonnard | ed7cbe9 | 2013-09-17 15:30:51 +0200 | [diff] [blame] | 376 | if( todo.ctr_drbg ) |
Manuel Pégourié-Gonnard | 8271f2f | 2013-09-17 14:57:55 +0200 | [diff] [blame] | 377 | { |
Manuel Pégourié-Gonnard | ed7cbe9 | 2013-09-17 15:30:51 +0200 | [diff] [blame] | 378 | ctr_drbg_context ctr_drbg; |
Paul Bakker | 02faf45 | 2011-11-29 11:23:58 +0000 | [diff] [blame] | 379 | |
Manuel Pégourié-Gonnard | 8271f2f | 2013-09-17 14:57:55 +0200 | [diff] [blame] | 380 | if( ctr_drbg_init( &ctr_drbg, myrand, NULL, NULL, 0 ) != 0 ) |
Paul Bakker | 02faf45 | 2011-11-29 11:23:58 +0000 | [diff] [blame] | 381 | exit(1); |
Manuel Pégourié-Gonnard | 8271f2f | 2013-09-17 14:57:55 +0200 | [diff] [blame] | 382 | TIME_AND_TSC( "CTR_DRBG (NOPR)", |
| 383 | if( ctr_drbg_random( &ctr_drbg, buf, BUFSIZE ) != 0 ) |
| 384 | exit(1) ); |
Paul Bakker | 02faf45 | 2011-11-29 11:23:58 +0000 | [diff] [blame] | 385 | |
Manuel Pégourié-Gonnard | 8271f2f | 2013-09-17 14:57:55 +0200 | [diff] [blame] | 386 | if( ctr_drbg_init( &ctr_drbg, myrand, NULL, NULL, 0 ) != 0 ) |
Paul Bakker | 02faf45 | 2011-11-29 11:23:58 +0000 | [diff] [blame] | 387 | exit(1); |
Manuel Pégourié-Gonnard | 8271f2f | 2013-09-17 14:57:55 +0200 | [diff] [blame] | 388 | ctr_drbg_set_prediction_resistance( &ctr_drbg, CTR_DRBG_PR_ON ); |
| 389 | TIME_AND_TSC( "CTR_DRBG (PR)", |
| 390 | if( ctr_drbg_random( &ctr_drbg, buf, BUFSIZE ) != 0 ) |
| 391 | exit(1) ); |
| 392 | } |
Paul Bakker | 02faf45 | 2011-11-29 11:23:58 +0000 | [diff] [blame] | 393 | #endif |
| 394 | |
Manuel Pégourié-Gonnard | fef0f8f | 2014-01-30 20:59:00 +0100 | [diff] [blame] | 395 | #if defined(POLARSSL_HMAC_DRBG_C) |
| 396 | if( todo.hmac_drbg ) |
| 397 | { |
| 398 | hmac_drbg_context hmac_drbg; |
| 399 | const md_info_t *md_info; |
| 400 | |
| 401 | #if defined(POLARSSL_SHA1_C) |
| 402 | if( ( md_info = md_info_from_type( POLARSSL_MD_SHA1 ) ) == NULL ) |
| 403 | exit(1); |
| 404 | |
| 405 | if( hmac_drbg_init( &hmac_drbg, md_info, myrand, NULL, NULL, 0 ) != 0 ) |
| 406 | exit(1); |
| 407 | TIME_AND_TSC( "HMAC_DRBG SHA-1 (NOPR)", |
| 408 | if( hmac_drbg_random( &hmac_drbg, buf, BUFSIZE ) != 0 ) |
| 409 | exit(1) ); |
| 410 | hmac_drbg_free( &hmac_drbg ); |
| 411 | |
| 412 | if( hmac_drbg_init( &hmac_drbg, md_info, myrand, NULL, NULL, 0 ) != 0 ) |
| 413 | exit(1); |
| 414 | hmac_drbg_set_prediction_resistance( &hmac_drbg, |
| 415 | POLARSSL_HMAC_DRBG_PR_ON ); |
| 416 | TIME_AND_TSC( "HMAC_DRBG SHA-1 (PR)", |
| 417 | if( hmac_drbg_random( &hmac_drbg, buf, BUFSIZE ) != 0 ) |
| 418 | exit(1) ); |
| 419 | hmac_drbg_free( &hmac_drbg ); |
| 420 | #endif |
| 421 | |
| 422 | #if defined(POLARSSL_SHA256_C) |
| 423 | if( ( md_info = md_info_from_type( POLARSSL_MD_SHA256 ) ) == NULL ) |
| 424 | exit(1); |
| 425 | |
| 426 | if( hmac_drbg_init( &hmac_drbg, md_info, myrand, NULL, NULL, 0 ) != 0 ) |
| 427 | exit(1); |
| 428 | TIME_AND_TSC( "HMAC_DRBG SHA-256 (NOPR)", |
| 429 | if( hmac_drbg_random( &hmac_drbg, buf, BUFSIZE ) != 0 ) |
| 430 | exit(1) ); |
| 431 | hmac_drbg_free( &hmac_drbg ); |
| 432 | |
| 433 | if( hmac_drbg_init( &hmac_drbg, md_info, myrand, NULL, NULL, 0 ) != 0 ) |
| 434 | exit(1); |
| 435 | hmac_drbg_set_prediction_resistance( &hmac_drbg, |
| 436 | POLARSSL_HMAC_DRBG_PR_ON ); |
| 437 | TIME_AND_TSC( "HMAC_DRBG SHA-256 (PR)", |
| 438 | if( hmac_drbg_random( &hmac_drbg, buf, BUFSIZE ) != 0 ) |
| 439 | exit(1) ); |
| 440 | hmac_drbg_free( &hmac_drbg ); |
| 441 | #endif |
| 442 | } |
| 443 | #endif |
| 444 | |
Manuel Pégourié-Gonnard | 8271f2f | 2013-09-17 14:57:55 +0200 | [diff] [blame] | 445 | #if defined(POLARSSL_RSA_C) && defined(POLARSSL_GENPRIME) |
Manuel Pégourié-Gonnard | ed7cbe9 | 2013-09-17 15:30:51 +0200 | [diff] [blame] | 446 | if( todo.rsa ) |
Paul Bakker | 5121ce5 | 2009-01-03 21:22:43 +0000 | [diff] [blame] | 447 | { |
Manuel Pégourié-Gonnard | 8271f2f | 2013-09-17 14:57:55 +0200 | [diff] [blame] | 448 | rsa_context rsa; |
| 449 | for( keysize = 1024; keysize <= 4096; keysize *= 2 ) |
| 450 | { |
| 451 | snprintf( title, sizeof( title ), "RSA-%d", keysize ); |
| 452 | |
| 453 | rsa_init( &rsa, RSA_PKCS_V15, 0 ); |
| 454 | rsa_gen_key( &rsa, myrand, NULL, keysize, 65537 ); |
| 455 | |
| 456 | TIME_PUBLIC( title, " public", |
| 457 | buf[0] = 0; |
| 458 | ret = rsa_public( &rsa, buf, buf ) ); |
| 459 | |
| 460 | TIME_PUBLIC( title, "private", |
| 461 | buf[0] = 0; |
| 462 | ret = rsa_private( &rsa, myrand, NULL, buf, buf ) ); |
| 463 | |
| 464 | rsa_free( &rsa ); |
| 465 | } |
Paul Bakker | 5121ce5 | 2009-01-03 21:22:43 +0000 | [diff] [blame] | 466 | } |
Paul Bakker | 5121ce5 | 2009-01-03 21:22:43 +0000 | [diff] [blame] | 467 | #endif |
| 468 | |
Manuel Pégourié-Gonnard | e870c0a | 2012-11-08 11:31:48 +0100 | [diff] [blame] | 469 | #if defined(POLARSSL_DHM_C) && defined(POLARSSL_BIGNUM_C) |
Manuel Pégourié-Gonnard | ed7cbe9 | 2013-09-17 15:30:51 +0200 | [diff] [blame] | 470 | if( todo.dhm ) |
Manuel Pégourié-Gonnard | e870c0a | 2012-11-08 11:31:48 +0100 | [diff] [blame] | 471 | { |
Manuel Pégourié-Gonnard | 8271f2f | 2013-09-17 14:57:55 +0200 | [diff] [blame] | 472 | #define DHM_SIZES 3 |
Manuel Pégourié-Gonnard | ed7cbe9 | 2013-09-17 15:30:51 +0200 | [diff] [blame] | 473 | int dhm_sizes[DHM_SIZES] = { 1024, 2048, 3072 }; |
Manuel Pégourié-Gonnard | 8271f2f | 2013-09-17 14:57:55 +0200 | [diff] [blame] | 474 | const char *dhm_P[DHM_SIZES] = { |
| 475 | POLARSSL_DHM_RFC5114_MODP_1024_P, |
| 476 | POLARSSL_DHM_RFC3526_MODP_2048_P, |
| 477 | POLARSSL_DHM_RFC3526_MODP_3072_P, |
| 478 | }; |
| 479 | const char *dhm_G[DHM_SIZES] = { |
| 480 | POLARSSL_DHM_RFC5114_MODP_1024_G, |
| 481 | POLARSSL_DHM_RFC3526_MODP_2048_G, |
| 482 | POLARSSL_DHM_RFC3526_MODP_3072_G, |
| 483 | }; |
| 484 | |
| 485 | dhm_context dhm; |
| 486 | size_t olen; |
Manuel Pégourié-Gonnard | ed7cbe9 | 2013-09-17 15:30:51 +0200 | [diff] [blame] | 487 | for( i = 0; i < DHM_SIZES; i++ ) |
Manuel Pégourié-Gonnard | 8271f2f | 2013-09-17 14:57:55 +0200 | [diff] [blame] | 488 | { |
| 489 | memset( &dhm, 0, sizeof( dhm_context ) ); |
| 490 | |
Paul Bakker | cbe3d0d | 2014-04-17 16:00:59 +0200 | [diff] [blame] | 491 | if( mpi_read_string( &dhm.P, 16, dhm_P[i] ) != 0 || |
| 492 | mpi_read_string( &dhm.G, 16, dhm_G[i] ) != 0 ) |
| 493 | { |
| 494 | exit( 1 ); |
| 495 | } |
| 496 | |
Manuel Pégourié-Gonnard | 8271f2f | 2013-09-17 14:57:55 +0200 | [diff] [blame] | 497 | dhm.len = mpi_size( &dhm.P ); |
Paul Bakker | 840ab20 | 2013-11-30 15:14:38 +0100 | [diff] [blame] | 498 | dhm_make_public( &dhm, (int) dhm.len, buf, dhm.len, myrand, NULL ); |
Paul Bakker | cbe3d0d | 2014-04-17 16:00:59 +0200 | [diff] [blame] | 499 | if( mpi_copy( &dhm.GY, &dhm.GX ) != 0 ) |
| 500 | exit( 1 ); |
Manuel Pégourié-Gonnard | 8271f2f | 2013-09-17 14:57:55 +0200 | [diff] [blame] | 501 | |
Manuel Pégourié-Gonnard | cc34f95 | 2013-09-17 16:04:08 +0200 | [diff] [blame] | 502 | snprintf( title, sizeof( title ), "DHE-%d", dhm_sizes[i] ); |
Manuel Pégourié-Gonnard | 8271f2f | 2013-09-17 14:57:55 +0200 | [diff] [blame] | 503 | TIME_PUBLIC( title, "handshake", |
| 504 | olen = sizeof( buf ); |
Paul Bakker | 840ab20 | 2013-11-30 15:14:38 +0100 | [diff] [blame] | 505 | ret |= dhm_make_public( &dhm, (int) dhm.len, buf, dhm.len, |
Manuel Pégourié-Gonnard | 8271f2f | 2013-09-17 14:57:55 +0200 | [diff] [blame] | 506 | myrand, NULL ); |
| 507 | ret |= dhm_calc_secret( &dhm, buf, &olen, myrand, NULL ) ); |
| 508 | |
Manuel Pégourié-Gonnard | cc34f95 | 2013-09-17 16:04:08 +0200 | [diff] [blame] | 509 | snprintf( title, sizeof( title ), "DH-%d", dhm_sizes[i] ); |
Manuel Pégourié-Gonnard | 8271f2f | 2013-09-17 14:57:55 +0200 | [diff] [blame] | 510 | TIME_PUBLIC( title, "handshake", |
| 511 | olen = sizeof( buf ); |
| 512 | ret |= dhm_calc_secret( &dhm, buf, &olen, myrand, NULL ) ); |
| 513 | |
| 514 | dhm_free( &dhm ); |
| 515 | } |
Manuel Pégourié-Gonnard | e870c0a | 2012-11-08 11:31:48 +0100 | [diff] [blame] | 516 | } |
Manuel Pégourié-Gonnard | e870c0a | 2012-11-08 11:31:48 +0100 | [diff] [blame] | 517 | #endif |
| 518 | |
Manuel Pégourié-Gonnard | cc34f95 | 2013-09-17 16:04:08 +0200 | [diff] [blame] | 519 | #if defined(POLARSSL_ECDSA_C) |
| 520 | if( todo.ecdsa ) |
| 521 | { |
| 522 | ecdsa_context ecdsa; |
| 523 | const ecp_curve_info *curve_info; |
| 524 | size_t sig_len; |
| 525 | |
| 526 | memset( buf, 0x2A, sizeof( buf ) ); |
| 527 | |
Manuel Pégourié-Gonnard | da179e4 | 2013-09-18 15:31:24 +0200 | [diff] [blame] | 528 | for( curve_info = ecp_curve_list(); |
Manuel Pégourié-Gonnard | cc34f95 | 2013-09-17 16:04:08 +0200 | [diff] [blame] | 529 | curve_info->grp_id != POLARSSL_ECP_DP_NONE; |
| 530 | curve_info++ ) |
| 531 | { |
| 532 | ecdsa_init( &ecdsa ); |
| 533 | |
| 534 | if( ecdsa_genkey( &ecdsa, curve_info->grp_id, myrand, NULL ) != 0 ) |
| 535 | exit( 1 ); |
| 536 | |
Manuel Pégourié-Gonnard | 56cd319 | 2013-09-17 17:23:07 +0200 | [diff] [blame] | 537 | snprintf( title, sizeof( title ), "ECDSA-%s", |
| 538 | curve_info->name ); |
Manuel Pégourié-Gonnard | cc34f95 | 2013-09-17 16:04:08 +0200 | [diff] [blame] | 539 | TIME_PUBLIC( title, "sign", |
| 540 | ret = ecdsa_write_signature( &ecdsa, buf, curve_info->size, |
Manuel Pégourié-Gonnard | 56cd319 | 2013-09-17 17:23:07 +0200 | [diff] [blame] | 541 | tmp, &sig_len, myrand, NULL ) ); |
| 542 | |
| 543 | TIME_PUBLIC( title, "verify", |
| 544 | ret = ecdsa_read_signature( &ecdsa, buf, curve_info->size, |
| 545 | tmp, sig_len ) ); |
Manuel Pégourié-Gonnard | cc34f95 | 2013-09-17 16:04:08 +0200 | [diff] [blame] | 546 | |
| 547 | ecdsa_free( &ecdsa ); |
| 548 | } |
| 549 | } |
| 550 | #endif |
| 551 | |
| 552 | #if defined(POLARSSL_ECDH_C) |
| 553 | if( todo.ecdh ) |
| 554 | { |
| 555 | ecdh_context ecdh; |
| 556 | const ecp_curve_info *curve_info; |
| 557 | size_t olen; |
| 558 | |
Manuel Pégourié-Gonnard | da179e4 | 2013-09-18 15:31:24 +0200 | [diff] [blame] | 559 | for( curve_info = ecp_curve_list(); |
Manuel Pégourié-Gonnard | cc34f95 | 2013-09-17 16:04:08 +0200 | [diff] [blame] | 560 | curve_info->grp_id != POLARSSL_ECP_DP_NONE; |
| 561 | curve_info++ ) |
| 562 | { |
| 563 | ecdh_init( &ecdh ); |
| 564 | |
| 565 | if( ecp_use_known_dp( &ecdh.grp, curve_info->grp_id ) != 0 || |
| 566 | ecdh_make_public( &ecdh, &olen, buf, sizeof( buf), |
| 567 | myrand, NULL ) != 0 || |
| 568 | ecp_copy( &ecdh.Qp, &ecdh.Q ) != 0 ) |
| 569 | { |
| 570 | exit( 1 ); |
| 571 | } |
| 572 | |
Manuel Pégourié-Gonnard | 56cd319 | 2013-09-17 17:23:07 +0200 | [diff] [blame] | 573 | snprintf( title, sizeof( title ), "ECDHE-%s", |
| 574 | curve_info->name ); |
Manuel Pégourié-Gonnard | cc34f95 | 2013-09-17 16:04:08 +0200 | [diff] [blame] | 575 | TIME_PUBLIC( title, "handshake", |
| 576 | ret |= ecdh_make_public( &ecdh, &olen, buf, sizeof( buf), |
| 577 | myrand, NULL ); |
| 578 | ret |= ecdh_calc_secret( &ecdh, &olen, buf, sizeof( buf ), |
| 579 | myrand, NULL ) ); |
| 580 | |
Manuel Pégourié-Gonnard | 56cd319 | 2013-09-17 17:23:07 +0200 | [diff] [blame] | 581 | snprintf( title, sizeof( title ), "ECDH-%s", |
| 582 | curve_info->name ); |
Manuel Pégourié-Gonnard | cc34f95 | 2013-09-17 16:04:08 +0200 | [diff] [blame] | 583 | TIME_PUBLIC( title, "handshake", |
| 584 | ret |= ecdh_calc_secret( &ecdh, &olen, buf, sizeof( buf ), |
| 585 | myrand, NULL ) ); |
| 586 | ecdh_free( &ecdh ); |
| 587 | } |
| 588 | } |
| 589 | #endif |
Paul Bakker | 1d4da2e | 2009-10-25 12:36:53 +0000 | [diff] [blame] | 590 | printf( "\n" ); |
| 591 | |
Paul Bakker | cce9d77 | 2011-11-18 14:26:47 +0000 | [diff] [blame] | 592 | #if defined(_WIN32) |
Paul Bakker | 5121ce5 | 2009-01-03 21:22:43 +0000 | [diff] [blame] | 593 | printf( " Press Enter to exit this program.\n" ); |
| 594 | fflush( stdout ); getchar(); |
| 595 | #endif |
| 596 | |
| 597 | return( 0 ); |
| 598 | } |
Manuel Pégourié-Gonnard | 8271f2f | 2013-09-17 14:57:55 +0200 | [diff] [blame] | 599 | |
Paul Bakker | 5690efc | 2011-05-26 13:16:06 +0000 | [diff] [blame] | 600 | #endif /* POLARSSL_TIMING_C */ |