David Woodhouse | 542dd9c | 2016-10-06 11:44:29 +0100 | [diff] [blame] | 1 | /* |
Matt Caswell | a28d06f | 2021-02-18 14:57:13 +0000 | [diff] [blame] | 2 | * Copyright 2016-2021 The OpenSSL Project Authors. All Rights Reserved. |
David Woodhouse | 542dd9c | 2016-10-06 11:44:29 +0100 | [diff] [blame] | 3 | * |
Richard Levitte | 909f1a2 | 2018-12-06 13:05:25 +0100 | [diff] [blame] | 4 | * Licensed under the Apache License 2.0 (the "License"). You may not use |
David Woodhouse | 542dd9c | 2016-10-06 11:44:29 +0100 | [diff] [blame] | 5 | * this file except in compliance with the License. You can obtain a copy |
| 6 | * in the file LICENSE in the source distribution or at |
| 7 | * https://www.openssl.org/source/license.html |
| 8 | */ |
| 9 | |
Rich Salz | 176db6d | 2017-08-22 08:35:43 -0400 | [diff] [blame] | 10 | #include "internal/nelem.h" |
Rich Salz | 3304d57 | 2017-04-18 14:50:00 -0400 | [diff] [blame] | 11 | #include "testutil.h" |
Dr. Matthias St. Pierre | 706457b | 2019-09-28 00:45:40 +0200 | [diff] [blame] | 12 | #include "../ssl/ssl_local.h" |
David Woodhouse | 542dd9c | 2016-10-06 11:44:29 +0100 | [diff] [blame] | 13 | |
Matt Caswell | 5682e77 | 2021-02-01 15:15:10 +0000 | [diff] [blame] | 14 | static int cipher_enabled(const SSL_CIPHER *ciph) |
| 15 | { |
| 16 | /* |
| 17 | * ssl_cipher_get_overhead() actually works with AEAD ciphers even if the |
| 18 | * underlying implementation is not present. |
| 19 | */ |
| 20 | if ((ciph->algorithm_mac & SSL_AEAD) != 0) |
| 21 | return 1; |
| 22 | |
| 23 | if (ciph->algorithm_enc != SSL_eNULL |
| 24 | && EVP_get_cipherbynid(SSL_CIPHER_get_cipher_nid(ciph)) == NULL) |
| 25 | return 0; |
| 26 | |
| 27 | if (EVP_get_digestbynid(SSL_CIPHER_get_digest_nid(ciph)) == NULL) |
| 28 | return 0; |
| 29 | |
| 30 | return 1; |
| 31 | } |
| 32 | |
Rich Salz | 3304d57 | 2017-04-18 14:50:00 -0400 | [diff] [blame] | 33 | static int cipher_overhead(void) |
David Woodhouse | 542dd9c | 2016-10-06 11:44:29 +0100 | [diff] [blame] | 34 | { |
Rich Salz | 3304d57 | 2017-04-18 14:50:00 -0400 | [diff] [blame] | 35 | int ret = 1, i, n = ssl3_num_ciphers(); |
David Woodhouse | 542dd9c | 2016-10-06 11:44:29 +0100 | [diff] [blame] | 36 | const SSL_CIPHER *ciph; |
| 37 | size_t mac, in, blk, ex; |
| 38 | |
| 39 | for (i = 0; i < n; i++) { |
| 40 | ciph = ssl3_get_cipher(i); |
| 41 | if (!ciph->min_dtls) |
| 42 | continue; |
Matt Caswell | 5682e77 | 2021-02-01 15:15:10 +0000 | [diff] [blame] | 43 | if (!cipher_enabled(ciph)) { |
| 44 | TEST_skip("Skipping disabled cipher %s", ciph->name); |
| 45 | continue; |
| 46 | } |
Rich Salz | 3304d57 | 2017-04-18 14:50:00 -0400 | [diff] [blame] | 47 | if (!TEST_true(ssl_cipher_get_overhead(ciph, &mac, &in, &blk, &ex))) { |
| 48 | TEST_info("Failed getting %s", ciph->name); |
| 49 | ret = 0; |
David Woodhouse | 542dd9c | 2016-10-06 11:44:29 +0100 | [diff] [blame] | 50 | } else { |
Richard Levitte | a9c6d22 | 2017-04-18 16:47:11 +0200 | [diff] [blame] | 51 | TEST_info("Cipher %s: %zu %zu %zu %zu", |
Rich Salz | 3304d57 | 2017-04-18 14:50:00 -0400 | [diff] [blame] | 52 | ciph->name, mac, in, blk, ex); |
David Woodhouse | 542dd9c | 2016-10-06 11:44:29 +0100 | [diff] [blame] | 53 | } |
| 54 | } |
Rich Salz | 3304d57 | 2017-04-18 14:50:00 -0400 | [diff] [blame] | 55 | return ret; |
| 56 | } |
| 57 | |
Pauli | ad88741 | 2017-07-18 11:48:27 +1000 | [diff] [blame] | 58 | int setup_tests(void) |
Rich Salz | 3304d57 | 2017-04-18 14:50:00 -0400 | [diff] [blame] | 59 | { |
| 60 | ADD_TEST(cipher_overhead); |
Pauli | ad88741 | 2017-07-18 11:48:27 +1000 | [diff] [blame] | 61 | return 1; |
David Woodhouse | 542dd9c | 2016-10-06 11:44:29 +0100 | [diff] [blame] | 62 | } |