blob: 2001b332958c4ebaffcfe9d392faaceaa587138f [file] [log] [blame]
David Woodhouse542dd9c2016-10-06 11:44:29 +01001/*
Matt Caswella28d06f2021-02-18 14:57:13 +00002 * Copyright 2016-2021 The OpenSSL Project Authors. All Rights Reserved.
David Woodhouse542dd9c2016-10-06 11:44:29 +01003 *
Richard Levitte909f1a22018-12-06 13:05:25 +01004 * Licensed under the Apache License 2.0 (the "License"). You may not use
David Woodhouse542dd9c2016-10-06 11:44:29 +01005 * 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 Salz176db6d2017-08-22 08:35:43 -040010#include "internal/nelem.h"
Rich Salz3304d572017-04-18 14:50:00 -040011#include "testutil.h"
Dr. Matthias St. Pierre706457b2019-09-28 00:45:40 +020012#include "../ssl/ssl_local.h"
David Woodhouse542dd9c2016-10-06 11:44:29 +010013
Matt Caswell5682e772021-02-01 15:15:10 +000014static 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 Salz3304d572017-04-18 14:50:00 -040033static int cipher_overhead(void)
David Woodhouse542dd9c2016-10-06 11:44:29 +010034{
Rich Salz3304d572017-04-18 14:50:00 -040035 int ret = 1, i, n = ssl3_num_ciphers();
David Woodhouse542dd9c2016-10-06 11:44:29 +010036 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 Caswell5682e772021-02-01 15:15:10 +000043 if (!cipher_enabled(ciph)) {
44 TEST_skip("Skipping disabled cipher %s", ciph->name);
45 continue;
46 }
Rich Salz3304d572017-04-18 14:50:00 -040047 if (!TEST_true(ssl_cipher_get_overhead(ciph, &mac, &in, &blk, &ex))) {
48 TEST_info("Failed getting %s", ciph->name);
49 ret = 0;
David Woodhouse542dd9c2016-10-06 11:44:29 +010050 } else {
Richard Levittea9c6d222017-04-18 16:47:11 +020051 TEST_info("Cipher %s: %zu %zu %zu %zu",
Rich Salz3304d572017-04-18 14:50:00 -040052 ciph->name, mac, in, blk, ex);
David Woodhouse542dd9c2016-10-06 11:44:29 +010053 }
54 }
Rich Salz3304d572017-04-18 14:50:00 -040055 return ret;
56}
57
Pauliad887412017-07-18 11:48:27 +100058int setup_tests(void)
Rich Salz3304d572017-04-18 14:50:00 -040059{
60 ADD_TEST(cipher_overhead);
Pauliad887412017-07-18 11:48:27 +100061 return 1;
David Woodhouse542dd9c2016-10-06 11:44:29 +010062}