static int eckey_param2type(int *pptype, void **ppval, EC_KEY *ec_key)
{
    const EC_GROUP *group;
    int nid;
    if (ec_key == NULL || (group = EC_KEY_get0_group(ec_key)) == NULL) {
        ECerr(EC_F_ECKEY_PARAM2TYPE, EC_R_MISSING_PARAMETERS);
        return 0;
    }
    if (EC_GROUP_get_asn1_flag(group)
        && (nid = EC_GROUP_get_curve_name(group)))
    {
        *ppval = OBJ_nid2obj(nid);
        *pptype = V_ASN1_OBJECT;
    } else {
        ASN1_STRING *pstr = NULL;
        pstr = ASN1_STRING_new();
        if (pstr == NULL)
            return 0;
        pstr->length = i2d_ECParameters(ec_key, &pstr->data);
        if (pstr->length <= 0) {
            ASN1_STRING_free(pstr);
            ECerr(EC_F_ECKEY_PARAM2TYPE, ERR_R_EC_LIB);
            return 0;
        }
        *ppval = pstr;
        *pptype = V_ASN1_SEQUENCE;
    }
    return 1;
}
['static int eckey_param2type(int *pptype, void **ppval, EC_KEY *ec_key)\n{\n    const EC_GROUP *group;\n    int nid;\n    if (ec_key == NULL || (group = EC_KEY_get0_group(ec_key)) == NULL) {\n        ECerr(EC_F_ECKEY_PARAM2TYPE, EC_R_MISSING_PARAMETERS);\n        return 0;\n    }\n    if (EC_GROUP_get_asn1_flag(group)\n        && (nid = EC_GROUP_get_curve_name(group)))\n    {\n        *ppval = OBJ_nid2obj(nid);\n        *pptype = V_ASN1_OBJECT;\n    } else {\n        ASN1_STRING *pstr = NULL;\n        pstr = ASN1_STRING_new();\n        if (pstr == NULL)\n            return 0;\n        pstr->length = i2d_ECParameters(ec_key, &pstr->data);\n        if (pstr->length <= 0) {\n            ASN1_STRING_free(pstr);\n            ECerr(EC_F_ECKEY_PARAM2TYPE, ERR_R_EC_LIB);\n            return 0;\n        }\n        *ppval = pstr;\n        *pptype = V_ASN1_SEQUENCE;\n    }\n    return 1;\n}', 'const EC_GROUP *EC_KEY_get0_group(const EC_KEY *key)\n{\n    return key->group;\n}', 'int EC_GROUP_get_asn1_flag(const EC_GROUP *group)\n{\n    return group->asn1_flag;\n}', 'ASN1_STRING *ASN1_STRING_new(void)\n{\n    return (ASN1_STRING_type_new(V_ASN1_OCTET_STRING));\n}', 'ASN1_STRING *ASN1_STRING_type_new(int type)\n{\n    ASN1_STRING *ret;\n    ret = OPENSSL_zalloc(sizeof(*ret));\n    if (ret == NULL) {\n        ASN1err(ASN1_F_ASN1_STRING_TYPE_NEW, ERR_R_MALLOC_FAILURE);\n        return (NULL);\n    }\n    ret->type = type;\n    return (ret);\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}', 'int i2d_ECParameters(EC_KEY *a, unsigned char **out)\n{\n    if (a == NULL) {\n        ECerr(EC_F_I2D_ECPARAMETERS, ERR_R_PASSED_NULL_PARAMETER);\n        return 0;\n    }\n    return i2d_ECPKParameters(a->group, out);\n}', 'int i2d_ECPKParameters(const EC_GROUP *a, unsigned char **out)\n{\n    int ret = 0;\n    ECPKPARAMETERS *tmp = ec_asn1_group2pkparameters(a, NULL);\n    if (tmp == NULL) {\n        ECerr(EC_F_I2D_ECPKPARAMETERS, EC_R_GROUP2PKPARAMETERS_FAILURE);\n        return 0;\n    }\n    if ((ret = i2d_ECPKPARAMETERS(tmp, out)) == 0) {\n        ECerr(EC_F_I2D_ECPKPARAMETERS, EC_R_I2D_ECPKPARAMETERS_FAILURE);\n        ECPKPARAMETERS_free(tmp);\n        return 0;\n    }\n    ECPKPARAMETERS_free(tmp);\n    return (ret);\n}', 'IMPLEMENT_ASN1_FUNCTIONS_const(ECPKPARAMETERS)', 'int ASN1_item_i2d(ASN1_VALUE *val, unsigned char **out, const ASN1_ITEM *it)\n{\n    return asn1_item_flags_i2d(val, out, it, 0);\n}', 'static int asn1_item_flags_i2d(ASN1_VALUE *val, unsigned char **out,\n                               const ASN1_ITEM *it, int flags)\n{\n    if (out && !*out) {\n        unsigned char *p, *buf;\n        int len;\n        len = ASN1_item_ex_i2d(&val, NULL, it, -1, flags);\n        if (len <= 0)\n            return len;\n        buf = OPENSSL_malloc(len);\n        if (buf == NULL)\n            return -1;\n        p = buf;\n        ASN1_item_ex_i2d(&val, &p, it, -1, flags);\n        *out = buf;\n        return len;\n    }\n    return ASN1_item_ex_i2d(&val, out, it, -1, flags);\n}', 'void ASN1_item_free(ASN1_VALUE *val, const ASN1_ITEM *it)\n{\n    asn1_item_embed_free(&val, it, 0);\n}', 'void ASN1_STRING_free(ASN1_STRING *a)\n{\n    if (a == NULL)\n        return;\n    if (!(a->flags & ASN1_STRING_FLAG_NDEF))\n        OPENSSL_free(a->data);\n    if (!(a->flags & ASN1_STRING_FLAG_EMBED))\n        OPENSSL_free(a);\n}']