diff options
author | tb <> | 2022-01-14 09:27:30 +0000 |
---|---|---|
committer | tb <> | 2022-01-14 09:27:30 +0000 |
commit | 72edcec0b5ec6b71ac44983e57ada002a48ac87a (patch) | |
tree | 046e4d55f68464c42d7ff7a0048d9328cd6f3368 | |
parent | ff3c7a014d1a3f328a80f975cccae5a134a02efa (diff) | |
download | openbsd-72edcec0b5ec6b71ac44983e57ada002a48ac87a.tar.gz openbsd-72edcec0b5ec6b71ac44983e57ada002a48ac87a.tar.bz2 openbsd-72edcec0b5ec6b71ac44983e57ada002a48ac87a.zip |
Convert openssl(1) speed for opaque EVP_AEAD_CTX
ok inoguchi jsing
-rw-r--r-- | src/usr.bin/openssl/speed.c | 44 |
1 files changed, 31 insertions, 13 deletions
diff --git a/src/usr.bin/openssl/speed.c b/src/usr.bin/openssl/speed.c index b5c8c742cc..f3e9fdc076 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.27 2021/12/26 15:34:26 tb Exp $ */ | 1 | /* $OpenBSD: speed.c,v 1.28 2022/01/14 09:27:30 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 | * |
@@ -1256,9 +1256,15 @@ speed_main(int argc, char **argv) | |||
1256 | const EVP_AEAD *aead = EVP_aead_aes_128_gcm(); | 1256 | const EVP_AEAD *aead = EVP_aead_aes_128_gcm(); |
1257 | static const unsigned char nonce[32] = {0}; | 1257 | static const unsigned char nonce[32] = {0}; |
1258 | size_t buf_len, nonce_len; | 1258 | size_t buf_len, nonce_len; |
1259 | EVP_AEAD_CTX ctx; | 1259 | EVP_AEAD_CTX *ctx; |
1260 | 1260 | ||
1261 | EVP_AEAD_CTX_init(&ctx, aead, key32, EVP_AEAD_key_length(aead), | 1261 | if ((ctx = EVP_AEAD_CTX_new()) == NULL) { |
1262 | BIO_printf(bio_err, | ||
1263 | "Failed to allocate aead context.\n"); | ||
1264 | goto end; | ||
1265 | } | ||
1266 | |||
1267 | EVP_AEAD_CTX_init(ctx, aead, key32, EVP_AEAD_key_length(aead), | ||
1262 | EVP_AEAD_DEFAULT_TAG_LENGTH, NULL); | 1268 | EVP_AEAD_DEFAULT_TAG_LENGTH, NULL); |
1263 | nonce_len = EVP_AEAD_nonce_length(aead); | 1269 | nonce_len = EVP_AEAD_nonce_length(aead); |
1264 | 1270 | ||
@@ -1266,21 +1272,27 @@ speed_main(int argc, char **argv) | |||
1266 | print_message(names[D_AES_128_GCM],c[D_AES_128_GCM][j],lengths[j]); | 1272 | print_message(names[D_AES_128_GCM],c[D_AES_128_GCM][j],lengths[j]); |
1267 | Time_F(START); | 1273 | Time_F(START); |
1268 | for (count = 0, run = 1; COND(c[D_AES_128_GCM][j]); count++) | 1274 | for (count = 0, run = 1; COND(c[D_AES_128_GCM][j]); count++) |
1269 | EVP_AEAD_CTX_seal(&ctx, buf, &buf_len, BUFSIZE, nonce, | 1275 | EVP_AEAD_CTX_seal(ctx, buf, &buf_len, BUFSIZE, nonce, |
1270 | nonce_len, buf, lengths[j], NULL, 0); | 1276 | nonce_len, buf, lengths[j], NULL, 0); |
1271 | d=Time_F(STOP); | 1277 | d=Time_F(STOP); |
1272 | print_result(D_AES_128_GCM,j,count,d); | 1278 | print_result(D_AES_128_GCM,j,count,d); |
1273 | } | 1279 | } |
1274 | EVP_AEAD_CTX_cleanup(&ctx); | 1280 | EVP_AEAD_CTX_free(ctx); |
1275 | } | 1281 | } |
1276 | 1282 | ||
1277 | if (doit[D_AES_256_GCM]) { | 1283 | if (doit[D_AES_256_GCM]) { |
1278 | const EVP_AEAD *aead = EVP_aead_aes_256_gcm(); | 1284 | const EVP_AEAD *aead = EVP_aead_aes_256_gcm(); |
1279 | static const unsigned char nonce[32] = {0}; | 1285 | static const unsigned char nonce[32] = {0}; |
1280 | size_t buf_len, nonce_len; | 1286 | size_t buf_len, nonce_len; |
1281 | EVP_AEAD_CTX ctx; | 1287 | EVP_AEAD_CTX *ctx; |
1282 | 1288 | ||
1283 | EVP_AEAD_CTX_init(&ctx, aead, key32, EVP_AEAD_key_length(aead), | 1289 | if ((ctx = EVP_AEAD_CTX_new()) == NULL) { |
1290 | BIO_printf(bio_err, | ||
1291 | "Failed to allocate aead context.\n"); | ||
1292 | goto end; | ||
1293 | } | ||
1294 | |||
1295 | EVP_AEAD_CTX_init(ctx, aead, key32, EVP_AEAD_key_length(aead), | ||
1284 | EVP_AEAD_DEFAULT_TAG_LENGTH, NULL); | 1296 | EVP_AEAD_DEFAULT_TAG_LENGTH, NULL); |
1285 | nonce_len = EVP_AEAD_nonce_length(aead); | 1297 | nonce_len = EVP_AEAD_nonce_length(aead); |
1286 | 1298 | ||
@@ -1288,12 +1300,12 @@ speed_main(int argc, char **argv) | |||
1288 | print_message(names[D_AES_256_GCM],c[D_AES_256_GCM][j],lengths[j]); | 1300 | print_message(names[D_AES_256_GCM],c[D_AES_256_GCM][j],lengths[j]); |
1289 | Time_F(START); | 1301 | Time_F(START); |
1290 | for (count = 0, run = 1; COND(c[D_AES_256_GCM][j]); count++) | 1302 | for (count = 0, run = 1; COND(c[D_AES_256_GCM][j]); count++) |
1291 | EVP_AEAD_CTX_seal(&ctx, buf, &buf_len, BUFSIZE, nonce, | 1303 | EVP_AEAD_CTX_seal(ctx, buf, &buf_len, BUFSIZE, nonce, |
1292 | nonce_len, buf, lengths[j], NULL, 0); | 1304 | nonce_len, buf, lengths[j], NULL, 0); |
1293 | d=Time_F(STOP); | 1305 | d=Time_F(STOP); |
1294 | print_result(D_AES_256_GCM, j, count, d); | 1306 | print_result(D_AES_256_GCM, j, count, d); |
1295 | } | 1307 | } |
1296 | EVP_AEAD_CTX_cleanup(&ctx); | 1308 | EVP_AEAD_CTX_free(ctx); |
1297 | } | 1309 | } |
1298 | #endif | 1310 | #endif |
1299 | #if !defined(OPENSSL_NO_CHACHA) && !defined(OPENSSL_NO_POLY1305) | 1311 | #if !defined(OPENSSL_NO_CHACHA) && !defined(OPENSSL_NO_POLY1305) |
@@ -1301,9 +1313,15 @@ speed_main(int argc, char **argv) | |||
1301 | const EVP_AEAD *aead = EVP_aead_chacha20_poly1305(); | 1313 | const EVP_AEAD *aead = EVP_aead_chacha20_poly1305(); |
1302 | static const unsigned char nonce[32] = {0}; | 1314 | static const unsigned char nonce[32] = {0}; |
1303 | size_t buf_len, nonce_len; | 1315 | size_t buf_len, nonce_len; |
1304 | EVP_AEAD_CTX ctx; | 1316 | EVP_AEAD_CTX *ctx; |
1317 | |||
1318 | if ((ctx = EVP_AEAD_CTX_new()) == NULL) { | ||
1319 | BIO_printf(bio_err, | ||
1320 | "Failed to allocate aead context.\n"); | ||
1321 | goto end; | ||
1322 | } | ||
1305 | 1323 | ||
1306 | EVP_AEAD_CTX_init(&ctx, aead, key32, EVP_AEAD_key_length(aead), | 1324 | EVP_AEAD_CTX_init(ctx, aead, key32, EVP_AEAD_key_length(aead), |
1307 | EVP_AEAD_DEFAULT_TAG_LENGTH, NULL); | 1325 | EVP_AEAD_DEFAULT_TAG_LENGTH, NULL); |
1308 | nonce_len = EVP_AEAD_nonce_length(aead); | 1326 | nonce_len = EVP_AEAD_nonce_length(aead); |
1309 | 1327 | ||
@@ -1312,12 +1330,12 @@ speed_main(int argc, char **argv) | |||
1312 | c[D_CHACHA20_POLY1305][j], lengths[j]); | 1330 | c[D_CHACHA20_POLY1305][j], lengths[j]); |
1313 | Time_F(START); | 1331 | Time_F(START); |
1314 | for (count = 0, run = 1; COND(c[D_CHACHA20_POLY1305][j]); count++) | 1332 | for (count = 0, run = 1; COND(c[D_CHACHA20_POLY1305][j]); count++) |
1315 | EVP_AEAD_CTX_seal(&ctx, buf, &buf_len, BUFSIZE, nonce, | 1333 | EVP_AEAD_CTX_seal(ctx, buf, &buf_len, BUFSIZE, nonce, |
1316 | nonce_len, buf, lengths[j], NULL, 0); | 1334 | nonce_len, buf, lengths[j], NULL, 0); |
1317 | d=Time_F(STOP); | 1335 | d=Time_F(STOP); |
1318 | print_result(D_CHACHA20_POLY1305, j, count, d); | 1336 | print_result(D_CHACHA20_POLY1305, j, count, d); |
1319 | } | 1337 | } |
1320 | EVP_AEAD_CTX_cleanup(&ctx); | 1338 | EVP_AEAD_CTX_free(ctx); |
1321 | } | 1339 | } |
1322 | #endif | 1340 | #endif |
1323 | #ifndef OPENSSL_NO_CAMELLIA | 1341 | #ifndef OPENSSL_NO_CAMELLIA |