static int pkey_gost_init(EVP_PKEY_CTX *ctx)
{
    struct gost_pmeth_data *data;
    EVP_PKEY *pkey = EVP_PKEY_CTX_get0_pkey(ctx);
    data = OPENSSL_zalloc(sizeof(*data));
    if (!data)
        return 0;
    if (pkey && EVP_PKEY_get0(pkey)) {
        switch (EVP_PKEY_base_id(pkey)) {
        case NID_id_GostR3410_2001:
            data->sign_param_nid =
                EC_GROUP_get_curve_name(EC_KEY_get0_group
                                        (EVP_PKEY_get0((EVP_PKEY *)pkey)));
            break;
        default:
            return 0;
        }
    }
    EVP_PKEY_CTX_set_data(ctx, data);
    return 1;
}
['static int pkey_gost_init(EVP_PKEY_CTX *ctx)\n{\n    struct gost_pmeth_data *data;\n    EVP_PKEY *pkey = EVP_PKEY_CTX_get0_pkey(ctx);\n    data = OPENSSL_zalloc(sizeof(*data));\n    if (!data)\n        return 0;\n    if (pkey && EVP_PKEY_get0(pkey)) {\n        switch (EVP_PKEY_base_id(pkey)) {\n        case NID_id_GostR3410_2001:\n            data->sign_param_nid =\n                EC_GROUP_get_curve_name(EC_KEY_get0_group\n                                        (EVP_PKEY_get0((EVP_PKEY *)pkey)));\n            break;\n        default:\n            return 0;\n        }\n    }\n    EVP_PKEY_CTX_set_data(ctx, data);\n    return 1;\n}', 'EVP_PKEY *EVP_PKEY_CTX_get0_pkey(EVP_PKEY_CTX *ctx)\n{\n    return ctx->pkey;\n}', 'void *CRYPTO_zalloc(size_t num, const char *file, int line)\n{\n    void *ret = CRYPTO_malloc(num, file, line);\n    if (ret != NULL)\n        memset(ret, 0, num);\n    return ret;\n}', 'void *CRYPTO_malloc(size_t num, const char *file, int line)\n{\n    void *ret = NULL;\n    if (num <= 0)\n        return NULL;\n    allow_customize = 0;\n#ifndef OPENSSL_NO_CRYPTO_MDEBUG\n    if (call_malloc_debug) {\n        CRYPTO_mem_debug_malloc(NULL, num, 0, file, line);\n        ret = malloc(num);\n        CRYPTO_mem_debug_malloc(ret, num, 1, file, line);\n    } else {\n        ret = malloc(num);\n    }\n#else\n    (void)file;\n    (void)line;\n    ret = malloc(num);\n#endif\n#ifndef OPENSSL_CPUID_OBJ\n    if (ret && (num > 2048)) {\n        extern unsigned char cleanse_ctr;\n        ((unsigned char *)ret)[0] = cleanse_ctr;\n    }\n#endif\n    return ret;\n}', 'void *EVP_PKEY_get0(EVP_PKEY *pkey)\n{\n    return pkey->pkey.ptr;\n}', 'int EVP_PKEY_base_id(const EVP_PKEY *pkey)\n{\n    return EVP_PKEY_type(pkey->type);\n}', 'int EVP_PKEY_type(int type)\n{\n    int ret;\n    const EVP_PKEY_ASN1_METHOD *ameth;\n    ENGINE *e;\n    ameth = EVP_PKEY_asn1_find(&e, type);\n    if (ameth)\n        ret = ameth->pkey_id;\n    else\n        ret = NID_undef;\n#ifndef OPENSSL_NO_ENGINE\n    if (e)\n        ENGINE_finish(e);\n#endif\n    return ret;\n}', 'const EVP_PKEY_ASN1_METHOD *EVP_PKEY_asn1_find(ENGINE **pe, int type)\n{\n    const EVP_PKEY_ASN1_METHOD *t;\n    for (;;) {\n        t = pkey_asn1_find(type);\n        if (!t || !(t->pkey_flags & ASN1_PKEY_ALIAS))\n            break;\n        type = t->pkey_base_id;\n    }\n    if (pe) {\n#ifndef OPENSSL_NO_ENGINE\n        ENGINE *e;\n        e = ENGINE_get_pkey_asn1_meth_engine(type);\n        if (e) {\n            *pe = e;\n            return ENGINE_get_pkey_asn1_meth(e, type);\n        }\n#endif\n        *pe = NULL;\n    }\n    return t;\n}', 'static const EVP_PKEY_ASN1_METHOD *pkey_asn1_find(int type)\n{\n    EVP_PKEY_ASN1_METHOD tmp;\n    const EVP_PKEY_ASN1_METHOD *t = &tmp, **ret;\n    tmp.pkey_id = type;\n    if (app_methods) {\n        int idx;\n        idx = sk_EVP_PKEY_ASN1_METHOD_find(app_methods, &tmp);\n        if (idx >= 0)\n            return sk_EVP_PKEY_ASN1_METHOD_value(app_methods, idx);\n    }\n    ret = OBJ_bsearch_ameth(&t, standard_methods, OSSL_NELEM(standard_methods));\n    if (!ret || !*ret)\n        return NULL;\n    return *ret;\n}', 'int sk_find(_STACK *st, void *data)\n{\n    return internal_find(st, data, OBJ_BSEARCH_FIRST_VALUE_ON_MATCH);\n}', 'static int internal_find(_STACK *st, void *data, int ret_val_options)\n{\n    const void *const *r;\n    int i;\n    if (st == NULL)\n        return -1;\n    if (st->comp == NULL) {\n        for (i = 0; i < st->num; i++)\n            if (st->data[i] == data)\n                return (i);\n        return (-1);\n    }\n    sk_sort(st);\n    if (data == NULL)\n        return (-1);\n    r = OBJ_bsearch_ex_(&data, st->data, st->num, sizeof(void *), st->comp,\n                        ret_val_options);\n    if (r == NULL)\n        return (-1);\n    return (int)((char **)r - st->data);\n}', 'void *sk_value(const _STACK *st, int i)\n{\n    if (!st || (i < 0) || (i >= st->num))\n        return NULL;\n    return st->data[i];\n}', 'ENGINE *ENGINE_get_pkey_asn1_meth_engine(int nid)\n{\n    return engine_table_select(&pkey_asn1_meth_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_w_lock(CRYPTO_LOCK_ENGINE);\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_w_unlock(CRYPTO_LOCK_ENGINE);\n    ERR_pop_to_mark();\n    return ret;\n}']