static int expand(OPENSSL_LHASH *lh)
{
    OPENSSL_LH_NODE **n, **n1, **n2, *np;
    unsigned int p, i, j;
    unsigned long hash, nni;
    lh->num_nodes++;
    lh->num_expands++;
    p = (int)lh->p++;
    n1 = &(lh->b[p]);
    n2 = &(lh->b[p + (int)lh->pmax]);
    *n2 = NULL;
    nni = lh->num_alloc_nodes;
    for (np = *n1; np != NULL;) {
        hash = np->hash;
        if ((hash % nni) != p) {
            *n1 = (*n1)->next;
            np->next = *n2;
            *n2 = np;
        } else
            n1 = &((*n1)->next);
        np = *n1;
    }
    if ((lh->p) >= lh->pmax) {
        j = (int)lh->num_alloc_nodes * 2;
        n = OPENSSL_realloc(lh->b, (int)(sizeof(OPENSSL_LH_NODE *) * j));
        if (n == NULL) {
            lh->error++;
            lh->p = 0;
            return 0;
        }
        for (i = (int)lh->num_alloc_nodes; i < j; i++)
            n[i] = NULL;
        lh->pmax = lh->num_alloc_nodes;
        lh->num_alloc_nodes = j;
        lh->num_expand_reallocs++;
        lh->p = 0;
        lh->b = n;
    }
    return 1;
}
['int srp_main(int argc, char **argv)\n{\n    CA_DB *db = NULL;\n    CONF *conf = NULL;\n    int gNindex = -1, maxgN = -1, ret = 1, errors = 0, verbose = 0, i;\n    int doupdatedb = 0, mode = OPT_ERR;\n    char *user = NULL, *passinarg = NULL, *passoutarg = NULL;\n    char *passin = NULL, *passout = NULL, *gN = NULL, *userinfo = NULL;\n    char *randfile = NULL, *section = NULL;\n    char **gNrow = NULL, *configfile = NULL;\n    char *srpvfile = NULL, **pp, *prog;\n    OPTION_CHOICE o;\n    prog = opt_init(argc, argv, srp_options);\n    while ((o = opt_next()) != OPT_EOF) {\n        switch (o) {\n        case OPT_EOF:\n        case OPT_ERR:\n opthelp:\n            BIO_printf(bio_err, "%s: Use -help for summary.\\n", prog);\n            goto end;\n        case OPT_HELP:\n            opt_help(srp_options);\n            ret = 0;\n            goto end;\n        case OPT_VERBOSE:\n            verbose++;\n            break;\n        case OPT_CONFIG:\n            configfile = opt_arg();\n            break;\n        case OPT_NAME:\n            section = opt_arg();\n            break;\n        case OPT_SRPVFILE:\n            srpvfile = opt_arg();\n            break;\n        case OPT_ADD:\n        case OPT_DELETE:\n        case OPT_MODIFY:\n        case OPT_LIST:\n            if (mode != OPT_ERR) {\n                BIO_printf(bio_err,\n                           "%s: Only one of -add/delete-modify/-list\\n",\n                           prog);\n                goto opthelp;\n            }\n            mode = o;\n            break;\n        case OPT_GN:\n            gN = opt_arg();\n            break;\n        case OPT_USERINFO:\n            userinfo = opt_arg();\n            break;\n        case OPT_PASSIN:\n            passinarg = opt_arg();\n            break;\n        case OPT_PASSOUT:\n            passoutarg = opt_arg();\n            break;\n        case OPT_ENGINE:\n            (void)setup_engine(opt_arg(), 0);\n            break;\n        }\n    }\n    argc = opt_num_rest();\n    argv = opt_rest();\n    if (srpvfile && configfile) {\n        BIO_printf(bio_err,\n                   "-srpvfile and -configfile cannot be specified together.\\n");\n        goto end;\n    }\n    if (mode == OPT_ERR) {\n        BIO_printf(bio_err,\n                   "Exactly one of the options -add, -delete, -modify -list must be specified.\\n");\n        goto opthelp;\n    }\n    if ((mode == OPT_DELETE || mode == OPT_MODIFY || mode == OPT_ADD)\n        && argc < 1) {\n        BIO_printf(bio_err,\n                   "Need at least one user for options -add, -delete, -modify. \\n");\n        goto opthelp;\n    }\n    if ((passin || passout) && argc != 1) {\n        BIO_printf(bio_err,\n                   "-passin, -passout arguments only valid with one user.\\n");\n        goto opthelp;\n    }\n    if (!app_passwd(passinarg, passoutarg, &passin, &passout)) {\n        BIO_printf(bio_err, "Error getting passwords\\n");\n        goto end;\n    }\n    if (!srpvfile) {\n        if (!configfile)\n            configfile = default_config_file;\n        if (verbose)\n            BIO_printf(bio_err, "Using configuration from %s\\n",\n                       configfile);\n        conf = app_load_config(configfile);\n        if (conf == NULL)\n            goto end;\n        if (configfile != default_config_file && !app_load_modules(conf))\n            goto end;\n        if (section == NULL) {\n            if (verbose)\n                BIO_printf(bio_err,\n                           "trying to read " ENV_DEFAULT_SRP\n                           " in " BASE_SECTION "\\n");\n            section = NCONF_get_string(conf, BASE_SECTION, ENV_DEFAULT_SRP);\n            if (section == NULL) {\n                lookup_fail(BASE_SECTION, ENV_DEFAULT_SRP);\n                goto end;\n            }\n        }\n        if (randfile == NULL && conf)\n            randfile = NCONF_get_string(conf, BASE_SECTION, "RANDFILE");\n        if (verbose)\n            BIO_printf(bio_err,\n                       "trying to read " ENV_DATABASE " in section \\"%s\\"\\n",\n                       section);\n        if ((srpvfile = NCONF_get_string(conf, section, ENV_DATABASE))\n                == NULL) {\n            lookup_fail(section, ENV_DATABASE);\n            goto end;\n        }\n    }\n    if (randfile == NULL)\n        ERR_clear_error();\n    else\n        app_RAND_load_file(randfile, 0);\n    if (verbose)\n        BIO_printf(bio_err, "Trying to read SRP verifier file \\"%s\\"\\n",\n                   srpvfile);\n    db = load_index(srpvfile, NULL);\n    if (db == NULL)\n        goto end;\n    for (i = 0; i < sk_OPENSSL_PSTRING_num(db->db->data); i++) {\n        pp = sk_OPENSSL_PSTRING_value(db->db->data, i);\n        if (pp[DB_srptype][0] == DB_SRP_INDEX) {\n            maxgN = i;\n            if ((gNindex < 0) && (gN != NULL) && strcmp(gN, pp[DB_srpid]) == 0)\n                gNindex = i;\n            print_index(db, i, verbose > 1);\n        }\n    }\n    if (verbose)\n        BIO_printf(bio_err, "Database initialised\\n");\n    if (gNindex >= 0) {\n        gNrow = sk_OPENSSL_PSTRING_value(db->db->data, gNindex);\n        print_entry(db, gNindex, verbose > 1, "Default g and N");\n    } else if (maxgN > 0 && !SRP_get_default_gN(gN)) {\n        BIO_printf(bio_err, "No g and N value for index \\"%s\\"\\n", gN);\n        goto end;\n    } else {\n        if (verbose)\n            BIO_printf(bio_err, "Database has no g N information.\\n");\n        gNrow = NULL;\n    }\n    if (verbose > 1)\n        BIO_printf(bio_err, "Starting user processing\\n");\n    if (argc > 0)\n        user = *(argv++);\n    while (mode == OPT_LIST || user) {\n        int userindex = -1;\n        if (user)\n            if (verbose > 1)\n                BIO_printf(bio_err, "Processing user \\"%s\\"\\n", user);\n        if ((userindex = get_index(db, user, \'U\')) >= 0) {\n            print_user(db, userindex, (verbose > 0)\n                       || mode == OPT_LIST);\n        }\n        if (mode == OPT_LIST) {\n            if (user == NULL) {\n                BIO_printf(bio_err, "List all users\\n");\n                for (i = 0; i < sk_OPENSSL_PSTRING_num(db->db->data); i++) {\n                    print_user(db, i, 1);\n                }\n            } else if (userindex < 0) {\n                BIO_printf(bio_err,\n                           "user \\"%s\\" does not exist, ignored. t\\n", user);\n                errors++;\n            }\n        } else if (mode == OPT_ADD) {\n            if (userindex >= 0) {\n                char **row =\n                    sk_OPENSSL_PSTRING_value(db->db->data, userindex);\n                BIO_printf(bio_err, "user \\"%s\\" reactivated.\\n", user);\n                row[DB_srptype][0] = \'V\';\n                doupdatedb = 1;\n            } else {\n                char *row[DB_NUMBER];\n                char *gNid;\n                row[DB_srpverifier] = NULL;\n                row[DB_srpsalt] = NULL;\n                row[DB_srpinfo] = NULL;\n                if (!\n                    (gNid =\n                     srp_create_user(user, &(row[DB_srpverifier]),\n                                     &(row[DB_srpsalt]),\n                                     gNrow ? gNrow[DB_srpsalt] : gN,\n                                     gNrow ? gNrow[DB_srpverifier] : NULL,\n                                     passout, verbose))) {\n                    BIO_printf(bio_err,\n                               "Cannot create srp verifier for user \\"%s\\", operation abandoned .\\n",\n                               user);\n                    errors++;\n                    goto end;\n                }\n                row[DB_srpid] = OPENSSL_strdup(user);\n                row[DB_srptype] = OPENSSL_strdup("v");\n                row[DB_srpgN] = OPENSSL_strdup(gNid);\n                if ((row[DB_srpid] == NULL)\n                    || (row[DB_srpgN] == NULL)\n                    || (row[DB_srptype] == NULL)\n                    || (row[DB_srpverifier] == NULL)\n                    || (row[DB_srpsalt] == NULL)\n                    || (userinfo\n                        && ((row[DB_srpinfo] = OPENSSL_strdup(userinfo)) == NULL))\n                    || !update_index(db, row)) {\n                    OPENSSL_free(row[DB_srpid]);\n                    OPENSSL_free(row[DB_srpgN]);\n                    OPENSSL_free(row[DB_srpinfo]);\n                    OPENSSL_free(row[DB_srptype]);\n                    OPENSSL_free(row[DB_srpverifier]);\n                    OPENSSL_free(row[DB_srpsalt]);\n                    goto end;\n                }\n                doupdatedb = 1;\n            }\n        } else if (mode == OPT_MODIFY) {\n            if (userindex < 0) {\n                BIO_printf(bio_err,\n                           "user \\"%s\\" does not exist, operation ignored.\\n",\n                           user);\n                errors++;\n            } else {\n                char **row =\n                    sk_OPENSSL_PSTRING_value(db->db->data, userindex);\n                char type = row[DB_srptype][0];\n                if (type == \'v\') {\n                    BIO_printf(bio_err,\n                               "user \\"%s\\" already updated, operation ignored.\\n",\n                               user);\n                    errors++;\n                } else {\n                    char *gNid;\n                    if (row[DB_srptype][0] == \'V\') {\n                        int user_gN;\n                        char **irow = NULL;\n                        if (verbose)\n                            BIO_printf(bio_err,\n                                       "Verifying password for user \\"%s\\"\\n",\n                                       user);\n                        if ((user_gN =\n                             get_index(db, row[DB_srpgN], DB_SRP_INDEX)) >= 0)\n                            irow =\n                                sk_OPENSSL_PSTRING_value(db->db->data,\n                                                         userindex);\n                        if (!srp_verify_user\n                            (user, row[DB_srpverifier], row[DB_srpsalt],\n                             irow ? irow[DB_srpsalt] : row[DB_srpgN],\n                             irow ? irow[DB_srpverifier] : NULL, passin,\n                             verbose)) {\n                            BIO_printf(bio_err,\n                                       "Invalid password for user \\"%s\\", operation abandoned.\\n",\n                                       user);\n                            errors++;\n                            goto end;\n                        }\n                    }\n                    if (verbose)\n                        BIO_printf(bio_err, "Password for user \\"%s\\" ok.\\n",\n                                   user);\n                    if (!\n                        (gNid =\n                         srp_create_user(user, &(row[DB_srpverifier]),\n                                         &(row[DB_srpsalt]),\n                                         gNrow ? gNrow[DB_srpsalt] : NULL,\n                                         gNrow ? gNrow[DB_srpverifier] : NULL,\n                                         passout, verbose))) {\n                        BIO_printf(bio_err,\n                                   "Cannot create srp verifier for user \\"%s\\", operation abandoned.\\n",\n                                   user);\n                        errors++;\n                        goto end;\n                    }\n                    row[DB_srptype][0] = \'v\';\n                    row[DB_srpgN] = OPENSSL_strdup(gNid);\n                    if (row[DB_srpid] == NULL\n                        || row[DB_srpgN] == NULL\n                        || row[DB_srptype] == NULL\n                        || row[DB_srpverifier] == NULL\n                        || row[DB_srpsalt] == NULL\n                        || (userinfo\n                            && ((row[DB_srpinfo] = OPENSSL_strdup(userinfo))\n                                == NULL)))\n                        goto end;\n                    doupdatedb = 1;\n                }\n            }\n        } else if (mode == OPT_DELETE) {\n            if (userindex < 0) {\n                BIO_printf(bio_err,\n                           "user \\"%s\\" does not exist, operation ignored. t\\n",\n                           user);\n                errors++;\n            } else {\n                char **xpp = sk_OPENSSL_PSTRING_value(db->db->data, userindex);\n                BIO_printf(bio_err, "user \\"%s\\" revoked. t\\n", user);\n                xpp[DB_srptype][0] = \'R\';\n                doupdatedb = 1;\n            }\n        }\n        if (--argc > 0)\n            user = *(argv++);\n        else {\n            user = NULL;\n        }\n    }\n    if (verbose)\n        BIO_printf(bio_err, "User procession done.\\n");\n    if (doupdatedb) {\n        for (i = 0; i < sk_OPENSSL_PSTRING_num(db->db->data); i++) {\n            pp = sk_OPENSSL_PSTRING_value(db->db->data, i);\n            if (pp[DB_srptype][0] == \'v\') {\n                pp[DB_srptype][0] = \'V\';\n                print_user(db, i, verbose);\n            }\n        }\n        if (verbose)\n            BIO_printf(bio_err, "Trying to update srpvfile.\\n");\n        if (!save_index(srpvfile, "new", db))\n            goto end;\n        if (verbose)\n            BIO_printf(bio_err, "Temporary srpvfile created.\\n");\n        if (!rotate_index(srpvfile, "new", "old"))\n            goto end;\n        if (verbose)\n            BIO_printf(bio_err, "srpvfile updated.\\n");\n    }\n    ret = (errors != 0);\n end:\n    if (errors != 0)\n        if (verbose)\n            BIO_printf(bio_err, "User errors %d.\\n", errors);\n    if (verbose)\n        BIO_printf(bio_err, "SRP terminating with code %d.\\n", ret);\n    OPENSSL_free(passin);\n    OPENSSL_free(passout);\n    if (ret)\n        ERR_print_errors(bio_err);\n    if (randfile)\n        app_RAND_write_file(randfile);\n    NCONF_free(conf);\n    free_index(db);\n    return (ret);\n}', 'static char *srp_create_user(char *user, char **srp_verifier,\n                             char **srp_usersalt, char *g, char *N,\n                             char *passout, int verbose)\n{\n    char password[1024];\n    PW_CB_DATA cb_tmp;\n    char *gNid = NULL;\n    char *salt = NULL;\n    cb_tmp.prompt_info = user;\n    cb_tmp.password = passout;\n    if (password_callback(password, 1024, 1, &cb_tmp) > 0) {\n        if (verbose)\n            BIO_printf(bio_err, "Creating\\n user=\\"%s\\"\\n g=\\"%s\\"\\n N=\\"%s\\"\\n",\n                       user, g, N);\n        if (!\n            (gNid =\n             SRP_create_verifier(user, password, &salt, srp_verifier, N,\n                                 g))) {\n            BIO_printf(bio_err, "Internal error creating SRP verifier\\n");\n        } else\n            *srp_usersalt = salt;\n        if (verbose > 1)\n            BIO_printf(bio_err, "gNid=%s salt =\\"%s\\"\\n verifier =\\"%s\\"\\n", gNid,\n                       salt, *srp_verifier);\n    }\n    return gNid;\n}', 'char *SRP_create_verifier(const char *user, const char *pass, char **salt,\n                          char **verifier, const char *N, const char *g)\n{\n    int len;\n    char *result = NULL, *vf = NULL;\n    const BIGNUM *N_bn = NULL, *g_bn = NULL;\n    BIGNUM *N_bn_alloc = NULL, *g_bn_alloc = NULL, *s = NULL, *v = NULL;\n    unsigned char tmp[MAX_LEN];\n    unsigned char tmp2[MAX_LEN];\n    char *defgNid = NULL;\n    int vfsize = 0;\n    if ((user == NULL) ||\n        (pass == NULL) || (salt == NULL) || (verifier == NULL))\n        goto err;\n    if (N) {\n        if ((len = t_fromb64(tmp, N)) == 0)\n            goto err;\n        N_bn_alloc = BN_bin2bn(tmp, len, NULL);\n        N_bn = N_bn_alloc;\n        if ((len = t_fromb64(tmp, g)) == 0)\n            goto err;\n        g_bn_alloc = BN_bin2bn(tmp, len, NULL);\n        g_bn = g_bn_alloc;\n        defgNid = "*";\n    } else {\n        SRP_gN *gN = SRP_get_gN_by_id(g, NULL);\n        if (gN == NULL)\n            goto err;\n        N_bn = gN->N;\n        g_bn = gN->g;\n        defgNid = gN->id;\n    }\n    if (*salt == NULL) {\n        if (RAND_bytes(tmp2, SRP_RANDOM_SALT_LEN) <= 0)\n            goto err;\n        s = BN_bin2bn(tmp2, SRP_RANDOM_SALT_LEN, NULL);\n    } else {\n        if ((len = t_fromb64(tmp2, *salt)) == 0)\n            goto err;\n        s = BN_bin2bn(tmp2, len, NULL);\n    }\n    if (!SRP_create_verifier_BN(user, pass, &s, &v, N_bn, g_bn))\n        goto err;\n    BN_bn2bin(v, tmp);\n    vfsize = BN_num_bytes(v) * 2;\n    if (((vf = OPENSSL_malloc(vfsize)) == NULL))\n        goto err;\n    t_tob64(vf, tmp, BN_num_bytes(v));\n    if (*salt == NULL) {\n        char *tmp_salt;\n        if ((tmp_salt = OPENSSL_malloc(SRP_RANDOM_SALT_LEN * 2)) == NULL) {\n            goto err;\n        }\n        t_tob64(tmp_salt, tmp2, SRP_RANDOM_SALT_LEN);\n        *salt = tmp_salt;\n    }\n    *verifier = vf;\n    vf = NULL;\n    result = defgNid;\n err:\n    BN_free(N_bn_alloc);\n    BN_free(g_bn_alloc);\n    OPENSSL_clear_free(vf, vfsize);\n    BN_clear_free(s);\n    BN_clear_free(v);\n    return result;\n}', 'int SRP_create_verifier_BN(const char *user, const char *pass, BIGNUM **salt,\n                           BIGNUM **verifier, const BIGNUM *N,\n                           const BIGNUM *g)\n{\n    int result = 0;\n    BIGNUM *x = NULL;\n    BN_CTX *bn_ctx = BN_CTX_new();\n    unsigned char tmp2[MAX_LEN];\n    BIGNUM *salttmp = NULL;\n    if ((user == NULL) ||\n        (pass == NULL) ||\n        (salt == NULL) ||\n        (verifier == NULL) || (N == NULL) || (g == NULL) || (bn_ctx == NULL))\n        goto err;\n    if (*salt == NULL) {\n        if (RAND_bytes(tmp2, SRP_RANDOM_SALT_LEN) <= 0)\n            goto err;\n        salttmp = BN_bin2bn(tmp2, SRP_RANDOM_SALT_LEN, NULL);\n    } else {\n        salttmp = *salt;\n    }\n    x = SRP_Calc_x(salttmp, user, pass);\n    *verifier = BN_new();\n    if (*verifier == NULL)\n        goto err;\n    if (!BN_mod_exp(*verifier, g, x, N, bn_ctx)) {\n        BN_clear_free(*verifier);\n        goto err;\n    }\n    result = 1;\n    *salt = salttmp;\n err:\n    if (salt != NULL && *salt != salttmp)\n        BN_clear_free(salttmp);\n    BN_clear_free(x);\n    BN_CTX_free(bn_ctx);\n    return result;\n}', 'BIGNUM *SRP_Calc_x(const BIGNUM *s, const char *user, const char *pass)\n{\n    unsigned char dig[SHA_DIGEST_LENGTH];\n    EVP_MD_CTX *ctxt;\n    unsigned char *cs;\n    BIGNUM *res = NULL;\n    if ((s == NULL) || (user == NULL) || (pass == NULL))\n        return NULL;\n    ctxt = EVP_MD_CTX_new();\n    if (ctxt == NULL)\n        return NULL;\n    if ((cs = OPENSSL_malloc(BN_num_bytes(s))) == NULL)\n        goto err;\n    if (!EVP_DigestInit_ex(ctxt, EVP_sha1(), NULL)\n        || !EVP_DigestUpdate(ctxt, user, strlen(user))\n        || !EVP_DigestUpdate(ctxt, ":", 1)\n        || !EVP_DigestUpdate(ctxt, pass, strlen(pass))\n        || !EVP_DigestFinal_ex(ctxt, dig, NULL)\n        || !EVP_DigestInit_ex(ctxt, EVP_sha1(), NULL))\n        goto err;\n    BN_bn2bin(s, cs);\n    if (!EVP_DigestUpdate(ctxt, cs, BN_num_bytes(s)))\n        goto err;\n    OPENSSL_free(cs);\n    if (!EVP_DigestUpdate(ctxt, dig, sizeof(dig))\n        || !EVP_DigestFinal_ex(ctxt, dig, NULL))\n        goto err;\n    res = BN_bin2bn(dig, sizeof(dig), NULL);\n err:\n    EVP_MD_CTX_free(ctxt);\n    return res;\n}', 'int EVP_DigestInit_ex(EVP_MD_CTX *ctx, const EVP_MD *type, ENGINE *impl)\n{\n    EVP_MD_CTX_clear_flags(ctx, EVP_MD_CTX_FLAG_CLEANED);\n#ifndef OPENSSL_NO_ENGINE\n    if (ctx->engine && ctx->digest &&\n        (type == NULL || (type->type == ctx->digest->type)))\n        goto skip_to_init;\n    if (type) {\n        ENGINE_finish(ctx->engine);\n        if (impl != NULL) {\n            if (!ENGINE_init(impl)) {\n                EVPerr(EVP_F_EVP_DIGESTINIT_EX, EVP_R_INITIALIZATION_ERROR);\n                return 0;\n            }\n        } else {\n            impl = ENGINE_get_digest_engine(type->type);\n        }\n        if (impl != NULL) {\n            const EVP_MD *d = ENGINE_get_digest(impl, type->type);\n            if (d == NULL) {\n                EVPerr(EVP_F_EVP_DIGESTINIT_EX, EVP_R_INITIALIZATION_ERROR);\n                ENGINE_finish(impl);\n                return 0;\n            }\n            type = d;\n            ctx->engine = impl;\n        } else\n            ctx->engine = NULL;\n    } else {\n        if (!ctx->digest) {\n            EVPerr(EVP_F_EVP_DIGESTINIT_EX, EVP_R_NO_DIGEST_SET);\n            return 0;\n        }\n        type = ctx->digest;\n    }\n#endif\n    if (ctx->digest != type) {\n        if (ctx->digest && ctx->digest->ctx_size) {\n            OPENSSL_clear_free(ctx->md_data, ctx->digest->ctx_size);\n            ctx->md_data = NULL;\n        }\n        ctx->digest = type;\n        if (!(ctx->flags & EVP_MD_CTX_FLAG_NO_INIT) && type->ctx_size) {\n            ctx->update = type->update;\n            ctx->md_data = OPENSSL_zalloc(type->ctx_size);\n            if (ctx->md_data == NULL) {\n                EVPerr(EVP_F_EVP_DIGESTINIT_EX, ERR_R_MALLOC_FAILURE);\n                return 0;\n            }\n        }\n    }\n#ifndef OPENSSL_NO_ENGINE\n skip_to_init:\n#endif\n    if (ctx->pctx) {\n        int r;\n        r = EVP_PKEY_CTX_ctrl(ctx->pctx, -1, EVP_PKEY_OP_TYPE_SIG,\n                              EVP_PKEY_CTRL_DIGESTINIT, 0, ctx);\n        if (r <= 0 && (r != -2))\n            return 0;\n    }\n    if (ctx->flags & EVP_MD_CTX_FLAG_NO_INIT)\n        return 1;\n    return ctx->digest->init(ctx);\n}', 'ENGINE *ENGINE_get_digest_engine(int nid)\n{\n    return engine_table_select(&digest_table, nid);\n}', 'ENGINE *engine_table_select(ENGINE_TABLE **table, int nid)\n#else\nENGINE *engine_table_select_tmp(ENGINE_TABLE **table, int nid, const char *f,\n                                int l)\n#endif\n{\n    ENGINE *ret = NULL;\n    ENGINE_PILE tmplate, *fnd = NULL;\n    int initres, loop = 0;\n    if (!(*table)) {\n#ifdef ENGINE_TABLE_DEBUG\n        fprintf(stderr, "engine_table_dbg: %s:%d, nid=%d, nothing "\n                "registered!\\n", f, l, nid);\n#endif\n        return NULL;\n    }\n    ERR_set_mark();\n    CRYPTO_THREAD_write_lock(global_engine_lock);\n    if (!int_table_check(table, 0))\n        goto end;\n    tmplate.nid = nid;\n    fnd = lh_ENGINE_PILE_retrieve(&(*table)->piles, &tmplate);\n    if (!fnd)\n        goto end;\n    if (fnd->funct && engine_unlocked_init(fnd->funct)) {\n#ifdef ENGINE_TABLE_DEBUG\n        fprintf(stderr, "engine_table_dbg: %s:%d, nid=%d, using "\n                "ENGINE \'%s\' cached\\n", f, l, nid, fnd->funct->id);\n#endif\n        ret = fnd->funct;\n        goto end;\n    }\n    if (fnd->uptodate) {\n        ret = fnd->funct;\n        goto end;\n    }\n trynext:\n    ret = sk_ENGINE_value(fnd->sk, loop++);\n    if (!ret) {\n#ifdef ENGINE_TABLE_DEBUG\n        fprintf(stderr, "engine_table_dbg: %s:%d, nid=%d, no "\n                "registered implementations would initialise\\n", f, l, nid);\n#endif\n        goto end;\n    }\n    if ((ret->funct_ref > 0) || !(table_flags & ENGINE_TABLE_FLAG_NOINIT))\n        initres = engine_unlocked_init(ret);\n    else\n        initres = 0;\n    if (initres) {\n        if ((fnd->funct != ret) && engine_unlocked_init(ret)) {\n            if (fnd->funct)\n                engine_unlocked_finish(fnd->funct, 0);\n            fnd->funct = ret;\n#ifdef ENGINE_TABLE_DEBUG\n            fprintf(stderr, "engine_table_dbg: %s:%d, nid=%d, "\n                    "setting default to \'%s\'\\n", f, l, nid, ret->id);\n#endif\n        }\n#ifdef ENGINE_TABLE_DEBUG\n        fprintf(stderr, "engine_table_dbg: %s:%d, nid=%d, using "\n                "newly initialised \'%s\'\\n", f, l, nid, ret->id);\n#endif\n        goto end;\n    }\n    goto trynext;\n end:\n    if (fnd)\n        fnd->uptodate = 1;\n#ifdef ENGINE_TABLE_DEBUG\n    if (ret)\n        fprintf(stderr, "engine_table_dbg: %s:%d, nid=%d, caching "\n                "ENGINE \'%s\'\\n", f, l, nid, ret->id);\n    else\n        fprintf(stderr, "engine_table_dbg: %s:%d, nid=%d, caching "\n                "\'no matching ENGINE\'\\n", f, l, nid);\n#endif\n    CRYPTO_THREAD_unlock(global_engine_lock);\n    ERR_pop_to_mark();\n    return ret;\n}', 'static int int_table_check(ENGINE_TABLE **t, int create)\n{\n    LHASH_OF(ENGINE_PILE) *lh;\n    if (*t)\n        return 1;\n    if (!create)\n        return 0;\n    if ((lh = lh_ENGINE_PILE_new(engine_pile_hash, engine_pile_cmp)) == NULL)\n        return 0;\n    *t = (ENGINE_TABLE *)lh;\n    return 1;\n}', 'DEFINE_LHASH_OF(ENGINE_PILE)', 'OPENSSL_LHASH *OPENSSL_LH_new(OPENSSL_LH_HASHFUNC h, OPENSSL_LH_COMPFUNC c)\n{\n    OPENSSL_LHASH *ret;\n    if ((ret = OPENSSL_zalloc(sizeof(*ret))) == NULL)\n        goto err0;\n    if ((ret->b = OPENSSL_zalloc(sizeof(*ret->b) * MIN_NODES)) == NULL)\n        goto err1;\n    ret->comp = ((c == NULL) ? (OPENSSL_LH_COMPFUNC)strcmp : c);\n    ret->hash = ((h == NULL) ? (OPENSSL_LH_HASHFUNC)OPENSSL_LH_strhash : h);\n    ret->num_nodes = MIN_NODES / 2;\n    ret->num_alloc_nodes = MIN_NODES;\n    ret->pmax = MIN_NODES / 2;\n    ret->up_load = UP_LOAD;\n    ret->down_load = DOWN_LOAD;\n    return (ret);\n err1:\n    OPENSSL_free(ret);\n err0:\n    return (NULL);\n}', 'static int update_index(CA_DB *db, char **row)\n{\n    char **irow;\n    int i;\n    irow = app_malloc(sizeof(*irow) * (DB_NUMBER + 1), "row pointers");\n    for (i = 0; i < DB_NUMBER; i++) {\n        irow[i] = row[i];\n        row[i] = NULL;\n    }\n    irow[DB_NUMBER] = NULL;\n    if (!TXT_DB_insert(db->db, irow)) {\n        BIO_printf(bio_err, "failed to update srpvfile\\n");\n        BIO_printf(bio_err, "TXT_DB error number %ld\\n", db->db->error);\n        OPENSSL_free(irow);\n        return 0;\n    }\n    return 1;\n}', 'int TXT_DB_insert(TXT_DB *db, OPENSSL_STRING *row)\n{\n    int i;\n    OPENSSL_STRING *r;\n    for (i = 0; i < db->num_fields; i++) {\n        if (db->index[i] != NULL) {\n            if ((db->qual[i] != NULL) && (db->qual[i] (row) == 0))\n                continue;\n            r = lh_OPENSSL_STRING_retrieve(db->index[i], row);\n            if (r != NULL) {\n                db->error = DB_ERROR_INDEX_CLASH;\n                db->arg1 = i;\n                db->arg_row = r;\n                goto err;\n            }\n        }\n    }\n    if (!sk_OPENSSL_PSTRING_push(db->data, row)) {\n        db->error = DB_ERROR_MALLOC;\n        goto err;\n    }\n    for (i = 0; i < db->num_fields; i++) {\n        if (db->index[i] != NULL) {\n            if ((db->qual[i] != NULL) && (db->qual[i] (row) == 0))\n                continue;\n            (void)lh_OPENSSL_STRING_insert(db->index[i], row);\n        }\n    }\n    return (1);\n err:\n    return (0);\n}', 'void *OPENSSL_LH_insert(OPENSSL_LHASH *lh, void *data)\n{\n    unsigned long hash;\n    OPENSSL_LH_NODE *nn, **rn;\n    void *ret;\n    lh->error = 0;\n    if ((lh->up_load <= (lh->num_items * LH_LOAD_MULT / lh->num_nodes)) && !expand(lh))\n        return NULL;\n    rn = getrn(lh, data, &hash);\n    if (*rn == NULL) {\n        if ((nn = OPENSSL_malloc(sizeof(*nn))) == NULL) {\n            lh->error++;\n            return (NULL);\n        }\n        nn->data = data;\n        nn->next = NULL;\n        nn->hash = hash;\n        *rn = nn;\n        ret = NULL;\n        lh->num_insert++;\n        lh->num_items++;\n    } else {\n        ret = (*rn)->data;\n        (*rn)->data = data;\n        lh->num_replace++;\n    }\n    return (ret);\n}', 'static int expand(OPENSSL_LHASH *lh)\n{\n    OPENSSL_LH_NODE **n, **n1, **n2, *np;\n    unsigned int p, i, j;\n    unsigned long hash, nni;\n    lh->num_nodes++;\n    lh->num_expands++;\n    p = (int)lh->p++;\n    n1 = &(lh->b[p]);\n    n2 = &(lh->b[p + (int)lh->pmax]);\n    *n2 = NULL;\n    nni = lh->num_alloc_nodes;\n    for (np = *n1; np != NULL;) {\n        hash = np->hash;\n        if ((hash % nni) != p) {\n            *n1 = (*n1)->next;\n            np->next = *n2;\n            *n2 = np;\n        } else\n            n1 = &((*n1)->next);\n        np = *n1;\n    }\n    if ((lh->p) >= lh->pmax) {\n        j = (int)lh->num_alloc_nodes * 2;\n        n = OPENSSL_realloc(lh->b, (int)(sizeof(OPENSSL_LH_NODE *) * j));\n        if (n == NULL) {\n            lh->error++;\n            lh->p = 0;\n            return 0;\n        }\n        for (i = (int)lh->num_alloc_nodes; i < j; i++)\n            n[i] = NULL;\n        lh->pmax = lh->num_alloc_nodes;\n        lh->num_alloc_nodes = j;\n        lh->num_expand_reallocs++;\n        lh->p = 0;\n        lh->b = n;\n    }\n    return 1;\n}', 'void *CRYPTO_realloc(void *str, size_t num, const char *file, int line)\n{\n    if (realloc_impl != NULL && realloc_impl != &CRYPTO_realloc)\n        return realloc_impl(str, num, file, line);\n    if (str == NULL)\n        return CRYPTO_malloc(num, file, line);\n    if (num == 0) {\n        CRYPTO_free(str, file, line);\n        return NULL;\n    }\n    allow_customize = 0;\n#ifndef OPENSSL_NO_CRYPTO_MDEBUG\n    if (call_malloc_debug) {\n        void *ret;\n        CRYPTO_mem_debug_realloc(str, NULL, num, 0, file, line);\n        ret = realloc(str, num);\n        CRYPTO_mem_debug_realloc(str, ret, num, 1, file, line);\n        return ret;\n    }\n#else\n    osslargused(file); osslargused(line);\n#endif\n    return realloc(str, num);\n}']