1*e0c4386eSCy Schubert /*
2*e0c4386eSCy Schubert * Copyright 2016-2021 The OpenSSL Project Authors. All Rights Reserved.
3*e0c4386eSCy Schubert *
4*e0c4386eSCy Schubert * Licensed under the Apache License 2.0 (the "License"). You may not use
5*e0c4386eSCy Schubert * this file except in compliance with the License. You can obtain a copy
6*e0c4386eSCy Schubert * in the file LICENSE in the source distribution or at
7*e0c4386eSCy Schubert * https://www.openssl.org/source/license.html
8*e0c4386eSCy Schubert */
9*e0c4386eSCy Schubert
10*e0c4386eSCy Schubert #include "internal/nelem.h"
11*e0c4386eSCy Schubert #include "testutil.h"
12*e0c4386eSCy Schubert #include "../ssl/ssl_local.h"
13*e0c4386eSCy Schubert
cipher_enabled(const SSL_CIPHER * ciph)14*e0c4386eSCy Schubert static int cipher_enabled(const SSL_CIPHER *ciph)
15*e0c4386eSCy Schubert {
16*e0c4386eSCy Schubert /*
17*e0c4386eSCy Schubert * ssl_cipher_get_overhead() actually works with AEAD ciphers even if the
18*e0c4386eSCy Schubert * underlying implementation is not present.
19*e0c4386eSCy Schubert */
20*e0c4386eSCy Schubert if ((ciph->algorithm_mac & SSL_AEAD) != 0)
21*e0c4386eSCy Schubert return 1;
22*e0c4386eSCy Schubert
23*e0c4386eSCy Schubert if (ciph->algorithm_enc != SSL_eNULL
24*e0c4386eSCy Schubert && EVP_get_cipherbynid(SSL_CIPHER_get_cipher_nid(ciph)) == NULL)
25*e0c4386eSCy Schubert return 0;
26*e0c4386eSCy Schubert
27*e0c4386eSCy Schubert if (EVP_get_digestbynid(SSL_CIPHER_get_digest_nid(ciph)) == NULL)
28*e0c4386eSCy Schubert return 0;
29*e0c4386eSCy Schubert
30*e0c4386eSCy Schubert return 1;
31*e0c4386eSCy Schubert }
32*e0c4386eSCy Schubert
cipher_overhead(void)33*e0c4386eSCy Schubert static int cipher_overhead(void)
34*e0c4386eSCy Schubert {
35*e0c4386eSCy Schubert int ret = 1, i, n = ssl3_num_ciphers();
36*e0c4386eSCy Schubert const SSL_CIPHER *ciph;
37*e0c4386eSCy Schubert size_t mac, in, blk, ex;
38*e0c4386eSCy Schubert
39*e0c4386eSCy Schubert for (i = 0; i < n; i++) {
40*e0c4386eSCy Schubert ciph = ssl3_get_cipher(i);
41*e0c4386eSCy Schubert if (!ciph->min_dtls)
42*e0c4386eSCy Schubert continue;
43*e0c4386eSCy Schubert if (!cipher_enabled(ciph)) {
44*e0c4386eSCy Schubert TEST_skip("Skipping disabled cipher %s", ciph->name);
45*e0c4386eSCy Schubert continue;
46*e0c4386eSCy Schubert }
47*e0c4386eSCy Schubert if (!TEST_true(ssl_cipher_get_overhead(ciph, &mac, &in, &blk, &ex))) {
48*e0c4386eSCy Schubert TEST_info("Failed getting %s", ciph->name);
49*e0c4386eSCy Schubert ret = 0;
50*e0c4386eSCy Schubert } else {
51*e0c4386eSCy Schubert TEST_info("Cipher %s: %zu %zu %zu %zu",
52*e0c4386eSCy Schubert ciph->name, mac, in, blk, ex);
53*e0c4386eSCy Schubert }
54*e0c4386eSCy Schubert }
55*e0c4386eSCy Schubert return ret;
56*e0c4386eSCy Schubert }
57*e0c4386eSCy Schubert
setup_tests(void)58*e0c4386eSCy Schubert int setup_tests(void)
59*e0c4386eSCy Schubert {
60*e0c4386eSCy Schubert ADD_TEST(cipher_overhead);
61*e0c4386eSCy Schubert return 1;
62*e0c4386eSCy Schubert }
63