1e1051a39Sopenharmony_ci/* 2e1051a39Sopenharmony_ci * Copyright 1999-2023 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 <stdio.h> 11e1051a39Sopenharmony_ci#include "internal/cryptlib.h" 12e1051a39Sopenharmony_ci#include <openssl/evp.h> 13e1051a39Sopenharmony_ci#include <openssl/core.h> 14e1051a39Sopenharmony_ci#include <openssl/core_names.h> 15e1051a39Sopenharmony_ci#include <openssl/pkcs12.h> 16e1051a39Sopenharmony_ci#include <openssl/x509.h> 17e1051a39Sopenharmony_ci#include "crypto/evp.h" 18e1051a39Sopenharmony_ci#include "evp_local.h" 19e1051a39Sopenharmony_ci 20e1051a39Sopenharmony_ci/* Password based encryption (PBE) functions */ 21e1051a39Sopenharmony_ci 22e1051a39Sopenharmony_ci/* Setup a cipher context from a PBE algorithm */ 23e1051a39Sopenharmony_ci 24e1051a39Sopenharmony_cistruct evp_pbe_st { 25e1051a39Sopenharmony_ci int pbe_type; 26e1051a39Sopenharmony_ci int pbe_nid; 27e1051a39Sopenharmony_ci int cipher_nid; 28e1051a39Sopenharmony_ci int md_nid; 29e1051a39Sopenharmony_ci EVP_PBE_KEYGEN *keygen; 30e1051a39Sopenharmony_ci EVP_PBE_KEYGEN_EX *keygen_ex; 31e1051a39Sopenharmony_ci}; 32e1051a39Sopenharmony_ci 33e1051a39Sopenharmony_cistatic STACK_OF(EVP_PBE_CTL) *pbe_algs; 34e1051a39Sopenharmony_ci 35e1051a39Sopenharmony_cistatic const EVP_PBE_CTL builtin_pbe[] = { 36e1051a39Sopenharmony_ci {EVP_PBE_TYPE_OUTER, NID_pbeWithMD2AndDES_CBC, 37e1051a39Sopenharmony_ci NID_des_cbc, NID_md2, PKCS5_PBE_keyivgen, PKCS5_PBE_keyivgen_ex}, 38e1051a39Sopenharmony_ci {EVP_PBE_TYPE_OUTER, NID_pbeWithMD5AndDES_CBC, 39e1051a39Sopenharmony_ci NID_des_cbc, NID_md5, PKCS5_PBE_keyivgen, PKCS5_PBE_keyivgen_ex}, 40e1051a39Sopenharmony_ci {EVP_PBE_TYPE_OUTER, NID_pbeWithSHA1AndRC2_CBC, 41e1051a39Sopenharmony_ci NID_rc2_64_cbc, NID_sha1, PKCS5_PBE_keyivgen, PKCS5_PBE_keyivgen_ex}, 42e1051a39Sopenharmony_ci 43e1051a39Sopenharmony_ci {EVP_PBE_TYPE_OUTER, NID_id_pbkdf2, -1, -1, PKCS5_v2_PBKDF2_keyivgen}, 44e1051a39Sopenharmony_ci 45e1051a39Sopenharmony_ci {EVP_PBE_TYPE_OUTER, NID_pbe_WithSHA1And128BitRC4, 46e1051a39Sopenharmony_ci NID_rc4, NID_sha1, PKCS12_PBE_keyivgen, &PKCS12_PBE_keyivgen_ex}, 47e1051a39Sopenharmony_ci {EVP_PBE_TYPE_OUTER, NID_pbe_WithSHA1And40BitRC4, 48e1051a39Sopenharmony_ci NID_rc4_40, NID_sha1, PKCS12_PBE_keyivgen, &PKCS12_PBE_keyivgen_ex}, 49e1051a39Sopenharmony_ci {EVP_PBE_TYPE_OUTER, NID_pbe_WithSHA1And3_Key_TripleDES_CBC, 50e1051a39Sopenharmony_ci NID_des_ede3_cbc, NID_sha1, PKCS12_PBE_keyivgen, &PKCS12_PBE_keyivgen_ex}, 51e1051a39Sopenharmony_ci {EVP_PBE_TYPE_OUTER, NID_pbe_WithSHA1And2_Key_TripleDES_CBC, 52e1051a39Sopenharmony_ci NID_des_ede_cbc, NID_sha1, PKCS12_PBE_keyivgen, &PKCS12_PBE_keyivgen_ex}, 53e1051a39Sopenharmony_ci {EVP_PBE_TYPE_OUTER, NID_pbe_WithSHA1And128BitRC2_CBC, 54e1051a39Sopenharmony_ci NID_rc2_cbc, NID_sha1, PKCS12_PBE_keyivgen, &PKCS12_PBE_keyivgen_ex}, 55e1051a39Sopenharmony_ci {EVP_PBE_TYPE_OUTER, NID_pbe_WithSHA1And40BitRC2_CBC, 56e1051a39Sopenharmony_ci NID_rc2_40_cbc, NID_sha1, PKCS12_PBE_keyivgen, &PKCS12_PBE_keyivgen_ex}, 57e1051a39Sopenharmony_ci 58e1051a39Sopenharmony_ci {EVP_PBE_TYPE_OUTER, NID_pbes2, -1, -1, PKCS5_v2_PBE_keyivgen, &PKCS5_v2_PBE_keyivgen_ex}, 59e1051a39Sopenharmony_ci 60e1051a39Sopenharmony_ci {EVP_PBE_TYPE_OUTER, NID_pbeWithMD2AndRC2_CBC, 61e1051a39Sopenharmony_ci NID_rc2_64_cbc, NID_md2, PKCS5_PBE_keyivgen, PKCS5_PBE_keyivgen_ex}, 62e1051a39Sopenharmony_ci {EVP_PBE_TYPE_OUTER, NID_pbeWithMD5AndRC2_CBC, 63e1051a39Sopenharmony_ci NID_rc2_64_cbc, NID_md5, PKCS5_PBE_keyivgen, PKCS5_PBE_keyivgen_ex}, 64e1051a39Sopenharmony_ci {EVP_PBE_TYPE_OUTER, NID_pbeWithSHA1AndDES_CBC, 65e1051a39Sopenharmony_ci NID_des_cbc, NID_sha1, PKCS5_PBE_keyivgen, PKCS5_PBE_keyivgen_ex}, 66e1051a39Sopenharmony_ci 67e1051a39Sopenharmony_ci {EVP_PBE_TYPE_PRF, NID_hmacWithSHA1, -1, NID_sha1, 0}, 68e1051a39Sopenharmony_ci {EVP_PBE_TYPE_PRF, NID_hmac_md5, -1, NID_md5, 0}, 69e1051a39Sopenharmony_ci {EVP_PBE_TYPE_PRF, NID_hmac_sha1, -1, NID_sha1, 0}, 70e1051a39Sopenharmony_ci {EVP_PBE_TYPE_PRF, NID_hmacWithMD5, -1, NID_md5, 0}, 71e1051a39Sopenharmony_ci {EVP_PBE_TYPE_PRF, NID_hmacWithSHA224, -1, NID_sha224, 0}, 72e1051a39Sopenharmony_ci {EVP_PBE_TYPE_PRF, NID_hmacWithSHA256, -1, NID_sha256, 0}, 73e1051a39Sopenharmony_ci {EVP_PBE_TYPE_PRF, NID_hmacWithSHA384, -1, NID_sha384, 0}, 74e1051a39Sopenharmony_ci {EVP_PBE_TYPE_PRF, NID_hmacWithSHA512, -1, NID_sha512, 0}, 75e1051a39Sopenharmony_ci {EVP_PBE_TYPE_PRF, NID_id_HMACGostR3411_94, -1, NID_id_GostR3411_94, 0}, 76e1051a39Sopenharmony_ci {EVP_PBE_TYPE_PRF, NID_id_tc26_hmac_gost_3411_2012_256, -1, 77e1051a39Sopenharmony_ci NID_id_GostR3411_2012_256, 0}, 78e1051a39Sopenharmony_ci {EVP_PBE_TYPE_PRF, NID_id_tc26_hmac_gost_3411_2012_512, -1, 79e1051a39Sopenharmony_ci NID_id_GostR3411_2012_512, 0}, 80e1051a39Sopenharmony_ci {EVP_PBE_TYPE_PRF, NID_hmacWithSHA512_224, -1, NID_sha512_224, 0}, 81e1051a39Sopenharmony_ci {EVP_PBE_TYPE_PRF, NID_hmacWithSHA512_256, -1, NID_sha512_256, 0}, 82e1051a39Sopenharmony_ci {EVP_PBE_TYPE_KDF, NID_id_pbkdf2, -1, -1, PKCS5_v2_PBKDF2_keyivgen, &PKCS5_v2_PBKDF2_keyivgen_ex}, 83e1051a39Sopenharmony_ci#ifndef OPENSSL_NO_SCRYPT 84e1051a39Sopenharmony_ci {EVP_PBE_TYPE_KDF, NID_id_scrypt, -1, -1, PKCS5_v2_scrypt_keyivgen, &PKCS5_v2_scrypt_keyivgen_ex} 85e1051a39Sopenharmony_ci#endif 86e1051a39Sopenharmony_ci}; 87e1051a39Sopenharmony_ci 88e1051a39Sopenharmony_ci 89e1051a39Sopenharmony_ciint EVP_PBE_CipherInit_ex(ASN1_OBJECT *pbe_obj, const char *pass, int passlen, 90e1051a39Sopenharmony_ci ASN1_TYPE *param, EVP_CIPHER_CTX *ctx, int en_de, 91e1051a39Sopenharmony_ci OSSL_LIB_CTX *libctx, const char *propq) 92e1051a39Sopenharmony_ci{ 93e1051a39Sopenharmony_ci const EVP_CIPHER *cipher = NULL; 94e1051a39Sopenharmony_ci EVP_CIPHER *cipher_fetch = NULL; 95e1051a39Sopenharmony_ci const EVP_MD *md = NULL; 96e1051a39Sopenharmony_ci EVP_MD *md_fetch = NULL; 97e1051a39Sopenharmony_ci int ret = 0, cipher_nid, md_nid; 98e1051a39Sopenharmony_ci EVP_PBE_KEYGEN_EX *keygen_ex; 99e1051a39Sopenharmony_ci EVP_PBE_KEYGEN *keygen; 100e1051a39Sopenharmony_ci 101e1051a39Sopenharmony_ci if (!EVP_PBE_find_ex(EVP_PBE_TYPE_OUTER, OBJ_obj2nid(pbe_obj), 102e1051a39Sopenharmony_ci &cipher_nid, &md_nid, &keygen, &keygen_ex)) { 103e1051a39Sopenharmony_ci char obj_tmp[80]; 104e1051a39Sopenharmony_ci 105e1051a39Sopenharmony_ci if (pbe_obj == NULL) 106e1051a39Sopenharmony_ci OPENSSL_strlcpy(obj_tmp, "NULL", sizeof(obj_tmp)); 107e1051a39Sopenharmony_ci else 108e1051a39Sopenharmony_ci i2t_ASN1_OBJECT(obj_tmp, sizeof(obj_tmp), pbe_obj); 109e1051a39Sopenharmony_ci ERR_raise_data(ERR_LIB_EVP, EVP_R_UNKNOWN_PBE_ALGORITHM, 110e1051a39Sopenharmony_ci "TYPE=%s", obj_tmp); 111e1051a39Sopenharmony_ci goto err; 112e1051a39Sopenharmony_ci } 113e1051a39Sopenharmony_ci 114e1051a39Sopenharmony_ci if (pass == NULL) 115e1051a39Sopenharmony_ci passlen = 0; 116e1051a39Sopenharmony_ci else if (passlen == -1) 117e1051a39Sopenharmony_ci passlen = strlen(pass); 118e1051a39Sopenharmony_ci 119e1051a39Sopenharmony_ci if (cipher_nid != -1) { 120e1051a39Sopenharmony_ci (void)ERR_set_mark(); 121e1051a39Sopenharmony_ci cipher = cipher_fetch = EVP_CIPHER_fetch(libctx, OBJ_nid2sn(cipher_nid), propq); 122e1051a39Sopenharmony_ci /* Fallback to legacy method */ 123e1051a39Sopenharmony_ci if (cipher == NULL) 124e1051a39Sopenharmony_ci cipher = EVP_get_cipherbynid(cipher_nid); 125e1051a39Sopenharmony_ci if (cipher == NULL) { 126e1051a39Sopenharmony_ci (void)ERR_clear_last_mark(); 127e1051a39Sopenharmony_ci ERR_raise_data(ERR_LIB_EVP, EVP_R_UNKNOWN_CIPHER, 128e1051a39Sopenharmony_ci OBJ_nid2sn(cipher_nid)); 129e1051a39Sopenharmony_ci goto err; 130e1051a39Sopenharmony_ci } 131e1051a39Sopenharmony_ci (void)ERR_pop_to_mark(); 132e1051a39Sopenharmony_ci } 133e1051a39Sopenharmony_ci 134e1051a39Sopenharmony_ci if (md_nid != -1) { 135e1051a39Sopenharmony_ci (void)ERR_set_mark(); 136e1051a39Sopenharmony_ci md = md_fetch = EVP_MD_fetch(libctx, OBJ_nid2sn(md_nid), propq); 137e1051a39Sopenharmony_ci /* Fallback to legacy method */ 138e1051a39Sopenharmony_ci if (md == NULL) 139e1051a39Sopenharmony_ci md = EVP_get_digestbynid(md_nid); 140e1051a39Sopenharmony_ci 141e1051a39Sopenharmony_ci if (md == NULL) { 142e1051a39Sopenharmony_ci (void)ERR_clear_last_mark(); 143e1051a39Sopenharmony_ci ERR_raise(ERR_LIB_EVP, EVP_R_UNKNOWN_DIGEST); 144e1051a39Sopenharmony_ci goto err; 145e1051a39Sopenharmony_ci } 146e1051a39Sopenharmony_ci (void)ERR_pop_to_mark(); 147e1051a39Sopenharmony_ci } 148e1051a39Sopenharmony_ci 149e1051a39Sopenharmony_ci /* Try extended keygen with libctx/propq first, fall back to legacy keygen */ 150e1051a39Sopenharmony_ci if (keygen_ex != NULL) 151e1051a39Sopenharmony_ci ret = keygen_ex(ctx, pass, passlen, param, cipher, md, en_de, libctx, propq); 152e1051a39Sopenharmony_ci else 153e1051a39Sopenharmony_ci ret = keygen(ctx, pass, passlen, param, cipher, md, en_de); 154e1051a39Sopenharmony_ci 155e1051a39Sopenharmony_cierr: 156e1051a39Sopenharmony_ci EVP_CIPHER_free(cipher_fetch); 157e1051a39Sopenharmony_ci EVP_MD_free(md_fetch); 158e1051a39Sopenharmony_ci 159e1051a39Sopenharmony_ci return ret; 160e1051a39Sopenharmony_ci} 161e1051a39Sopenharmony_ci 162e1051a39Sopenharmony_ciint EVP_PBE_CipherInit(ASN1_OBJECT *pbe_obj, const char *pass, int passlen, 163e1051a39Sopenharmony_ci ASN1_TYPE *param, EVP_CIPHER_CTX *ctx, int en_de) 164e1051a39Sopenharmony_ci{ 165e1051a39Sopenharmony_ci return EVP_PBE_CipherInit_ex(pbe_obj, pass, passlen, param, ctx, en_de, NULL, NULL); 166e1051a39Sopenharmony_ci} 167e1051a39Sopenharmony_ci 168e1051a39Sopenharmony_ciDECLARE_OBJ_BSEARCH_CMP_FN(EVP_PBE_CTL, EVP_PBE_CTL, pbe2); 169e1051a39Sopenharmony_ci 170e1051a39Sopenharmony_cistatic int pbe2_cmp(const EVP_PBE_CTL *pbe1, const EVP_PBE_CTL *pbe2) 171e1051a39Sopenharmony_ci{ 172e1051a39Sopenharmony_ci int ret = pbe1->pbe_type - pbe2->pbe_type; 173e1051a39Sopenharmony_ci if (ret) 174e1051a39Sopenharmony_ci return ret; 175e1051a39Sopenharmony_ci else 176e1051a39Sopenharmony_ci return pbe1->pbe_nid - pbe2->pbe_nid; 177e1051a39Sopenharmony_ci} 178e1051a39Sopenharmony_ci 179e1051a39Sopenharmony_ciIMPLEMENT_OBJ_BSEARCH_CMP_FN(EVP_PBE_CTL, EVP_PBE_CTL, pbe2); 180e1051a39Sopenharmony_ci 181e1051a39Sopenharmony_cistatic int pbe_cmp(const EVP_PBE_CTL *const *a, const EVP_PBE_CTL *const *b) 182e1051a39Sopenharmony_ci{ 183e1051a39Sopenharmony_ci int ret = (*a)->pbe_type - (*b)->pbe_type; 184e1051a39Sopenharmony_ci if (ret) 185e1051a39Sopenharmony_ci return ret; 186e1051a39Sopenharmony_ci else 187e1051a39Sopenharmony_ci return (*a)->pbe_nid - (*b)->pbe_nid; 188e1051a39Sopenharmony_ci} 189e1051a39Sopenharmony_ci 190e1051a39Sopenharmony_ci/* Add a PBE algorithm */ 191e1051a39Sopenharmony_ci 192e1051a39Sopenharmony_ciint EVP_PBE_alg_add_type(int pbe_type, int pbe_nid, int cipher_nid, 193e1051a39Sopenharmony_ci int md_nid, EVP_PBE_KEYGEN *keygen) 194e1051a39Sopenharmony_ci{ 195e1051a39Sopenharmony_ci EVP_PBE_CTL *pbe_tmp; 196e1051a39Sopenharmony_ci 197e1051a39Sopenharmony_ci if (pbe_algs == NULL) { 198e1051a39Sopenharmony_ci pbe_algs = sk_EVP_PBE_CTL_new(pbe_cmp); 199e1051a39Sopenharmony_ci if (pbe_algs == NULL) 200e1051a39Sopenharmony_ci goto err; 201e1051a39Sopenharmony_ci } 202e1051a39Sopenharmony_ci 203e1051a39Sopenharmony_ci if ((pbe_tmp = OPENSSL_zalloc(sizeof(*pbe_tmp))) == NULL) 204e1051a39Sopenharmony_ci goto err; 205e1051a39Sopenharmony_ci 206e1051a39Sopenharmony_ci pbe_tmp->pbe_type = pbe_type; 207e1051a39Sopenharmony_ci pbe_tmp->pbe_nid = pbe_nid; 208e1051a39Sopenharmony_ci pbe_tmp->cipher_nid = cipher_nid; 209e1051a39Sopenharmony_ci pbe_tmp->md_nid = md_nid; 210e1051a39Sopenharmony_ci pbe_tmp->keygen = keygen; 211e1051a39Sopenharmony_ci 212e1051a39Sopenharmony_ci if (!sk_EVP_PBE_CTL_push(pbe_algs, pbe_tmp)) { 213e1051a39Sopenharmony_ci OPENSSL_free(pbe_tmp); 214e1051a39Sopenharmony_ci goto err; 215e1051a39Sopenharmony_ci } 216e1051a39Sopenharmony_ci return 1; 217e1051a39Sopenharmony_ci 218e1051a39Sopenharmony_ci err: 219e1051a39Sopenharmony_ci ERR_raise(ERR_LIB_EVP, ERR_R_MALLOC_FAILURE); 220e1051a39Sopenharmony_ci return 0; 221e1051a39Sopenharmony_ci} 222e1051a39Sopenharmony_ci 223e1051a39Sopenharmony_ciint EVP_PBE_alg_add(int nid, const EVP_CIPHER *cipher, const EVP_MD *md, 224e1051a39Sopenharmony_ci EVP_PBE_KEYGEN *keygen) 225e1051a39Sopenharmony_ci{ 226e1051a39Sopenharmony_ci int cipher_nid, md_nid; 227e1051a39Sopenharmony_ci 228e1051a39Sopenharmony_ci if (cipher) 229e1051a39Sopenharmony_ci cipher_nid = EVP_CIPHER_get_nid(cipher); 230e1051a39Sopenharmony_ci else 231e1051a39Sopenharmony_ci cipher_nid = -1; 232e1051a39Sopenharmony_ci if (md) 233e1051a39Sopenharmony_ci md_nid = EVP_MD_get_type(md); 234e1051a39Sopenharmony_ci else 235e1051a39Sopenharmony_ci md_nid = -1; 236e1051a39Sopenharmony_ci 237e1051a39Sopenharmony_ci return EVP_PBE_alg_add_type(EVP_PBE_TYPE_OUTER, nid, 238e1051a39Sopenharmony_ci cipher_nid, md_nid, keygen); 239e1051a39Sopenharmony_ci} 240e1051a39Sopenharmony_ci 241e1051a39Sopenharmony_ciint EVP_PBE_find_ex(int type, int pbe_nid, int *pcnid, int *pmnid, 242e1051a39Sopenharmony_ci EVP_PBE_KEYGEN **pkeygen, EVP_PBE_KEYGEN_EX **pkeygen_ex) 243e1051a39Sopenharmony_ci{ 244e1051a39Sopenharmony_ci EVP_PBE_CTL *pbetmp = NULL, pbelu; 245e1051a39Sopenharmony_ci int i; 246e1051a39Sopenharmony_ci if (pbe_nid == NID_undef) 247e1051a39Sopenharmony_ci return 0; 248e1051a39Sopenharmony_ci 249e1051a39Sopenharmony_ci pbelu.pbe_type = type; 250e1051a39Sopenharmony_ci pbelu.pbe_nid = pbe_nid; 251e1051a39Sopenharmony_ci 252e1051a39Sopenharmony_ci if (pbe_algs != NULL) { 253e1051a39Sopenharmony_ci i = sk_EVP_PBE_CTL_find(pbe_algs, &pbelu); 254e1051a39Sopenharmony_ci pbetmp = sk_EVP_PBE_CTL_value(pbe_algs, i); 255e1051a39Sopenharmony_ci } 256e1051a39Sopenharmony_ci if (pbetmp == NULL) { 257e1051a39Sopenharmony_ci pbetmp = OBJ_bsearch_pbe2(&pbelu, builtin_pbe, OSSL_NELEM(builtin_pbe)); 258e1051a39Sopenharmony_ci } 259e1051a39Sopenharmony_ci if (pbetmp == NULL) 260e1051a39Sopenharmony_ci return 0; 261e1051a39Sopenharmony_ci if (pcnid != NULL) 262e1051a39Sopenharmony_ci *pcnid = pbetmp->cipher_nid; 263e1051a39Sopenharmony_ci if (pmnid != NULL) 264e1051a39Sopenharmony_ci *pmnid = pbetmp->md_nid; 265e1051a39Sopenharmony_ci if (pkeygen != NULL) 266e1051a39Sopenharmony_ci *pkeygen = pbetmp->keygen; 267e1051a39Sopenharmony_ci if (pkeygen_ex != NULL) 268e1051a39Sopenharmony_ci *pkeygen_ex = pbetmp->keygen_ex; 269e1051a39Sopenharmony_ci return 1; 270e1051a39Sopenharmony_ci} 271e1051a39Sopenharmony_ci 272e1051a39Sopenharmony_ciint EVP_PBE_find(int type, int pbe_nid, 273e1051a39Sopenharmony_ci int *pcnid, int *pmnid, EVP_PBE_KEYGEN **pkeygen) 274e1051a39Sopenharmony_ci{ 275e1051a39Sopenharmony_ci return EVP_PBE_find_ex(type, pbe_nid, pcnid, pmnid, pkeygen, NULL); 276e1051a39Sopenharmony_ci} 277e1051a39Sopenharmony_ci 278e1051a39Sopenharmony_cistatic void free_evp_pbe_ctl(EVP_PBE_CTL *pbe) 279e1051a39Sopenharmony_ci{ 280e1051a39Sopenharmony_ci OPENSSL_free(pbe); 281e1051a39Sopenharmony_ci} 282e1051a39Sopenharmony_ci 283e1051a39Sopenharmony_civoid EVP_PBE_cleanup(void) 284e1051a39Sopenharmony_ci{ 285e1051a39Sopenharmony_ci sk_EVP_PBE_CTL_pop_free(pbe_algs, free_evp_pbe_ctl); 286e1051a39Sopenharmony_ci pbe_algs = NULL; 287e1051a39Sopenharmony_ci} 288e1051a39Sopenharmony_ci 289e1051a39Sopenharmony_ciint EVP_PBE_get(int *ptype, int *ppbe_nid, size_t num) 290e1051a39Sopenharmony_ci{ 291e1051a39Sopenharmony_ci const EVP_PBE_CTL *tpbe; 292e1051a39Sopenharmony_ci 293e1051a39Sopenharmony_ci if (num >= OSSL_NELEM(builtin_pbe)) 294e1051a39Sopenharmony_ci return 0; 295e1051a39Sopenharmony_ci 296e1051a39Sopenharmony_ci tpbe = builtin_pbe + num; 297e1051a39Sopenharmony_ci if (ptype) 298e1051a39Sopenharmony_ci *ptype = tpbe->pbe_type; 299e1051a39Sopenharmony_ci if (ppbe_nid) 300e1051a39Sopenharmony_ci *ppbe_nid = tpbe->pbe_nid; 301e1051a39Sopenharmony_ci return 1; 302e1051a39Sopenharmony_ci} 303