static int gf2m_Mxy(const EC_GROUP *group, const BIGNUM *x, const BIGNUM *y,
                    BIGNUM *x1, BIGNUM *z1, BIGNUM *x2, BIGNUM *z2,
                    BN_CTX *ctx)
{
    BIGNUM *t3, *t4, *t5;
    int ret = 0;
    if (BN_is_zero(z1)) {
        BN_zero(x2);
        BN_zero(z2);
        return 1;
    }
    if (BN_is_zero(z2)) {
        if (!BN_copy(x2, x))
            return 0;
        if (!BN_GF2m_add(z2, x, y))
            return 0;
        return 2;
    }
    BN_CTX_start(ctx);
    t3 = BN_CTX_get(ctx);
    t4 = BN_CTX_get(ctx);
    t5 = BN_CTX_get(ctx);
    if (t5 == NULL)
        goto err;
    if (!BN_one(t5))
        goto err;
    if (!group->meth->field_mul(group, t3, z1, z2, ctx))
        goto err;
    if (!group->meth->field_mul(group, z1, z1, x, ctx))
        goto err;
    if (!BN_GF2m_add(z1, z1, x1))
        goto err;
    if (!group->meth->field_mul(group, z2, z2, x, ctx))
        goto err;
    if (!group->meth->field_mul(group, x1, z2, x1, ctx))
        goto err;
    if (!BN_GF2m_add(z2, z2, x2))
        goto err;
    if (!group->meth->field_mul(group, z2, z2, z1, ctx))
        goto err;
    if (!group->meth->field_sqr(group, t4, x, ctx))
        goto err;
    if (!BN_GF2m_add(t4, t4, y))
        goto err;
    if (!group->meth->field_mul(group, t4, t4, t3, ctx))
        goto err;
    if (!BN_GF2m_add(t4, t4, z2))
        goto err;
    if (!group->meth->field_mul(group, t3, t3, x, ctx))
        goto err;
    if (!group->meth->field_div(group, t3, t5, t3, ctx))
        goto err;
    if (!group->meth->field_mul(group, t4, t3, t4, ctx))
        goto err;
    if (!group->meth->field_mul(group, x2, x1, t3, ctx))
        goto err;
    if (!BN_GF2m_add(z2, x2, x))
        goto err;
    if (!group->meth->field_mul(group, z2, z2, t4, ctx))
        goto err;
    if (!BN_GF2m_add(z2, z2, y))
        goto err;
    ret = 2;
 err:
    BN_CTX_end(ctx);
    return ret;
}
['static int gf2m_Mxy(const EC_GROUP *group, const BIGNUM *x, const BIGNUM *y,\n                    BIGNUM *x1, BIGNUM *z1, BIGNUM *x2, BIGNUM *z2,\n                    BN_CTX *ctx)\n{\n    BIGNUM *t3, *t4, *t5;\n    int ret = 0;\n    if (BN_is_zero(z1)) {\n        BN_zero(x2);\n        BN_zero(z2);\n        return 1;\n    }\n    if (BN_is_zero(z2)) {\n        if (!BN_copy(x2, x))\n            return 0;\n        if (!BN_GF2m_add(z2, x, y))\n            return 0;\n        return 2;\n    }\n    BN_CTX_start(ctx);\n    t3 = BN_CTX_get(ctx);\n    t4 = BN_CTX_get(ctx);\n    t5 = BN_CTX_get(ctx);\n    if (t5 == NULL)\n        goto err;\n    if (!BN_one(t5))\n        goto err;\n    if (!group->meth->field_mul(group, t3, z1, z2, ctx))\n        goto err;\n    if (!group->meth->field_mul(group, z1, z1, x, ctx))\n        goto err;\n    if (!BN_GF2m_add(z1, z1, x1))\n        goto err;\n    if (!group->meth->field_mul(group, z2, z2, x, ctx))\n        goto err;\n    if (!group->meth->field_mul(group, x1, z2, x1, ctx))\n        goto err;\n    if (!BN_GF2m_add(z2, z2, x2))\n        goto err;\n    if (!group->meth->field_mul(group, z2, z2, z1, ctx))\n        goto err;\n    if (!group->meth->field_sqr(group, t4, x, ctx))\n        goto err;\n    if (!BN_GF2m_add(t4, t4, y))\n        goto err;\n    if (!group->meth->field_mul(group, t4, t4, t3, ctx))\n        goto err;\n    if (!BN_GF2m_add(t4, t4, z2))\n        goto err;\n    if (!group->meth->field_mul(group, t3, t3, x, ctx))\n        goto err;\n    if (!group->meth->field_div(group, t3, t5, t3, ctx))\n        goto err;\n    if (!group->meth->field_mul(group, t4, t3, t4, ctx))\n        goto err;\n    if (!group->meth->field_mul(group, x2, x1, t3, ctx))\n        goto err;\n    if (!BN_GF2m_add(z2, x2, x))\n        goto err;\n    if (!group->meth->field_mul(group, z2, z2, t4, ctx))\n        goto err;\n    if (!BN_GF2m_add(z2, z2, y))\n        goto err;\n    ret = 2;\n err:\n    BN_CTX_end(ctx);\n    return ret;\n}', 'int BN_is_zero(const BIGNUM *a)\n{\n    return a->top == 0;\n}', 'void BN_CTX_start(BN_CTX *ctx)\n{\n    CTXDBG_ENTRY("BN_CTX_start", ctx);\n    if (ctx->err_stack || ctx->too_many)\n        ctx->err_stack++;\n    else if (!BN_STACK_push(&ctx->stack, ctx->used)) {\n        BNerr(BN_F_BN_CTX_START, BN_R_TOO_MANY_TEMPORARY_VARIABLES);\n        ctx->err_stack++;\n    }\n    CTXDBG_EXIT(ctx);\n}', 'static int BN_STACK_push(BN_STACK *st, unsigned int idx)\n{\n    if (st->depth == st->size) {\n        unsigned int newsize =\n            st->size ? (st->size * 3 / 2) : BN_CTX_START_FRAMES;\n        unsigned int *newitems = OPENSSL_malloc(sizeof(*newitems) * newsize);\n        if (newitems == NULL)\n            return 0;\n        if (st->depth)\n            memcpy(newitems, st->indexes, sizeof(*newitems) * st->depth);\n        OPENSSL_free(st->indexes);\n        st->indexes = newitems;\n        st->size = newsize;\n    }\n    st->indexes[(st->depth)++] = idx;\n    return 1;\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 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}', 'BIGNUM *BN_CTX_get(BN_CTX *ctx)\n{\n    BIGNUM *ret;\n    CTXDBG_ENTRY("BN_CTX_get", ctx);\n    if (ctx->err_stack || ctx->too_many)\n        return NULL;\n    if ((ret = BN_POOL_get(&ctx->pool, ctx->flags)) == NULL) {\n        ctx->too_many = 1;\n        BNerr(BN_F_BN_CTX_GET, BN_R_TOO_MANY_TEMPORARY_VARIABLES);\n        return NULL;\n    }\n    BN_zero(ret);\n    ctx->used++;\n    CTXDBG_RET(ctx, ret);\n    return ret;\n}', 'int BN_set_word(BIGNUM *a, BN_ULONG w)\n{\n    bn_check_top(a);\n    if (bn_expand(a, (int)sizeof(BN_ULONG) * 8) == NULL)\n        return (0);\n    a->neg = 0;\n    a->d[0] = w;\n    a->top = (w ? 1 : 0);\n    bn_check_top(a);\n    return (1);\n}']