static int do_raw_keyop(int pkey_op, EVP_PKEY_CTX *ctx,
                        const EVP_MD *md, EVP_PKEY *pkey, BIO *in,
                        int filesize, unsigned char *sig, int siglen,
                        unsigned char **out, size_t *poutlen)
{
    int rv = 0;
    EVP_MD_CTX *mctx = NULL;
    unsigned char tbuf[TBUF_MAXSIZE];
    unsigned char *mbuf = NULL;
    int buf_len = 0;
    if ((mctx = EVP_MD_CTX_new()) == NULL) {
        BIO_printf(bio_err, "Error: out of memory\n");
        return rv;
    }
    EVP_MD_CTX_set_pkey_ctx(mctx, ctx);
    if (EVP_PKEY_id(pkey) == EVP_PKEY_ED25519
            || EVP_PKEY_id(pkey) == EVP_PKEY_ED448) {
        if (filesize < 0) {
            BIO_printf(bio_err,
                       "Error: unable to determine file size for oneshot operation\n");
            return rv;
        }
        mbuf = app_malloc(filesize, "oneshot sign/verify buffer");
        switch(pkey_op) {
        case EVP_PKEY_OP_VERIFY:
            if (EVP_DigestVerifyInit(mctx, NULL, md, NULL, pkey) != 1)
                goto end;
            buf_len = BIO_read(in, mbuf, filesize);
            if (buf_len != filesize) {
                BIO_printf(bio_err, "Error reading raw input data\n");
                goto end;
            }
            rv = EVP_DigestVerify(mctx, sig, (size_t)siglen, mbuf, buf_len);
            break;
        case EVP_PKEY_OP_SIGN:
            if (EVP_DigestSignInit(mctx, NULL, md, NULL, pkey) != 1)
                goto end;
            buf_len = BIO_read(in, mbuf, filesize);
            if (buf_len != filesize) {
                BIO_printf(bio_err, "Error reading raw input data\n");
                goto end;
            }
            rv = EVP_DigestSign(mctx, NULL, poutlen, mbuf, buf_len);
            if (rv == 1 && out != NULL) {
                *out = app_malloc(*poutlen, "buffer output");
                rv = EVP_DigestSign(mctx, *out, poutlen, mbuf, buf_len);
            }
            break;
        }
        OPENSSL_free(mbuf);
        goto end;
    }
    switch(pkey_op) {
    case EVP_PKEY_OP_VERIFY:
        if (EVP_DigestVerifyInit(mctx, NULL, md, NULL, pkey) != 1)
            goto end;
        for (;;) {
            buf_len = BIO_read(in, tbuf, TBUF_MAXSIZE);
            if (buf_len == 0)
                break;
            if (buf_len < 0) {
                BIO_printf(bio_err, "Error reading raw input data\n");
                goto end;
            }
            rv = EVP_DigestVerifyUpdate(mctx, tbuf, (size_t)buf_len);
            if (rv != 1) {
                BIO_printf(bio_err, "Error verifying raw input data\n");
                goto end;
            }
        }
        rv = EVP_DigestVerifyFinal(mctx, sig, (size_t)siglen);
        break;
    case EVP_PKEY_OP_SIGN:
        if (EVP_DigestSignInit(mctx, NULL, md, NULL, pkey) != 1)
            goto end;
        for (;;) {
            buf_len = BIO_read(in, tbuf, TBUF_MAXSIZE);
            if (buf_len == 0)
                break;
            if (buf_len < 0) {
                BIO_printf(bio_err, "Error reading raw input data\n");
                goto end;
            }
            rv = EVP_DigestSignUpdate(mctx, tbuf, (size_t)buf_len);
            if (rv != 1) {
                BIO_printf(bio_err, "Error signing raw input data\n");
                goto end;
            }
        }
        rv = EVP_DigestSignFinal(mctx, NULL, poutlen);
        if (rv == 1 && out != NULL) {
            *out = app_malloc(*poutlen, "buffer output");
            rv = EVP_DigestSignFinal(mctx, *out, poutlen);
        }
        break;
    }
 end:
    EVP_MD_CTX_free(mctx);
    return rv;
}
['static int do_raw_keyop(int pkey_op, EVP_PKEY_CTX *ctx,\n                        const EVP_MD *md, EVP_PKEY *pkey, BIO *in,\n                        int filesize, unsigned char *sig, int siglen,\n                        unsigned char **out, size_t *poutlen)\n{\n    int rv = 0;\n    EVP_MD_CTX *mctx = NULL;\n    unsigned char tbuf[TBUF_MAXSIZE];\n    unsigned char *mbuf = NULL;\n    int buf_len = 0;\n    if ((mctx = EVP_MD_CTX_new()) == NULL) {\n        BIO_printf(bio_err, "Error: out of memory\\n");\n        return rv;\n    }\n    EVP_MD_CTX_set_pkey_ctx(mctx, ctx);\n    if (EVP_PKEY_id(pkey) == EVP_PKEY_ED25519\n            || EVP_PKEY_id(pkey) == EVP_PKEY_ED448) {\n        if (filesize < 0) {\n            BIO_printf(bio_err,\n                       "Error: unable to determine file size for oneshot operation\\n");\n            return rv;\n        }\n        mbuf = app_malloc(filesize, "oneshot sign/verify buffer");\n        switch(pkey_op) {\n        case EVP_PKEY_OP_VERIFY:\n            if (EVP_DigestVerifyInit(mctx, NULL, md, NULL, pkey) != 1)\n                goto end;\n            buf_len = BIO_read(in, mbuf, filesize);\n            if (buf_len != filesize) {\n                BIO_printf(bio_err, "Error reading raw input data\\n");\n                goto end;\n            }\n            rv = EVP_DigestVerify(mctx, sig, (size_t)siglen, mbuf, buf_len);\n            break;\n        case EVP_PKEY_OP_SIGN:\n            if (EVP_DigestSignInit(mctx, NULL, md, NULL, pkey) != 1)\n                goto end;\n            buf_len = BIO_read(in, mbuf, filesize);\n            if (buf_len != filesize) {\n                BIO_printf(bio_err, "Error reading raw input data\\n");\n                goto end;\n            }\n            rv = EVP_DigestSign(mctx, NULL, poutlen, mbuf, buf_len);\n            if (rv == 1 && out != NULL) {\n                *out = app_malloc(*poutlen, "buffer output");\n                rv = EVP_DigestSign(mctx, *out, poutlen, mbuf, buf_len);\n            }\n            break;\n        }\n        OPENSSL_free(mbuf);\n        goto end;\n    }\n    switch(pkey_op) {\n    case EVP_PKEY_OP_VERIFY:\n        if (EVP_DigestVerifyInit(mctx, NULL, md, NULL, pkey) != 1)\n            goto end;\n        for (;;) {\n            buf_len = BIO_read(in, tbuf, TBUF_MAXSIZE);\n            if (buf_len == 0)\n                break;\n            if (buf_len < 0) {\n                BIO_printf(bio_err, "Error reading raw input data\\n");\n                goto end;\n            }\n            rv = EVP_DigestVerifyUpdate(mctx, tbuf, (size_t)buf_len);\n            if (rv != 1) {\n                BIO_printf(bio_err, "Error verifying raw input data\\n");\n                goto end;\n            }\n        }\n        rv = EVP_DigestVerifyFinal(mctx, sig, (size_t)siglen);\n        break;\n    case EVP_PKEY_OP_SIGN:\n        if (EVP_DigestSignInit(mctx, NULL, md, NULL, pkey) != 1)\n            goto end;\n        for (;;) {\n            buf_len = BIO_read(in, tbuf, TBUF_MAXSIZE);\n            if (buf_len == 0)\n                break;\n            if (buf_len < 0) {\n                BIO_printf(bio_err, "Error reading raw input data\\n");\n                goto end;\n            }\n            rv = EVP_DigestSignUpdate(mctx, tbuf, (size_t)buf_len);\n            if (rv != 1) {\n                BIO_printf(bio_err, "Error signing raw input data\\n");\n                goto end;\n            }\n        }\n        rv = EVP_DigestSignFinal(mctx, NULL, poutlen);\n        if (rv == 1 && out != NULL) {\n            *out = app_malloc(*poutlen, "buffer output");\n            rv = EVP_DigestSignFinal(mctx, *out, poutlen);\n        }\n        break;\n    }\n end:\n    EVP_MD_CTX_free(mctx);\n    return rv;\n}', 'EVP_MD_CTX *EVP_MD_CTX_new(void)\n{\n    return OPENSSL_zalloc(sizeof(EVP_MD_CTX));\n}', 'void *CRYPTO_zalloc(size_t num, const char *file, int line)\n{\n    void *ret = CRYPTO_malloc(num, file, line);\n    FAILTEST();\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    INCREMENT(malloc_count);\n    if (malloc_impl != NULL && malloc_impl != CRYPTO_malloc)\n        return malloc_impl(num, file, line);\n    if (num == 0)\n        return NULL;\n    FAILTEST();\n    if (allow_customize) {\n        allow_customize = 0;\n    }\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); (void)(line);\n    ret = malloc(num);\n#endif\n    return ret;\n}', 'void EVP_MD_CTX_set_pkey_ctx(EVP_MD_CTX *ctx, EVP_PKEY_CTX *pctx)\n{\n    if (!EVP_MD_CTX_test_flags(ctx, EVP_MD_CTX_FLAG_KEEP_PKEY_CTX))\n        EVP_PKEY_CTX_free(ctx->pctx);\n    ctx->pctx = pctx;\n    if (pctx != NULL) {\n        EVP_MD_CTX_set_flags(ctx, EVP_MD_CTX_FLAG_KEEP_PKEY_CTX);\n    } else {\n        EVP_MD_CTX_clear_flags(ctx, EVP_MD_CTX_FLAG_KEEP_PKEY_CTX);\n    }\n}', 'int EVP_MD_CTX_test_flags(const EVP_MD_CTX *ctx, int flags)\n{\n    return (ctx->flags & flags);\n}', 'void EVP_MD_CTX_set_flags(EVP_MD_CTX *ctx, int flags)\n{\n    ctx->flags |= flags;\n}', 'int EVP_PKEY_id(const EVP_PKEY *pkey)\n{\n    return pkey->type;\n}']