1c7da899bSchristos /*
213d40330Schristos * Copyright 2015-2017 The OpenSSL Project Authors. All Rights Reserved.
3c7da899bSchristos *
4*b0d17251Schristos * Licensed under the Apache License 2.0 (the "License"). You may not use
5c7da899bSchristos * this file except in compliance with the License. You can obtain a copy
6c7da899bSchristos * in the file LICENSE in the source distribution or at
7c7da899bSchristos * https://www.openssl.org/source/license.html
8c7da899bSchristos */
9c7da899bSchristos
10c7da899bSchristos #include <openssl/evp.h>
1113d40330Schristos #include "testutil.h"
12c7da899bSchristos
13c7da899bSchristos /*
14c7da899bSchristos * Password based encryption (PBE) table ordering test.
15c7da899bSchristos * Attempt to look up all supported algorithms.
16c7da899bSchristos */
17c7da899bSchristos
test_pbelu(void)1813d40330Schristos static int test_pbelu(void)
19c7da899bSchristos {
2013d40330Schristos int i, failed = 0;
2113d40330Schristos int pbe_type, pbe_nid, last_type = -1, last_nid = -1;
2213d40330Schristos
23c7da899bSchristos for (i = 0; EVP_PBE_get(&pbe_type, &pbe_nid, i) != 0; i++) {
2413d40330Schristos if (!TEST_true(EVP_PBE_find(pbe_type, pbe_nid, NULL, NULL, 0))) {
2513d40330Schristos TEST_note("i=%d, pbe_type=%d, pbe_nid=%d", i, pbe_type, pbe_nid);
2613d40330Schristos failed = 1;
27c7da899bSchristos break;
28c7da899bSchristos }
29c7da899bSchristos }
3013d40330Schristos
3113d40330Schristos if (!failed)
3213d40330Schristos return 1;
3313d40330Schristos
34c7da899bSchristos /* Error: print out whole table */
35c7da899bSchristos for (i = 0; EVP_PBE_get(&pbe_type, &pbe_nid, i) != 0; i++) {
3613d40330Schristos failed = pbe_type < last_type
3713d40330Schristos || (pbe_type == last_type && pbe_nid < last_nid);
3813d40330Schristos TEST_note("PBE type=%d %d (%s): %s\n", pbe_type, pbe_nid,
3913d40330Schristos OBJ_nid2sn(pbe_nid), failed ? "ERROR" : "OK");
40c7da899bSchristos last_type = pbe_type;
41c7da899bSchristos last_nid = pbe_nid;
42c7da899bSchristos }
4313d40330Schristos return 0;
4413d40330Schristos }
4513d40330Schristos
setup_tests(void)4613d40330Schristos int setup_tests(void)
4713d40330Schristos {
4813d40330Schristos ADD_TEST(test_pbelu);
49c7da899bSchristos return 1;
50c7da899bSchristos }
51