PKCS12_SAFEBAG *PKCS12_SAFEBAG_create_pkcs8_encrypt(int pbe_nid,
                                                    const char *pass,
                                                    int passlen,
                                                    unsigned char *salt,
                                                    int saltlen, int iter,
                                                    PKCS8_PRIV_KEY_INFO *p8inf)
{
    PKCS12_SAFEBAG *bag;
    const EVP_CIPHER *pbe_ciph;
    X509_SIG *p8;
    pbe_ciph = EVP_get_cipherbynid(pbe_nid);
    if (pbe_ciph)
        pbe_nid = -1;
    p8 = PKCS8_encrypt(pbe_nid, pbe_ciph, pass, passlen, salt, saltlen, iter,
                       p8inf);
    if (p8 == NULL) {
        PKCS12err(PKCS12_F_PKCS12_SAFEBAG_CREATE_PKCS8_ENCRYPT, ERR_R_MALLOC_FAILURE);
        return NULL;
    }
    bag = PKCS12_SAFEBAG_create0_pkcs8(p8);
    if (bag == NULL) {
        PKCS12err(PKCS12_F_PKCS12_SAFEBAG_CREATE_PKCS8_ENCRYPT, ERR_R_MALLOC_FAILURE);
        X509_SIG_free(p8);
        return NULL;
    }
    return bag;
}
['PKCS12_SAFEBAG *PKCS12_SAFEBAG_create_pkcs8_encrypt(int pbe_nid,\n                                                    const char *pass,\n                                                    int passlen,\n                                                    unsigned char *salt,\n                                                    int saltlen, int iter,\n                                                    PKCS8_PRIV_KEY_INFO *p8inf)\n{\n    PKCS12_SAFEBAG *bag;\n    const EVP_CIPHER *pbe_ciph;\n    X509_SIG *p8;\n    pbe_ciph = EVP_get_cipherbynid(pbe_nid);\n    if (pbe_ciph)\n        pbe_nid = -1;\n    p8 = PKCS8_encrypt(pbe_nid, pbe_ciph, pass, passlen, salt, saltlen, iter,\n                       p8inf);\n    if (p8 == NULL) {\n        PKCS12err(PKCS12_F_PKCS12_SAFEBAG_CREATE_PKCS8_ENCRYPT, ERR_R_MALLOC_FAILURE);\n        return NULL;\n    }\n    bag = PKCS12_SAFEBAG_create0_pkcs8(p8);\n    if (bag == NULL) {\n        PKCS12err(PKCS12_F_PKCS12_SAFEBAG_CREATE_PKCS8_ENCRYPT, ERR_R_MALLOC_FAILURE);\n        X509_SIG_free(p8);\n        return NULL;\n    }\n    return bag;\n}', 'const char *OBJ_nid2sn(int n)\n{\n    ADDED_OBJ ad, *adp;\n    ASN1_OBJECT ob;\n    if ((n >= 0) && (n < NUM_NID)) {\n        if ((n != NID_undef) && (nid_objs[n].nid == NID_undef)) {\n            OBJerr(OBJ_F_OBJ_NID2SN, OBJ_R_UNKNOWN_NID);\n            return NULL;\n        }\n        return nid_objs[n].sn;\n    } else if (added == NULL)\n        return NULL;\n    else {\n        ad.type = ADDED_NID;\n        ad.obj = &ob;\n        ob.nid = n;\n        adp = lh_ADDED_OBJ_retrieve(added, &ad);\n        if (adp != NULL)\n            return adp->obj->sn;\n        else {\n            OBJerr(OBJ_F_OBJ_NID2SN, OBJ_R_UNKNOWN_NID);\n            return NULL;\n        }\n    }\n}', 'DEFINE_LHASH_OF(ADDED_OBJ)', 'void *OPENSSL_LH_retrieve(OPENSSL_LHASH *lh, const void *data)\n{\n    unsigned long hash;\n    OPENSSL_LH_NODE **rn;\n    void *ret;\n    int scratch;\n    lh->error = 0;\n    rn = getrn(lh, data, &hash);\n    if (*rn == NULL) {\n        CRYPTO_atomic_add(&lh->num_retrieve_miss, 1, &scratch, lh->retrieve_stats_lock);\n        return NULL;\n    } else {\n        ret = (*rn)->data;\n        CRYPTO_atomic_add(&lh->num_retrieve, 1, &scratch, lh->retrieve_stats_lock);\n    }\n    return ret;\n}', 'int CRYPTO_atomic_add(int *val, int amount, int *ret, CRYPTO_RWLOCK *lock)\n{\n# if defined(__GNUC__) && defined(__ATOMIC_ACQ_REL)\n    if (__atomic_is_lock_free(sizeof(*val), val)) {\n        *ret = __atomic_add_fetch(val, amount, __ATOMIC_ACQ_REL);\n        return 1;\n    }\n# endif\n    if (!CRYPTO_THREAD_write_lock(lock))\n        return 0;\n    *val += amount;\n    *ret  = *val;\n    if (!CRYPTO_THREAD_unlock(lock))\n        return 0;\n    return 1;\n}', 'int CRYPTO_THREAD_write_lock(CRYPTO_RWLOCK *lock)\n{\n# ifdef USE_RWLOCK\n    if (pthread_rwlock_wrlock(lock) != 0)\n        return 0;\n# else\n    if (pthread_mutex_lock(lock) != 0)\n        return 0;\n# endif\n    return 1;\n}', 'const EVP_CIPHER *EVP_get_cipherbyname(const char *name)\n{\n    const EVP_CIPHER *cp;\n    if (!OPENSSL_init_crypto(OPENSSL_INIT_ADD_ALL_CIPHERS, NULL))\n        return NULL;\n    cp = (const EVP_CIPHER *)OBJ_NAME_get(name, OBJ_NAME_TYPE_CIPHER_METH);\n    return (cp);\n}']