xref: /netbsd-src/crypto/external/bsd/openssl.old/dist/test/pbelutest.c (revision 4724848cf0da353df257f730694b7882798e5daf)
1*4724848cSchristos /*
2*4724848cSchristos  * Copyright 2015-2017 The OpenSSL Project Authors. All Rights Reserved.
3*4724848cSchristos  *
4*4724848cSchristos  * Licensed under the OpenSSL license (the "License").  You may not use
5*4724848cSchristos  * this file except in compliance with the License.  You can obtain a copy
6*4724848cSchristos  * in the file LICENSE in the source distribution or at
7*4724848cSchristos  * https://www.openssl.org/source/license.html
8*4724848cSchristos  */
9*4724848cSchristos 
10*4724848cSchristos #include <openssl/evp.h>
11*4724848cSchristos #include "testutil.h"
12*4724848cSchristos 
13*4724848cSchristos /*
14*4724848cSchristos  * Password based encryption (PBE) table ordering test.
15*4724848cSchristos  * Attempt to look up all supported algorithms.
16*4724848cSchristos  */
17*4724848cSchristos 
test_pbelu(void)18*4724848cSchristos static int test_pbelu(void)
19*4724848cSchristos {
20*4724848cSchristos     int i, failed = 0;
21*4724848cSchristos     int pbe_type, pbe_nid, last_type = -1, last_nid = -1;
22*4724848cSchristos 
23*4724848cSchristos     for (i = 0; EVP_PBE_get(&pbe_type, &pbe_nid, i) != 0; i++) {
24*4724848cSchristos         if (!TEST_true(EVP_PBE_find(pbe_type, pbe_nid, NULL, NULL, 0))) {
25*4724848cSchristos             TEST_note("i=%d, pbe_type=%d, pbe_nid=%d", i, pbe_type, pbe_nid);
26*4724848cSchristos             failed = 1;
27*4724848cSchristos             break;
28*4724848cSchristos         }
29*4724848cSchristos     }
30*4724848cSchristos 
31*4724848cSchristos     if (!failed)
32*4724848cSchristos         return 1;
33*4724848cSchristos 
34*4724848cSchristos     /* Error: print out whole table */
35*4724848cSchristos     for (i = 0; EVP_PBE_get(&pbe_type, &pbe_nid, i) != 0; i++) {
36*4724848cSchristos         failed = pbe_type < last_type
37*4724848cSchristos                  || (pbe_type == last_type && pbe_nid < last_nid);
38*4724848cSchristos         TEST_note("PBE type=%d %d (%s): %s\n", pbe_type, pbe_nid,
39*4724848cSchristos                   OBJ_nid2sn(pbe_nid), failed ? "ERROR" : "OK");
40*4724848cSchristos         last_type = pbe_type;
41*4724848cSchristos         last_nid = pbe_nid;
42*4724848cSchristos     }
43*4724848cSchristos     return 0;
44*4724848cSchristos }
45*4724848cSchristos 
setup_tests(void)46*4724848cSchristos int setup_tests(void)
47*4724848cSchristos {
48*4724848cSchristos     ADD_TEST(test_pbelu);
49*4724848cSchristos     return 1;
50*4724848cSchristos }
51