int ossl_ec_key_gen(EC_KEY *eckey)
{
    int ok = 0;
    BN_CTX *ctx = NULL;
    BIGNUM *priv_key = NULL, *order = NULL;
    EC_POINT *pub_key = NULL;
    if ((order = BN_new()) == NULL)
        goto err;
    if ((ctx = BN_CTX_new()) == NULL)
        goto err;
    if (eckey->priv_key == NULL) {
        priv_key = BN_new();
        if (priv_key == NULL)
            goto err;
    } else
        priv_key = eckey->priv_key;
    if (!EC_GROUP_get_order(eckey->group, order, ctx))
        goto err;
    do
        if (!BN_rand_range(priv_key, order))
            goto err;
    while (BN_is_zero(priv_key)) ;
    if (eckey->pub_key == NULL) {
        pub_key = EC_POINT_new(eckey->group);
        if (pub_key == NULL)
            goto err;
    } else
        pub_key = eckey->pub_key;
    if (!EC_POINT_mul(eckey->group, pub_key, priv_key, NULL, NULL, ctx))
        goto err;
    eckey->priv_key = priv_key;
    eckey->pub_key = pub_key;
    ok = 1;
 err:
    BN_free(order);
    if (eckey->pub_key == NULL)
        EC_POINT_free(pub_key);
    if (eckey->priv_key != priv_key)
        BN_free(priv_key);
    BN_CTX_free(ctx);
    return (ok);
}
['int ossl_ec_key_gen(EC_KEY *eckey)\n{\n    int ok = 0;\n    BN_CTX *ctx = NULL;\n    BIGNUM *priv_key = NULL, *order = NULL;\n    EC_POINT *pub_key = NULL;\n    if ((order = BN_new()) == NULL)\n        goto err;\n    if ((ctx = BN_CTX_new()) == NULL)\n        goto err;\n    if (eckey->priv_key == NULL) {\n        priv_key = BN_new();\n        if (priv_key == NULL)\n            goto err;\n    } else\n        priv_key = eckey->priv_key;\n    if (!EC_GROUP_get_order(eckey->group, order, ctx))\n        goto err;\n    do\n        if (!BN_rand_range(priv_key, order))\n            goto err;\n    while (BN_is_zero(priv_key)) ;\n    if (eckey->pub_key == NULL) {\n        pub_key = EC_POINT_new(eckey->group);\n        if (pub_key == NULL)\n            goto err;\n    } else\n        pub_key = eckey->pub_key;\n    if (!EC_POINT_mul(eckey->group, pub_key, priv_key, NULL, NULL, ctx))\n        goto err;\n    eckey->priv_key = priv_key;\n    eckey->pub_key = pub_key;\n    ok = 1;\n err:\n    BN_free(order);\n    if (eckey->pub_key == NULL)\n        EC_POINT_free(pub_key);\n    if (eckey->priv_key != priv_key)\n        BN_free(priv_key);\n    BN_CTX_free(ctx);\n    return (ok);\n}', 'BIGNUM *BN_new(void)\n{\n    BIGNUM *ret;\n    if ((ret = OPENSSL_zalloc(sizeof(*ret))) == NULL) {\n        BNerr(BN_F_BN_NEW, ERR_R_MALLOC_FAILURE);\n        return (NULL);\n    }\n    ret->flags = BN_FLG_MALLOCED;\n    bn_check_top(ret);\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}', 'BN_CTX *BN_CTX_new(void)\n{\n    BN_CTX *ret;\n    if ((ret = OPENSSL_zalloc(sizeof(*ret))) == NULL) {\n        BNerr(BN_F_BN_CTX_NEW, ERR_R_MALLOC_FAILURE);\n        return NULL;\n    }\n    BN_POOL_init(&ret->pool);\n    BN_STACK_init(&ret->stack);\n    return ret;\n}', 'static void BN_POOL_init(BN_POOL *p)\n{\n    p->head = p->current = p->tail = NULL;\n    p->used = p->size = 0;\n}', 'static void BN_STACK_init(BN_STACK *st)\n{\n    st->indexes = NULL;\n    st->depth = st->size = 0;\n}', 'int EC_GROUP_get_order(const EC_GROUP *group, BIGNUM *order, BN_CTX *ctx)\n{\n    if (!BN_copy(order, group->order))\n        return 0;\n    return !BN_is_zero(order);\n}', 'int BN_is_zero(const BIGNUM *a)\n{\n    return a->top == 0;\n}', 'int BN_rand_range(BIGNUM *r, const BIGNUM *range)\n{\n    return bn_rand_range(0, r, range);\n}', 'EC_POINT *EC_POINT_new(const EC_GROUP *group)\n{\n    EC_POINT *ret;\n    if (group == NULL) {\n        ECerr(EC_F_EC_POINT_NEW, ERR_R_PASSED_NULL_PARAMETER);\n        return NULL;\n    }\n    if (group->meth->point_init == 0) {\n        ECerr(EC_F_EC_POINT_NEW, ERR_R_SHOULD_NOT_HAVE_BEEN_CALLED);\n        return NULL;\n    }\n    ret = OPENSSL_malloc(sizeof(*ret));\n    if (ret == NULL) {\n        ECerr(EC_F_EC_POINT_NEW, ERR_R_MALLOC_FAILURE);\n        return NULL;\n    }\n    ret->meth = group->meth;\n    if (!ret->meth->point_init(ret)) {\n        OPENSSL_free(ret);\n        return NULL;\n    }\n    return ret;\n}', 'void CRYPTO_free(void *str)\n{\n#ifndef OPENSSL_NO_CRYPTO_MDEBUG\n    if (call_malloc_debug) {\n        CRYPTO_mem_debug_free(str, 0);\n        free(str);\n        CRYPTO_mem_debug_free(str, 1);\n    } else {\n        free(str);\n    }\n#else\n    free(str);\n#endif\n}', 'void BN_free(BIGNUM *a)\n{\n    if (a == NULL)\n        return;\n    bn_check_top(a);\n    if (!BN_get_flags(a, BN_FLG_STATIC_DATA))\n        bn_free_d(a);\n    if (a->flags & BN_FLG_MALLOCED)\n        OPENSSL_free(a);\n    else {\n#if OPENSSL_API_COMPAT < 0x00908000L\n        a->flags |= BN_FLG_FREE;\n#endif\n        a->d = NULL;\n    }\n}', 'int BN_get_flags(const BIGNUM *b, int n)\n{\n    return b->flags & n;\n}']