cipher_overhead_test.c 1.7 KB

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