X-Git-Url: https://git.openssl.org/gitweb/?p=openssl.git;a=blobdiff_plain;f=test%2Fcipher_overhead_test.c;h=0492e67ec5418330f1c1a50b13268a75b3d5f943;hp=8c262b3b9a7a31e9875614e84a74c5e4abb04308;hb=HEAD;hpb=542dd9c58712201a46a5519ee02e878792bbcb72 diff --git a/test/cipher_overhead_test.c b/test/cipher_overhead_test.c index 8c262b3b9a..2001b33295 100644 --- a/test/cipher_overhead_test.c +++ b/test/cipher_overhead_test.c @@ -1,19 +1,38 @@ /* - * Copyright 2016 The OpenSSL Project Authors. All Rights Reserved. + * Copyright 2016-2021 The OpenSSL Project Authors. All Rights Reserved. * - * Licensed under the OpenSSL license (the "License"). You may not use + * Licensed under the Apache License 2.0 (the "License"). You may not use * this file except in compliance with the License. You can obtain a copy * in the file LICENSE in the source distribution or at * https://www.openssl.org/source/license.html */ -#include +#include "internal/nelem.h" +#include "testutil.h" +#include "../ssl/ssl_local.h" -#include "../ssl/ssl_locl.h" +static int cipher_enabled(const SSL_CIPHER *ciph) +{ + /* + * ssl_cipher_get_overhead() actually works with AEAD ciphers even if the + * underlying implementation is not present. + */ + if ((ciph->algorithm_mac & SSL_AEAD) != 0) + return 1; + + if (ciph->algorithm_enc != SSL_eNULL + && EVP_get_cipherbynid(SSL_CIPHER_get_cipher_nid(ciph)) == NULL) + return 0; + + if (EVP_get_digestbynid(SSL_CIPHER_get_digest_nid(ciph)) == NULL) + return 0; + + return 1; +} -int main(void) +static int cipher_overhead(void) { - int i, n = ssl3_num_ciphers(); + int ret = 1, i, n = ssl3_num_ciphers(); const SSL_CIPHER *ciph; size_t mac, in, blk, ex; @@ -21,13 +40,23 @@ int main(void) ciph = ssl3_get_cipher(i); if (!ciph->min_dtls) continue; - if (!ssl_cipher_get_overhead(ciph, &mac, &in, &blk, &ex)) { - printf("Error getting overhead for %s\n", ciph->name); - exit(1); + if (!cipher_enabled(ciph)) { + TEST_skip("Skipping disabled cipher %s", ciph->name); + continue; + } + if (!TEST_true(ssl_cipher_get_overhead(ciph, &mac, &in, &blk, &ex))) { + TEST_info("Failed getting %s", ciph->name); + ret = 0; } else { - printf("Cipher %s: %"OSSLzu" %"OSSLzu" %"OSSLzu" %"OSSLzu"\n", - ciph->name, mac, in, blk, ex); + TEST_info("Cipher %s: %zu %zu %zu %zu", + ciph->name, mac, in, blk, ex); } } - exit(0); + return ret; +} + +int setup_tests(void) +{ + ADD_TEST(cipher_overhead); + return 1; }