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