summaryrefslogtreecommitdiff
path: root/src/lib
diff options
context:
space:
mode:
authorjsing <>2014-04-24 12:04:31 +0000
committerjsing <>2014-04-24 12:04:31 +0000
commit6923103673e413744c67110027c3358d8e469927 (patch)
treea950dd4b33f1e1ed1699082c5067673b72a1fd0d /src/lib
parent7092ac256a7a418fb6aa87744bbed6d1101ea9f8 (diff)
downloadopenbsd-6923103673e413744c67110027c3358d8e469927.tar.gz
openbsd-6923103673e413744c67110027c3358d8e469927.tar.bz2
openbsd-6923103673e413744c67110027c3358d8e469927.zip
Rip a bunch of ifdefs from speed. We know we can fork, have SIGALRM and
do not use lint. ok miod@
Diffstat (limited to 'src/lib')
-rw-r--r--src/lib/libssl/src/apps/speed.c269
1 files changed, 2 insertions, 267 deletions
diff --git a/src/lib/libssl/src/apps/speed.c b/src/lib/libssl/src/apps/speed.c
index ea9a0fd6c3..56abf47c0e 100644
--- a/src/lib/libssl/src/apps/speed.c
+++ b/src/lib/libssl/src/apps/speed.c
@@ -173,16 +173,6 @@
173#include <openssl/modes.h> 173#include <openssl/modes.h>
174 174
175 175
176#ifndef HAVE_FORK
177#define HAVE_FORK 1
178#endif
179
180#if HAVE_FORK
181#undef NO_FORK
182#else
183#define NO_FORK
184#endif
185
186#undef BUFSIZE 176#undef BUFSIZE
187#define BUFSIZE ((long)1024*8+1) 177#define BUFSIZE ((long)1024*8+1)
188int run = 0; 178int run = 0;
@@ -196,9 +186,7 @@ static void
196pkey_print_message(const char *str, const char *str2, 186pkey_print_message(const char *str, const char *str2,
197 long num, int bits, int sec); 187 long num, int bits, int sec);
198static void print_result(int alg, int run_no, int count, double time_used); 188static void print_result(int alg, int run_no, int count, double time_used);
199#ifndef NO_FORK
200static int do_multi(int multi); 189static int do_multi(int multi);
201#endif
202 190
203#define ALGOR_NUM 30 191#define ALGOR_NUM 30
204#define SIZE_NUM 5 192#define SIZE_NUM 5
@@ -231,24 +219,14 @@ static double ecdsa_results[EC_NUM][2];
231static double ecdh_results[EC_NUM][1]; 219static double ecdh_results[EC_NUM][1];
232#endif 220#endif
233 221
234#ifdef SIGALRM 222static void sig_done(int sig);
235#if defined(__STDC__) || defined(sgi) || defined(_AIX)
236#define SIGRETTYPE void
237#else
238#define SIGRETTYPE int
239#endif
240 223
241static SIGRETTYPE sig_done(int sig); 224static void
242static SIGRETTYPE
243sig_done(int sig) 225sig_done(int sig)
244{ 226{
245 signal(SIGALRM, sig_done); 227 signal(SIGALRM, sig_done);
246 run = 0; 228 run = 0;
247#ifdef LINT
248 sig = sig;
249#endif
250} 229}
251#endif
252 230
253#define START 0 231#define START 0
254#define STOP 1 232#define STOP 1
@@ -549,9 +527,7 @@ speed_main(int argc, char **argv)
549 const EVP_CIPHER *evp_cipher = NULL; 527 const EVP_CIPHER *evp_cipher = NULL;
550 const EVP_MD *evp_md = NULL; 528 const EVP_MD *evp_md = NULL;
551 int decrypt = 0; 529 int decrypt = 0;
552#ifndef NO_FORK
553 int multi = 0; 530 int multi = 0;
554#endif
555 531
556#ifndef TIMES 532#ifndef TIMES
557 usertime = -1; 533 usertime = -1;
@@ -662,7 +638,6 @@ speed_main(int argc, char **argv)
662 j--; 638 j--;
663 } 639 }
664#endif 640#endif
665#ifndef NO_FORK
666 else if ((argc > 0) && (strcmp(*argv, "-multi") == 0)) { 641 else if ((argc > 0) && (strcmp(*argv, "-multi") == 0)) {
667 argc--; 642 argc--;
668 argv++; 643 argv++;
@@ -678,7 +653,6 @@ speed_main(int argc, char **argv)
678 j--; /* Otherwise, -mr gets confused with an 653 j--; /* Otherwise, -mr gets confused with an
679 * algorithm. */ 654 * algorithm. */
680 } 655 }
681#endif
682 else if (argc > 0 && !strcmp(*argv, "-mr")) { 656 else if (argc > 0 && !strcmp(*argv, "-mr")) {
683 mr = 1; 657 mr = 1;
684 j--; /* Otherwise, -mr gets confused with an 658 j--; /* Otherwise, -mr gets confused with an
@@ -1104,9 +1078,7 @@ speed_main(int argc, char **argv)
1104 BIO_printf(bio_err, "-evp e use EVP e.\n"); 1078 BIO_printf(bio_err, "-evp e use EVP e.\n");
1105 BIO_printf(bio_err, "-decrypt time decryption instead of encryption (only EVP).\n"); 1079 BIO_printf(bio_err, "-decrypt time decryption instead of encryption (only EVP).\n");
1106 BIO_printf(bio_err, "-mr produce machine readable output.\n"); 1080 BIO_printf(bio_err, "-mr produce machine readable output.\n");
1107#ifndef NO_FORK
1108 BIO_printf(bio_err, "-multi n run n benchmarks in parallel.\n"); 1081 BIO_printf(bio_err, "-multi n run n benchmarks in parallel.\n");
1109#endif
1110 goto end; 1082 goto end;
1111 } 1083 }
1112 argc--; 1084 argc--;
@@ -1114,10 +1086,8 @@ speed_main(int argc, char **argv)
1114 j++; 1086 j++;
1115 } 1087 }
1116 1088
1117#ifndef NO_FORK
1118 if (multi && do_multi(multi)) 1089 if (multi && do_multi(multi))
1119 goto show_res; 1090 goto show_res;
1120#endif
1121 1091
1122 if (j == 0) { 1092 if (j == 0) {
1123 for (i = 0; i < ALGOR_NUM; i++) { 1093 for (i = 0; i < ALGOR_NUM; i++) {
@@ -1211,222 +1181,9 @@ speed_main(int argc, char **argv)
1211#ifndef OPENSSL_NO_RSA 1181#ifndef OPENSSL_NO_RSA
1212 memset(rsa_c, 0, sizeof(rsa_c)); 1182 memset(rsa_c, 0, sizeof(rsa_c));
1213#endif 1183#endif
1214#ifndef SIGALRM
1215#ifndef OPENSSL_NO_DES
1216 BIO_printf(bio_err, "First we calculate the approximate speed ...\n");
1217 count = 10;
1218 do {
1219 long it;
1220 count *= 2;
1221 Time_F(START);
1222 for (it = count; it; it--)
1223 DES_ecb_encrypt((DES_cblock *) buf,
1224 (DES_cblock *) buf,
1225 &sch, DES_ENCRYPT);
1226 d = Time_F(STOP);
1227 } while (d < 3);
1228 save_count = count;
1229 c[D_MD2][0] = count / 10;
1230 c[D_MDC2][0] = count / 10;
1231 c[D_MD4][0] = count;
1232 c[D_MD5][0] = count;
1233 c[D_HMAC][0] = count;
1234 c[D_SHA1][0] = count;
1235 c[D_RMD160][0] = count;
1236 c[D_RC4][0] = count * 5;
1237 c[D_CBC_DES][0] = count;
1238 c[D_EDE3_DES][0] = count / 3;
1239 c[D_CBC_IDEA][0] = count;
1240 c[D_CBC_SEED][0] = count;
1241 c[D_CBC_RC2][0] = count;
1242 c[D_CBC_RC5][0] = count;
1243 c[D_CBC_BF][0] = count;
1244 c[D_CBC_CAST][0] = count;
1245 c[D_CBC_128_AES][0] = count;
1246 c[D_CBC_192_AES][0] = count;
1247 c[D_CBC_256_AES][0] = count;
1248 c[D_CBC_128_CML][0] = count;
1249 c[D_CBC_192_CML][0] = count;
1250 c[D_CBC_256_CML][0] = count;
1251 c[D_SHA256][0] = count;
1252 c[D_SHA512][0] = count;
1253 c[D_WHIRLPOOL][0] = count;
1254 c[D_IGE_128_AES][0] = count;
1255 c[D_IGE_192_AES][0] = count;
1256 c[D_IGE_256_AES][0] = count;
1257 c[D_GHASH][0] = count;
1258
1259 for (i = 1; i < SIZE_NUM; i++) {
1260 c[D_MD2][i] = c[D_MD2][0] * 4 * lengths[0] / lengths[i];
1261 c[D_MDC2][i] = c[D_MDC2][0] * 4 * lengths[0] / lengths[i];
1262 c[D_MD4][i] = c[D_MD4][0] * 4 * lengths[0] / lengths[i];
1263 c[D_MD5][i] = c[D_MD5][0] * 4 * lengths[0] / lengths[i];
1264 c[D_HMAC][i] = c[D_HMAC][0] * 4 * lengths[0] / lengths[i];
1265 c[D_SHA1][i] = c[D_SHA1][0] * 4 * lengths[0] / lengths[i];
1266 c[D_RMD160][i] = c[D_RMD160][0] * 4 * lengths[0] / lengths[i];
1267 c[D_SHA256][i] = c[D_SHA256][0] * 4 * lengths[0] / lengths[i];
1268 c[D_SHA512][i] = c[D_SHA512][0] * 4 * lengths[0] / lengths[i];
1269 c[D_WHIRLPOOL][i] = c[D_WHIRLPOOL][0] * 4 * lengths[0] / lengths[i];
1270 }
1271 for (i = 1; i < SIZE_NUM; i++) {
1272 long l0, l1;
1273
1274 l0 = (long) lengths[i - 1];
1275 l1 = (long) lengths[i];
1276 c[D_RC4][i] = c[D_RC4][i - 1] * l0 / l1;
1277 c[D_CBC_DES][i] = c[D_CBC_DES][i - 1] * l0 / l1;
1278 c[D_EDE3_DES][i] = c[D_EDE3_DES][i - 1] * l0 / l1;
1279 c[D_CBC_IDEA][i] = c[D_CBC_IDEA][i - 1] * l0 / l1;
1280 c[D_CBC_SEED][i] = c[D_CBC_SEED][i - 1] * l0 / l1;
1281 c[D_CBC_RC2][i] = c[D_CBC_RC2][i - 1] * l0 / l1;
1282 c[D_CBC_RC5][i] = c[D_CBC_RC5][i - 1] * l0 / l1;
1283 c[D_CBC_BF][i] = c[D_CBC_BF][i - 1] * l0 / l1;
1284 c[D_CBC_CAST][i] = c[D_CBC_CAST][i - 1] * l0 / l1;
1285 c[D_CBC_128_AES][i] = c[D_CBC_128_AES][i - 1] * l0 / l1;
1286 c[D_CBC_192_AES][i] = c[D_CBC_192_AES][i - 1] * l0 / l1;
1287 c[D_CBC_256_AES][i] = c[D_CBC_256_AES][i - 1] * l0 / l1;
1288 c[D_CBC_128_CML][i] = c[D_CBC_128_CML][i - 1] * l0 / l1;
1289 c[D_CBC_192_CML][i] = c[D_CBC_192_CML][i - 1] * l0 / l1;
1290 c[D_CBC_256_CML][i] = c[D_CBC_256_CML][i - 1] * l0 / l1;
1291 c[D_IGE_128_AES][i] = c[D_IGE_128_AES][i - 1] * l0 / l1;
1292 c[D_IGE_192_AES][i] = c[D_IGE_192_AES][i - 1] * l0 / l1;
1293 c[D_IGE_256_AES][i] = c[D_IGE_256_AES][i - 1] * l0 / l1;
1294 }
1295#ifndef OPENSSL_NO_RSA
1296 rsa_c[R_RSA_512][0] = count / 2000;
1297 rsa_c[R_RSA_512][1] = count / 400;
1298 for (i = 1; i < RSA_NUM; i++) {
1299 rsa_c[i][0] = rsa_c[i - 1][0] / 8;
1300 rsa_c[i][1] = rsa_c[i - 1][1] / 4;
1301 if ((rsa_doit[i] <= 1) && (rsa_c[i][0] == 0))
1302 rsa_doit[i] = 0;
1303 else {
1304 if (rsa_c[i][0] == 0) {
1305 rsa_c[i][0] = 1;
1306 rsa_c[i][1] = 20;
1307 }
1308 }
1309 }
1310#endif
1311
1312#ifndef OPENSSL_NO_DSA
1313 dsa_c[R_DSA_512][0] = count / 1000;
1314 dsa_c[R_DSA_512][1] = count / 1000 / 2;
1315 for (i = 1; i < DSA_NUM; i++) {
1316 dsa_c[i][0] = dsa_c[i - 1][0] / 4;
1317 dsa_c[i][1] = dsa_c[i - 1][1] / 4;
1318 if ((dsa_doit[i] <= 1) && (dsa_c[i][0] == 0))
1319 dsa_doit[i] = 0;
1320 else {
1321 if (dsa_c[i] == 0) {
1322 dsa_c[i][0] = 1;
1323 dsa_c[i][1] = 1;
1324 }
1325 }
1326 }
1327#endif
1328
1329#ifndef OPENSSL_NO_ECDSA
1330 ecdsa_c[R_EC_P160][0] = count / 1000;
1331 ecdsa_c[R_EC_P160][1] = count / 1000 / 2;
1332 for (i = R_EC_P192; i <= R_EC_P521; i++) {
1333 ecdsa_c[i][0] = ecdsa_c[i - 1][0] / 2;
1334 ecdsa_c[i][1] = ecdsa_c[i - 1][1] / 2;
1335 if ((ecdsa_doit[i] <= 1) && (ecdsa_c[i][0] == 0))
1336 ecdsa_doit[i] = 0;
1337 else {
1338 if (ecdsa_c[i] == 0) {
1339 ecdsa_c[i][0] = 1;
1340 ecdsa_c[i][1] = 1;
1341 }
1342 }
1343 }
1344 ecdsa_c[R_EC_K163][0] = count / 1000;
1345 ecdsa_c[R_EC_K163][1] = count / 1000 / 2;
1346 for (i = R_EC_K233; i <= R_EC_K571; i++) {
1347 ecdsa_c[i][0] = ecdsa_c[i - 1][0] / 2;
1348 ecdsa_c[i][1] = ecdsa_c[i - 1][1] / 2;
1349 if ((ecdsa_doit[i] <= 1) && (ecdsa_c[i][0] == 0))
1350 ecdsa_doit[i] = 0;
1351 else {
1352 if (ecdsa_c[i] == 0) {
1353 ecdsa_c[i][0] = 1;
1354 ecdsa_c[i][1] = 1;
1355 }
1356 }
1357 }
1358 ecdsa_c[R_EC_B163][0] = count / 1000;
1359 ecdsa_c[R_EC_B163][1] = count / 1000 / 2;
1360 for (i = R_EC_B233; i <= R_EC_B571; i++) {
1361 ecdsa_c[i][0] = ecdsa_c[i - 1][0] / 2;
1362 ecdsa_c[i][1] = ecdsa_c[i - 1][1] / 2;
1363 if ((ecdsa_doit[i] <= 1) && (ecdsa_c[i][0] == 0))
1364 ecdsa_doit[i] = 0;
1365 else {
1366 if (ecdsa_c[i] == 0) {
1367 ecdsa_c[i][0] = 1;
1368 ecdsa_c[i][1] = 1;
1369 }
1370 }
1371 }
1372#endif
1373
1374#ifndef OPENSSL_NO_ECDH
1375 ecdh_c[R_EC_P160][0] = count / 1000;
1376 ecdh_c[R_EC_P160][1] = count / 1000;
1377 for (i = R_EC_P192; i <= R_EC_P521; i++) {
1378 ecdh_c[i][0] = ecdh_c[i - 1][0] / 2;
1379 ecdh_c[i][1] = ecdh_c[i - 1][1] / 2;
1380 if ((ecdh_doit[i] <= 1) && (ecdh_c[i][0] == 0))
1381 ecdh_doit[i] = 0;
1382 else {
1383 if (ecdh_c[i] == 0) {
1384 ecdh_c[i][0] = 1;
1385 ecdh_c[i][1] = 1;
1386 }
1387 }
1388 }
1389 ecdh_c[R_EC_K163][0] = count / 1000;
1390 ecdh_c[R_EC_K163][1] = count / 1000;
1391 for (i = R_EC_K233; i <= R_EC_K571; i++) {
1392 ecdh_c[i][0] = ecdh_c[i - 1][0] / 2;
1393 ecdh_c[i][1] = ecdh_c[i - 1][1] / 2;
1394 if ((ecdh_doit[i] <= 1) && (ecdh_c[i][0] == 0))
1395 ecdh_doit[i] = 0;
1396 else {
1397 if (ecdh_c[i] == 0) {
1398 ecdh_c[i][0] = 1;
1399 ecdh_c[i][1] = 1;
1400 }
1401 }
1402 }
1403 ecdh_c[R_EC_B163][0] = count / 1000;
1404 ecdh_c[R_EC_B163][1] = count / 1000;
1405 for (i = R_EC_B233; i <= R_EC_B571; i++) {
1406 ecdh_c[i][0] = ecdh_c[i - 1][0] / 2;
1407 ecdh_c[i][1] = ecdh_c[i - 1][1] / 2;
1408 if ((ecdh_doit[i] <= 1) && (ecdh_c[i][0] == 0))
1409 ecdh_doit[i] = 0;
1410 else {
1411 if (ecdh_c[i] == 0) {
1412 ecdh_c[i][0] = 1;
1413 ecdh_c[i][1] = 1;
1414 }
1415 }
1416 }
1417#endif
1418
1419#define COND(d) (count < (d))
1420#define COUNT(d) (d)
1421#else
1422/* not worth fixing */
1423#error "You cannot disable DES on systems without SIGALRM."
1424#endif /* OPENSSL_NO_DES */
1425#else
1426#define COND(c) (run && count<0x7fffffff) 1184#define COND(c) (run && count<0x7fffffff)
1427#define COUNT(d) (count) 1185#define COUNT(d) (count)
1428 signal(SIGALRM, sig_done); 1186 signal(SIGALRM, sig_done);
1429#endif /* SIGALRM */
1430 1187
1431#ifndef OPENSSL_NO_MD2 1188#ifndef OPENSSL_NO_MD2
1432 if (doit[D_MD2]) { 1189 if (doit[D_MD2]) {
@@ -2186,9 +1943,7 @@ speed_main(int argc, char **argv)
2186 } 1943 }
2187 } 1944 }
2188#endif 1945#endif
2189#ifndef NO_FORK
2190show_res: 1946show_res:
2191#endif
2192 if (!mr) { 1947 if (!mr) {
2193 fprintf(stdout, "%s\n", SSLeay_version(SSLEAY_VERSION)); 1948 fprintf(stdout, "%s\n", SSLeay_version(SSLEAY_VERSION));
2194 fprintf(stdout, "%s\n", SSLeay_version(SSLEAY_BUILT_ON)); 1949 fprintf(stdout, "%s\n", SSLeay_version(SSLEAY_BUILT_ON));
@@ -2363,38 +2118,20 @@ end:
2363static void 2118static void
2364print_message(const char *s, long num, int length) 2119print_message(const char *s, long num, int length)
2365{ 2120{
2366#ifdef SIGALRM
2367 BIO_printf(bio_err, mr ? "+DT:%s:%d:%d\n" 2121 BIO_printf(bio_err, mr ? "+DT:%s:%d:%d\n"
2368 : "Doing %s for %ds on %d size blocks: ", s, SECONDS, length); 2122 : "Doing %s for %ds on %d size blocks: ", s, SECONDS, length);
2369 (void) BIO_flush(bio_err); 2123 (void) BIO_flush(bio_err);
2370 alarm(SECONDS); 2124 alarm(SECONDS);
2371#else
2372 BIO_printf(bio_err, mr ? "+DN:%s:%ld:%d\n"
2373 : "Doing %s %ld times on %d size blocks: ", s, num, length);
2374 (void) BIO_flush(bio_err);
2375#endif
2376#ifdef LINT
2377 num = num;
2378#endif
2379} 2125}
2380 2126
2381static void 2127static void
2382pkey_print_message(const char *str, const char *str2, long num, 2128pkey_print_message(const char *str, const char *str2, long num,
2383 int bits, int tm) 2129 int bits, int tm)
2384{ 2130{
2385#ifdef SIGALRM
2386 BIO_printf(bio_err, mr ? "+DTP:%d:%s:%s:%d\n" 2131 BIO_printf(bio_err, mr ? "+DTP:%d:%s:%s:%d\n"
2387 : "Doing %d bit %s %s's for %ds: ", bits, str, str2, tm); 2132 : "Doing %d bit %s %s's for %ds: ", bits, str, str2, tm);
2388 (void) BIO_flush(bio_err); 2133 (void) BIO_flush(bio_err);
2389 alarm(tm); 2134 alarm(tm);
2390#else
2391 BIO_printf(bio_err, mr ? "+DNP:%ld:%d:%s:%s\n"
2392 : "Doing %ld %d bit %s %s's: ", num, bits, str, str2);
2393 (void) BIO_flush(bio_err);
2394#endif
2395#ifdef LINT
2396 num = num;
2397#endif
2398} 2135}
2399 2136
2400static void 2137static void
@@ -2405,7 +2142,6 @@ print_result(int alg, int run_no, int count, double time_used)
2405 results[alg][run_no] = ((double) count) / time_used * lengths[run_no]; 2142 results[alg][run_no] = ((double) count) / time_used * lengths[run_no];
2406} 2143}
2407 2144
2408#ifndef NO_FORK
2409static char * 2145static char *
2410sstrsep(char **string, const char *delim) 2146sstrsep(char **string, const char *delim)
2411{ 2147{
@@ -2608,4 +2344,3 @@ do_multi(int multi)
2608 return 1; 2344 return 1;
2609} 2345}
2610#endif 2346#endif
2611#endif