summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authortb <>2021-12-12 20:35:40 +0000
committertb <>2021-12-12 20:35:40 +0000
commitf82f1d237145260c8e0c96710a50c98367acc37d (patch)
tree723a25a67cffe50e0b63df44288436d4b7d76a53
parent3f19462ef9f7b14cbdfe731cbd045f86e3e05b24 (diff)
downloadopenbsd-f82f1d237145260c8e0c96710a50c98367acc37d.tar.gz
openbsd-f82f1d237145260c8e0c96710a50c98367acc37d.tar.bz2
openbsd-f82f1d237145260c8e0c96710a50c98367acc37d.zip
Make speed.c compile with opaque EVP_CIPHER, EVP_MD and HMAC_CTX.
ok inoguchi
-rw-r--r--src/usr.bin/openssl/speed.c49
1 files changed, 29 insertions, 20 deletions
diff --git a/src/usr.bin/openssl/speed.c b/src/usr.bin/openssl/speed.c
index 3d226a204e..5b9b324493 100644
--- a/src/usr.bin/openssl/speed.c
+++ b/src/usr.bin/openssl/speed.c
@@ -1,4 +1,4 @@
1/* $OpenBSD: speed.c,v 1.23 2018/07/13 18:36:56 cheloha Exp $ */ 1/* $OpenBSD: speed.c,v 1.24 2021/12/12 20:35:40 tb Exp $ */
2/* Copyright (C) 1995-1998 Eric Young (eay@cryptsoft.com) 2/* Copyright (C) 1995-1998 Eric Young (eay@cryptsoft.com)
3 * All rights reserved. 3 * All rights reserved.
4 * 4 *
@@ -1031,24 +1031,28 @@ speed_main(int argc, char **argv)
1031 1031
1032#if !defined(OPENSSL_NO_MD5) && !defined(OPENSSL_NO_HMAC) 1032#if !defined(OPENSSL_NO_MD5) && !defined(OPENSSL_NO_HMAC)
1033 if (doit[D_HMAC]) { 1033 if (doit[D_HMAC]) {
1034 HMAC_CTX hctx; 1034 HMAC_CTX *hctx;
1035 1035
1036 HMAC_CTX_init(&hctx); 1036 if ((hctx = HMAC_CTX_new()) == NULL) {
1037 HMAC_Init_ex(&hctx, (unsigned char *) "This is a key...", 1037 BIO_printf(bio_err, "Failed to allocate HMAC context.\n");
1038 return 0;
1039 }
1040
1041 HMAC_Init_ex(hctx, (unsigned char *) "This is a key...",
1038 16, EVP_md5(), NULL); 1042 16, EVP_md5(), NULL);
1039 1043
1040 for (j = 0; j < SIZE_NUM; j++) { 1044 for (j = 0; j < SIZE_NUM; j++) {
1041 print_message(names[D_HMAC], c[D_HMAC][j], lengths[j]); 1045 print_message(names[D_HMAC], c[D_HMAC][j], lengths[j]);
1042 Time_F(START); 1046 Time_F(START);
1043 for (count = 0, run = 1; COND(c[D_HMAC][j]); count++) { 1047 for (count = 0, run = 1; COND(c[D_HMAC][j]); count++) {
1044 HMAC_Init_ex(&hctx, NULL, 0, NULL, NULL); 1048 HMAC_Init_ex(hctx, NULL, 0, NULL, NULL);
1045 HMAC_Update(&hctx, buf, lengths[j]); 1049 HMAC_Update(hctx, buf, lengths[j]);
1046 HMAC_Final(&hctx, &(hmac[0]), NULL); 1050 HMAC_Final(hctx, &(hmac[0]), NULL);
1047 } 1051 }
1048 d = Time_F(STOP); 1052 d = Time_F(STOP);
1049 print_result(D_HMAC, j, count, d); 1053 print_result(D_HMAC, j, count, d);
1050 } 1054 }
1051 HMAC_CTX_cleanup(&hctx); 1055 HMAC_CTX_free(hctx);
1052 } 1056 }
1053#endif 1057#endif
1054#ifndef OPENSSL_NO_SHA 1058#ifndef OPENSSL_NO_SHA
@@ -1405,10 +1409,11 @@ speed_main(int argc, char **argv)
1405 if (doit[D_EVP]) { 1409 if (doit[D_EVP]) {
1406 for (j = 0; j < SIZE_NUM; j++) { 1410 for (j = 0; j < SIZE_NUM; j++) {
1407 if (evp_cipher) { 1411 if (evp_cipher) {
1408 EVP_CIPHER_CTX ctx; 1412 EVP_CIPHER_CTX *ctx;
1409 int outl; 1413 int outl;
1410 1414
1411 names[D_EVP] = OBJ_nid2ln(evp_cipher->nid); 1415 names[D_EVP] =
1416 OBJ_nid2ln(EVP_CIPHER_nid(evp_cipher));
1412 /* 1417 /*
1413 * -O3 -fschedule-insns messes up an 1418 * -O3 -fschedule-insns messes up an
1414 * optimization here! names[D_EVP] somehow 1419 * optimization here! names[D_EVP] somehow
@@ -1417,29 +1422,33 @@ speed_main(int argc, char **argv)
1417 print_message(names[D_EVP], save_count, 1422 print_message(names[D_EVP], save_count,
1418 lengths[j]); 1423 lengths[j]);
1419 1424
1420 EVP_CIPHER_CTX_init(&ctx); 1425 if ((ctx = EVP_CIPHER_CTX_new()) == NULL) {
1426 BIO_printf(bio_err, "Failed to "
1427 "allocate cipher context.\n");
1428 return 0;
1429 }
1421 if (decrypt) 1430 if (decrypt)
1422 EVP_DecryptInit_ex(&ctx, evp_cipher, NULL, key16, iv); 1431 EVP_DecryptInit_ex(ctx, evp_cipher, NULL, key16, iv);
1423 else 1432 else
1424 EVP_EncryptInit_ex(&ctx, evp_cipher, NULL, key16, iv); 1433 EVP_EncryptInit_ex(ctx, evp_cipher, NULL, key16, iv);
1425 EVP_CIPHER_CTX_set_padding(&ctx, 0); 1434 EVP_CIPHER_CTX_set_padding(ctx, 0);
1426 1435
1427 Time_F(START); 1436 Time_F(START);
1428 if (decrypt) 1437 if (decrypt)
1429 for (count = 0, run = 1; COND(save_count * 4 * lengths[0] / lengths[j]); count++) 1438 for (count = 0, run = 1; COND(save_count * 4 * lengths[0] / lengths[j]); count++)
1430 EVP_DecryptUpdate(&ctx, buf, &outl, buf, lengths[j]); 1439 EVP_DecryptUpdate(ctx, buf, &outl, buf, lengths[j]);
1431 else 1440 else
1432 for (count = 0, run = 1; COND(save_count * 4 * lengths[0] / lengths[j]); count++) 1441 for (count = 0, run = 1; COND(save_count * 4 * lengths[0] / lengths[j]); count++)
1433 EVP_EncryptUpdate(&ctx, buf, &outl, buf, lengths[j]); 1442 EVP_EncryptUpdate(ctx, buf, &outl, buf, lengths[j]);
1434 if (decrypt) 1443 if (decrypt)
1435 EVP_DecryptFinal_ex(&ctx, buf, &outl); 1444 EVP_DecryptFinal_ex(ctx, buf, &outl);
1436 else 1445 else
1437 EVP_EncryptFinal_ex(&ctx, buf, &outl); 1446 EVP_EncryptFinal_ex(ctx, buf, &outl);
1438 d = Time_F(STOP); 1447 d = Time_F(STOP);
1439 EVP_CIPHER_CTX_cleanup(&ctx); 1448 EVP_CIPHER_CTX_free(ctx);
1440 } 1449 }
1441 if (evp_md) { 1450 if (evp_md) {
1442 names[D_EVP] = OBJ_nid2ln(evp_md->type); 1451 names[D_EVP] = OBJ_nid2ln(EVP_MD_type(evp_md));
1443 print_message(names[D_EVP], save_count, 1452 print_message(names[D_EVP], save_count,
1444 lengths[j]); 1453 lengths[j]);
1445 1454