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