xref: /netbsd-src/crypto/external/bsd/openssl/dist/test/cipher_overhead_test.c (revision b0d1725196a7921d003d2c66a14f186abda4176b)
113d40330Schristos /*
2*b0d17251Schristos  * Copyright 2016-2021 The OpenSSL Project Authors. All Rights Reserved.
313d40330Schristos  *
4*b0d17251Schristos  * Licensed under the Apache License 2.0 (the "License").  You may not use
513d40330Schristos  * this file except in compliance with the License.  You can obtain a copy
613d40330Schristos  * in the file LICENSE in the source distribution or at
713d40330Schristos  * https://www.openssl.org/source/license.html
813d40330Schristos  */
913d40330Schristos 
1013d40330Schristos #include "internal/nelem.h"
1113d40330Schristos #include "testutil.h"
127d004720Schristos #include "../ssl/ssl_local.h"
1313d40330Schristos 
cipher_enabled(const SSL_CIPHER * ciph)14*b0d17251Schristos static int cipher_enabled(const SSL_CIPHER *ciph)
15*b0d17251Schristos {
16*b0d17251Schristos     /*
17*b0d17251Schristos      * ssl_cipher_get_overhead() actually works with AEAD ciphers even if the
18*b0d17251Schristos      * underlying implementation is not present.
19*b0d17251Schristos      */
20*b0d17251Schristos     if ((ciph->algorithm_mac & SSL_AEAD) != 0)
21*b0d17251Schristos         return 1;
22*b0d17251Schristos 
23*b0d17251Schristos     if (ciph->algorithm_enc != SSL_eNULL
24*b0d17251Schristos             && EVP_get_cipherbynid(SSL_CIPHER_get_cipher_nid(ciph)) == NULL)
25*b0d17251Schristos         return 0;
26*b0d17251Schristos 
27*b0d17251Schristos     if (EVP_get_digestbynid(SSL_CIPHER_get_digest_nid(ciph)) == NULL)
28*b0d17251Schristos         return 0;
29*b0d17251Schristos 
30*b0d17251Schristos     return 1;
31*b0d17251Schristos }
3213d40330Schristos 
cipher_overhead(void)3313d40330Schristos static int cipher_overhead(void)
3413d40330Schristos {
3513d40330Schristos     int ret = 1, i, n = ssl3_num_ciphers();
3613d40330Schristos     const SSL_CIPHER *ciph;
3713d40330Schristos     size_t mac, in, blk, ex;
3813d40330Schristos 
3913d40330Schristos     for (i = 0; i < n; i++) {
4013d40330Schristos         ciph = ssl3_get_cipher(i);
4113d40330Schristos         if (!ciph->min_dtls)
4213d40330Schristos             continue;
43*b0d17251Schristos         if (!cipher_enabled(ciph)) {
44*b0d17251Schristos             TEST_skip("Skipping disabled cipher %s", ciph->name);
45*b0d17251Schristos             continue;
46*b0d17251Schristos         }
4713d40330Schristos         if (!TEST_true(ssl_cipher_get_overhead(ciph, &mac, &in, &blk, &ex))) {
4813d40330Schristos             TEST_info("Failed getting %s", ciph->name);
4913d40330Schristos             ret = 0;
5013d40330Schristos         } else {
5113d40330Schristos             TEST_info("Cipher %s: %zu %zu %zu %zu",
5213d40330Schristos                       ciph->name, mac, in, blk, ex);
5313d40330Schristos         }
5413d40330Schristos     }
5513d40330Schristos     return ret;
5613d40330Schristos }
5713d40330Schristos 
setup_tests(void)5813d40330Schristos int setup_tests(void)
5913d40330Schristos {
6013d40330Schristos     ADD_TEST(cipher_overhead);
6113d40330Schristos     return 1;
6213d40330Schristos }
63