pbelutest.c 1.5 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455
  1. /*
  2. * Copyright 2015-2016 The OpenSSL Project Authors. All Rights Reserved.
  3. *
  4. * Licensed under the OpenSSL license (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 <openssl/evp.h>
  10. #include "testutil.h"
  11. /*
  12. * Password based encryption (PBE) table ordering test.
  13. * Attempt to look up all supported algorithms.
  14. */
  15. static int test_pbelu(void)
  16. {
  17. int i, failed = 0, ok;
  18. int pbe_type, pbe_nid, last_type = -1, last_nid = -1;
  19. for (i = 0; EVP_PBE_get(&pbe_type, &pbe_nid, i) != 0; i++) {
  20. if (!TEST_true(EVP_PBE_find(pbe_type, pbe_nid, NULL, NULL, 0))) {
  21. TEST_info("i=%d, pbe_type=%d, pbe_nid=%d", i, pbe_type, pbe_nid);
  22. failed = 1;
  23. break;
  24. }
  25. }
  26. if (!failed)
  27. return 1;
  28. /* Error: print out whole table */
  29. for (i = 0; EVP_PBE_get(&pbe_type, &pbe_nid, i) != 0; i++) {
  30. if (pbe_type > last_type)
  31. ok = 0;
  32. else if (pbe_type < last_type || pbe_nid < last_nid)
  33. ok = 1;
  34. else
  35. ok = 0;
  36. if (!ok)
  37. failed = 1;
  38. TEST_info("PBE type=%d %d (%s): %s\n", pbe_type, pbe_nid,
  39. OBJ_nid2sn(pbe_nid), ok ? "ERROR" : "OK");
  40. last_type = pbe_type;
  41. last_nid = pbe_nid;
  42. }
  43. return failed ? 0 : 1;
  44. }
  45. void register_tests(void)
  46. {
  47. ADD_TEST(test_pbelu);
  48. }