apps/pkeyutl.c:383: error: INTEGER_OVERFLOW_L2
  ([0, +oo] - 1):unsigned64.
Showing all 6 steps of the trace


apps/pkeyutl.c:372:21: <LHS trace>
370.       if (in != NULL && !rawin) {
371.           /* Read the input data */
372.           buf_inlen = bio_to_mem(&buf_in, keysize * 10, in);
                           ^
373.           if (buf_inlen < 0) {
374.               BIO_printf(bio_err, "Error reading input Data\n");

apps/pkeyutl.c:372:21: Call
370.       if (in != NULL && !rawin) {
371.           /* Read the input data */
372.           buf_inlen = bio_to_mem(&buf_in, keysize * 10, in);
                           ^
373.           if (buf_inlen < 0) {
374.               BIO_printf(bio_err, "Error reading input Data\n");

apps/apps.c:1698:9: Assignment
  1696.       mem = BIO_new(BIO_s_mem());
  1697.       if (mem == NULL)
  1698.           return -1;
                  ^
  1699.       for (;;) {
  1700.           if ((maxlen != -1) && maxlen < 1024)

apps/pkeyutl.c:372:9: Assignment
370.       if (in != NULL && !rawin) {
371.           /* Read the input data */
372.           buf_inlen = bio_to_mem(&buf_in, keysize * 10, in);
               ^
373.           if (buf_inlen < 0) {
374.               BIO_printf(bio_err, "Error reading input Data\n");

apps/pkeyutl.c:380:13: Assignment
378.               size_t i;
379.               unsigned char ctmp;
380.               size_t l = (size_t)buf_inlen;
                   ^
381.               for (i = 0; i < l / 2; i++) {
382.                   ctmp = buf_in[i];

apps/pkeyutl.c:383:29: Binary operation: ([0, +oo] - 1):unsigned64
381.               for (i = 0; i < l / 2; i++) {
382.                   ctmp = buf_in[i];
383.                   buf_in[i] = buf_in[l - 1 - i];
                                   ^
384.                   buf_in[l - 1 - i] = ctmp;
385.               }

int pkeyutl_main(int argc, char **argv)
{
    BIO *in = NULL, *out = NULL;
    ENGINE *e = NULL;
    EVP_PKEY_CTX *ctx = NULL;
    EVP_PKEY *pkey = NULL;
    char *infile = NULL, *outfile = NULL, *sigfile = NULL, *passinarg = NULL;
    char hexdump = 0, asn1parse = 0, rev = 0, *prog;
    unsigned char *buf_in = NULL, *buf_out = NULL, *sig = NULL;
    OPTION_CHOICE o;
    int buf_inlen = 0, siglen = -1, keyform = FORMAT_PEM, peerform = FORMAT_PEM;
    int keysize = -1, pkey_op = EVP_PKEY_OP_SIGN, key_type = KEY_PRIVKEY;
    int engine_impl = 0;
    int ret = 1, rv = -1;
    size_t buf_outlen;
    const char *inkey = NULL;
    const char *peerkey = NULL;
    const char *kdfalg = NULL;
    int kdflen = 0;
    STACK_OF(OPENSSL_STRING) *pkeyopts = NULL;
    STACK_OF(OPENSSL_STRING) *pkeyopts_passin = NULL;
    int rawin = 0;
    const EVP_MD *md = NULL;
    prog = opt_init(argc, argv, pkeyutl_options);
    while ((o = opt_next()) != OPT_EOF) {
        switch (o) {
        case OPT_EOF:
        case OPT_ERR:
 opthelp:
            BIO_printf(bio_err, "%s: Use -help for summary.\n", prog);
            goto end;
        case OPT_HELP:
            opt_help(pkeyutl_options);
            ret = 0;
            goto end;
        case OPT_IN:
            infile = opt_arg();
            break;
        case OPT_OUT:
            outfile = opt_arg();
            break;
        case OPT_SIGFILE:
            sigfile = opt_arg();
            break;
        case OPT_ENGINE_IMPL:
            engine_impl = 1;
            break;
        case OPT_INKEY:
            inkey = opt_arg();
            break;
        case OPT_PEERKEY:
            peerkey = opt_arg();
            break;
        case OPT_PASSIN:
            passinarg = opt_arg();
            break;
        case OPT_PEERFORM:
            if (!opt_format(opt_arg(), OPT_FMT_PDE, &peerform))
                goto opthelp;
            break;
        case OPT_KEYFORM:
            if (!opt_format(opt_arg(), OPT_FMT_PDE, &keyform))
                goto opthelp;
            break;
        case OPT_R_CASES:
            if (!opt_rand(o))
                goto end;
            break;
        case OPT_ENGINE:
            e = setup_engine(opt_arg(), 0);
            break;
        case OPT_PUBIN:
            key_type = KEY_PUBKEY;
            break;
        case OPT_CERTIN:
            key_type = KEY_CERT;
            break;
        case OPT_ASN1PARSE:
            asn1parse = 1;
            break;
        case OPT_HEXDUMP:
            hexdump = 1;
            break;
        case OPT_SIGN:
            pkey_op = EVP_PKEY_OP_SIGN;
            break;
        case OPT_VERIFY:
            pkey_op = EVP_PKEY_OP_VERIFY;
            break;
        case OPT_VERIFYRECOVER:
            pkey_op = EVP_PKEY_OP_VERIFYRECOVER;
            break;
        case OPT_ENCRYPT:
            pkey_op = EVP_PKEY_OP_ENCRYPT;
            break;
        case OPT_DECRYPT:
            pkey_op = EVP_PKEY_OP_DECRYPT;
            break;
        case OPT_DERIVE:
            pkey_op = EVP_PKEY_OP_DERIVE;
            break;
        case OPT_KDF:
            pkey_op = EVP_PKEY_OP_DERIVE;
            key_type = KEY_NONE;
            kdfalg = opt_arg();
            break;
        case OPT_KDFLEN:
            kdflen = atoi(opt_arg());
            break;
        case OPT_REV:
            rev = 1;
            break;
        case OPT_PKEYOPT:
            if ((pkeyopts == NULL &&
                 (pkeyopts = sk_OPENSSL_STRING_new_null()) == NULL) ||
                sk_OPENSSL_STRING_push(pkeyopts, opt_arg()) == 0) {
                BIO_puts(bio_err, "out of memory\n");
                goto end;
            }
            break;
        case OPT_PKEYOPT_PASSIN:
            if ((pkeyopts_passin == NULL &&
                 (pkeyopts_passin = sk_OPENSSL_STRING_new_null()) == NULL) ||
                sk_OPENSSL_STRING_push(pkeyopts_passin, opt_arg()) == 0) {
                BIO_puts(bio_err, "out of memory\n");
                goto end;
            }
            break;
        case OPT_RAWIN:
            rawin = 1;
            break;
        case OPT_DIGEST:
            if (!opt_md(opt_arg(), &md))
                goto end;
            break;
        }
    }
    argc = opt_num_rest();
    if (argc != 0)
        goto opthelp;
    if (rawin && pkey_op != EVP_PKEY_OP_SIGN && pkey_op != EVP_PKEY_OP_VERIFY) {
        BIO_printf(bio_err,
                   "%s: -rawin can only be used with -sign or -verify\n",
                   prog);
        goto opthelp;
    }
    if (md != NULL && !rawin) {
        BIO_printf(bio_err,
                   "%s: -digest can only be used with -rawin\n",
                   prog);
        goto opthelp;
    }
    if (rawin && rev) {
        BIO_printf(bio_err, "%s: -rev cannot be used with raw input\n",
                   prog);
        goto opthelp;
    }
    if (kdfalg != NULL) {
        if (kdflen == 0) {
            BIO_printf(bio_err,
                       "%s: no KDF length given (-kdflen parameter).\n", prog);
            goto opthelp;
        }
    } else if (inkey == NULL) {
        BIO_printf(bio_err,
                   "%s: no private key given (-inkey parameter).\n", prog);
        goto opthelp;
    } else if (peerkey != NULL && pkey_op != EVP_PKEY_OP_DERIVE) {
        BIO_printf(bio_err,
                   "%s: no peer key given (-peerkey parameter).\n", prog);
        goto opthelp;
    }
    ctx = init_ctx(kdfalg, &keysize, inkey, keyform, key_type,
                   passinarg, pkey_op, e, engine_impl, &pkey);
    if (ctx == NULL) {
        BIO_printf(bio_err, "%s: Error initializing context\n", prog);
        ERR_print_errors(bio_err);
        goto end;
    }
    if (peerkey != NULL && !setup_peer(ctx, peerform, peerkey, e)) {
        BIO_printf(bio_err, "%s: Error setting up peer key\n", prog);
        ERR_print_errors(bio_err);
        goto end;
    }
    if (pkeyopts != NULL) {
        int num = sk_OPENSSL_STRING_num(pkeyopts);
        int i;
        for (i = 0; i < num; ++i) {
            const char *opt = sk_OPENSSL_STRING_value(pkeyopts, i);
            if (pkey_ctrl_string(ctx, opt) <= 0) {
                BIO_printf(bio_err, "%s: Can't set parameter \"%s\":\n",
                           prog, opt);
                ERR_print_errors(bio_err);
                goto end;
            }
        }
    }
    if (pkeyopts_passin != NULL) {
        int num = sk_OPENSSL_STRING_num(pkeyopts_passin);
        int i;
        for (i = 0; i < num; i++) {
            char *opt = sk_OPENSSL_STRING_value(pkeyopts_passin, i);
            char *passin = strchr(opt, ':');
            char *passwd;
            if (passin == NULL) {
                char passwd_buf[4096];
                BIO_snprintf(passwd_buf, sizeof(passwd_buf), "Enter %s: ", opt);
                EVP_read_pw_string(passwd_buf, sizeof(passwd_buf) - 1,
                                   passwd_buf, 0);
                passwd = OPENSSL_strdup(passwd_buf);
                if (passwd == NULL) {
                    BIO_puts(bio_err, "out of memory\n");
                    goto end;
                }
            } else {
                *passin = 0;
                passin++;
                if (app_passwd(passin, NULL, &passwd, NULL) == 0) {
                    BIO_printf(bio_err, "failed to get '%s'\n", opt);
                    goto end;
                }
            }
            if (EVP_PKEY_CTX_ctrl_str(ctx, opt, passwd) <= 0) {
                BIO_printf(bio_err, "%s: Can't set parameter \"%s\":\n",
                           prog, opt);
                goto end;
            }
            OPENSSL_free(passwd);
        }
    }
    if (sigfile != NULL && (pkey_op != EVP_PKEY_OP_VERIFY)) {
        BIO_printf(bio_err,
                   "%s: Signature file specified for non verify\n", prog);
        goto end;
    }
    if (sigfile == NULL && (pkey_op == EVP_PKEY_OP_VERIFY)) {
        BIO_printf(bio_err,
                   "%s: No signature file specified for verify\n", prog);
        goto end;
    }
    if (pkey_op != EVP_PKEY_OP_DERIVE) {
        in = bio_open_default(infile, 'r', FORMAT_BINARY);
        if (in == NULL)
            goto end;
    }
    out = bio_open_default(outfile, 'w', FORMAT_BINARY);
    if (out == NULL)
        goto end;
    if (sigfile != NULL) {
        BIO *sigbio = BIO_new_file(sigfile, "rb");
        if (sigbio == NULL) {
            BIO_printf(bio_err, "Can't open signature file %s\n", sigfile);
            goto end;
        }
        siglen = bio_to_mem(&sig, keysize * 10, sigbio);
        BIO_free(sigbio);
        if (siglen < 0) {
            BIO_printf(bio_err, "Error reading signature data\n");
            goto end;
        }
    }
    if (in != NULL && !rawin) {
        buf_inlen = bio_to_mem(&buf_in, keysize * 10, in);
        if (buf_inlen < 0) {
            BIO_printf(bio_err, "Error reading input Data\n");
            goto end;
        }
        if (rev) {
            size_t i;
            unsigned char ctmp;
            size_t l = (size_t)buf_inlen;
            for (i = 0; i < l / 2; i++) {
                ctmp = buf_in[i];
                buf_in[i] = buf_in[l - 1 - i];
                buf_in[l - 1 - i] = ctmp;
            }
        }
    }
    if (!rawin
            && buf_inlen > EVP_MAX_MD_SIZE
            && (pkey_op == EVP_PKEY_OP_SIGN
                || pkey_op == EVP_PKEY_OP_VERIFY
                || pkey_op == EVP_PKEY_OP_VERIFYRECOVER)) {
        BIO_printf(bio_err,
                   "Error: The input data looks too long to be a hash\n");
        goto end;
    }
    if (pkey_op == EVP_PKEY_OP_VERIFY) {
        if (rawin) {
            rv = do_raw_keyop(pkey_op, ctx, md, pkey, in, sig, siglen,
                              NULL, 0);
        } else {
            rv = EVP_PKEY_verify(ctx, sig, (size_t)siglen,
                                 buf_in, (size_t)buf_inlen);
        }
        if (rv == 1) {
            BIO_puts(out, "Signature Verified Successfully\n");
            ret = 0;
        } else {
            BIO_puts(out, "Signature Verification Failure\n");
        }
        goto end;
    }
    if (kdflen != 0) {
        buf_outlen = kdflen;
        rv = 1;
    } else {
        if (rawin) {
            rv = do_raw_keyop(pkey_op, ctx, md, pkey, in, NULL, 0,
                              &buf_out, (size_t *)&buf_outlen);
        } else {
            rv = do_keyop(ctx, pkey_op, NULL, (size_t *)&buf_outlen,
                          buf_in, (size_t)buf_inlen);
            if (rv > 0 && buf_outlen != 0) {
                buf_out = app_malloc(buf_outlen, "buffer output");
                rv = do_keyop(ctx, pkey_op,
                              buf_out, (size_t *)&buf_outlen,
                              buf_in, (size_t)buf_inlen);
            }
        }
    }
    if (rv <= 0) {
        if (pkey_op != EVP_PKEY_OP_DERIVE) {
            BIO_puts(bio_err, "Public Key operation error\n");
        } else {
            BIO_puts(bio_err, "Key derivation failed\n");
        }
        ERR_print_errors(bio_err);
        goto end;
    }
    ret = 0;
    if (asn1parse) {
        if (!ASN1_parse_dump(out, buf_out, buf_outlen, 1, -1))
            ERR_print_errors(bio_err);
    } else if (hexdump) {
        BIO_dump(out, (char *)buf_out, buf_outlen);
    } else {
        BIO_write(out, buf_out, buf_outlen);
    }
 end:
    EVP_PKEY_CTX_free(ctx);
    release_engine(e);
    BIO_free(in);
    BIO_free_all(out);
    OPENSSL_free(buf_in);
    OPENSSL_free(buf_out);
    OPENSSL_free(sig);
    sk_OPENSSL_STRING_free(pkeyopts);
    sk_OPENSSL_STRING_free(pkeyopts_passin);
    return ret;
}
['int pkeyutl_main(int argc, char **argv)\n{\n    BIO *in = NULL, *out = NULL;\n    ENGINE *e = NULL;\n    EVP_PKEY_CTX *ctx = NULL;\n    EVP_PKEY *pkey = NULL;\n    char *infile = NULL, *outfile = NULL, *sigfile = NULL, *passinarg = NULL;\n    char hexdump = 0, asn1parse = 0, rev = 0, *prog;\n    unsigned char *buf_in = NULL, *buf_out = NULL, *sig = NULL;\n    OPTION_CHOICE o;\n    int buf_inlen = 0, siglen = -1, keyform = FORMAT_PEM, peerform = FORMAT_PEM;\n    int keysize = -1, pkey_op = EVP_PKEY_OP_SIGN, key_type = KEY_PRIVKEY;\n    int engine_impl = 0;\n    int ret = 1, rv = -1;\n    size_t buf_outlen;\n    const char *inkey = NULL;\n    const char *peerkey = NULL;\n    const char *kdfalg = NULL;\n    int kdflen = 0;\n    STACK_OF(OPENSSL_STRING) *pkeyopts = NULL;\n    STACK_OF(OPENSSL_STRING) *pkeyopts_passin = NULL;\n    int rawin = 0;\n    const EVP_MD *md = NULL;\n    prog = opt_init(argc, argv, pkeyutl_options);\n    while ((o = opt_next()) != OPT_EOF) {\n        switch (o) {\n        case OPT_EOF:\n        case OPT_ERR:\n opthelp:\n            BIO_printf(bio_err, "%s: Use -help for summary.\\n", prog);\n            goto end;\n        case OPT_HELP:\n            opt_help(pkeyutl_options);\n            ret = 0;\n            goto end;\n        case OPT_IN:\n            infile = opt_arg();\n            break;\n        case OPT_OUT:\n            outfile = opt_arg();\n            break;\n        case OPT_SIGFILE:\n            sigfile = opt_arg();\n            break;\n        case OPT_ENGINE_IMPL:\n            engine_impl = 1;\n            break;\n        case OPT_INKEY:\n            inkey = opt_arg();\n            break;\n        case OPT_PEERKEY:\n            peerkey = opt_arg();\n            break;\n        case OPT_PASSIN:\n            passinarg = opt_arg();\n            break;\n        case OPT_PEERFORM:\n            if (!opt_format(opt_arg(), OPT_FMT_PDE, &peerform))\n                goto opthelp;\n            break;\n        case OPT_KEYFORM:\n            if (!opt_format(opt_arg(), OPT_FMT_PDE, &keyform))\n                goto opthelp;\n            break;\n        case OPT_R_CASES:\n            if (!opt_rand(o))\n                goto end;\n            break;\n        case OPT_ENGINE:\n            e = setup_engine(opt_arg(), 0);\n            break;\n        case OPT_PUBIN:\n            key_type = KEY_PUBKEY;\n            break;\n        case OPT_CERTIN:\n            key_type = KEY_CERT;\n            break;\n        case OPT_ASN1PARSE:\n            asn1parse = 1;\n            break;\n        case OPT_HEXDUMP:\n            hexdump = 1;\n            break;\n        case OPT_SIGN:\n            pkey_op = EVP_PKEY_OP_SIGN;\n            break;\n        case OPT_VERIFY:\n            pkey_op = EVP_PKEY_OP_VERIFY;\n            break;\n        case OPT_VERIFYRECOVER:\n            pkey_op = EVP_PKEY_OP_VERIFYRECOVER;\n            break;\n        case OPT_ENCRYPT:\n            pkey_op = EVP_PKEY_OP_ENCRYPT;\n            break;\n        case OPT_DECRYPT:\n            pkey_op = EVP_PKEY_OP_DECRYPT;\n            break;\n        case OPT_DERIVE:\n            pkey_op = EVP_PKEY_OP_DERIVE;\n            break;\n        case OPT_KDF:\n            pkey_op = EVP_PKEY_OP_DERIVE;\n            key_type = KEY_NONE;\n            kdfalg = opt_arg();\n            break;\n        case OPT_KDFLEN:\n            kdflen = atoi(opt_arg());\n            break;\n        case OPT_REV:\n            rev = 1;\n            break;\n        case OPT_PKEYOPT:\n            if ((pkeyopts == NULL &&\n                 (pkeyopts = sk_OPENSSL_STRING_new_null()) == NULL) ||\n                sk_OPENSSL_STRING_push(pkeyopts, opt_arg()) == 0) {\n                BIO_puts(bio_err, "out of memory\\n");\n                goto end;\n            }\n            break;\n        case OPT_PKEYOPT_PASSIN:\n            if ((pkeyopts_passin == NULL &&\n                 (pkeyopts_passin = sk_OPENSSL_STRING_new_null()) == NULL) ||\n                sk_OPENSSL_STRING_push(pkeyopts_passin, opt_arg()) == 0) {\n                BIO_puts(bio_err, "out of memory\\n");\n                goto end;\n            }\n            break;\n        case OPT_RAWIN:\n            rawin = 1;\n            break;\n        case OPT_DIGEST:\n            if (!opt_md(opt_arg(), &md))\n                goto end;\n            break;\n        }\n    }\n    argc = opt_num_rest();\n    if (argc != 0)\n        goto opthelp;\n    if (rawin && pkey_op != EVP_PKEY_OP_SIGN && pkey_op != EVP_PKEY_OP_VERIFY) {\n        BIO_printf(bio_err,\n                   "%s: -rawin can only be used with -sign or -verify\\n",\n                   prog);\n        goto opthelp;\n    }\n    if (md != NULL && !rawin) {\n        BIO_printf(bio_err,\n                   "%s: -digest can only be used with -rawin\\n",\n                   prog);\n        goto opthelp;\n    }\n    if (rawin && rev) {\n        BIO_printf(bio_err, "%s: -rev cannot be used with raw input\\n",\n                   prog);\n        goto opthelp;\n    }\n    if (kdfalg != NULL) {\n        if (kdflen == 0) {\n            BIO_printf(bio_err,\n                       "%s: no KDF length given (-kdflen parameter).\\n", prog);\n            goto opthelp;\n        }\n    } else if (inkey == NULL) {\n        BIO_printf(bio_err,\n                   "%s: no private key given (-inkey parameter).\\n", prog);\n        goto opthelp;\n    } else if (peerkey != NULL && pkey_op != EVP_PKEY_OP_DERIVE) {\n        BIO_printf(bio_err,\n                   "%s: no peer key given (-peerkey parameter).\\n", prog);\n        goto opthelp;\n    }\n    ctx = init_ctx(kdfalg, &keysize, inkey, keyform, key_type,\n                   passinarg, pkey_op, e, engine_impl, &pkey);\n    if (ctx == NULL) {\n        BIO_printf(bio_err, "%s: Error initializing context\\n", prog);\n        ERR_print_errors(bio_err);\n        goto end;\n    }\n    if (peerkey != NULL && !setup_peer(ctx, peerform, peerkey, e)) {\n        BIO_printf(bio_err, "%s: Error setting up peer key\\n", prog);\n        ERR_print_errors(bio_err);\n        goto end;\n    }\n    if (pkeyopts != NULL) {\n        int num = sk_OPENSSL_STRING_num(pkeyopts);\n        int i;\n        for (i = 0; i < num; ++i) {\n            const char *opt = sk_OPENSSL_STRING_value(pkeyopts, i);\n            if (pkey_ctrl_string(ctx, opt) <= 0) {\n                BIO_printf(bio_err, "%s: Can\'t set parameter \\"%s\\":\\n",\n                           prog, opt);\n                ERR_print_errors(bio_err);\n                goto end;\n            }\n        }\n    }\n    if (pkeyopts_passin != NULL) {\n        int num = sk_OPENSSL_STRING_num(pkeyopts_passin);\n        int i;\n        for (i = 0; i < num; i++) {\n            char *opt = sk_OPENSSL_STRING_value(pkeyopts_passin, i);\n            char *passin = strchr(opt, \':\');\n            char *passwd;\n            if (passin == NULL) {\n                char passwd_buf[4096];\n                BIO_snprintf(passwd_buf, sizeof(passwd_buf), "Enter %s: ", opt);\n                EVP_read_pw_string(passwd_buf, sizeof(passwd_buf) - 1,\n                                   passwd_buf, 0);\n                passwd = OPENSSL_strdup(passwd_buf);\n                if (passwd == NULL) {\n                    BIO_puts(bio_err, "out of memory\\n");\n                    goto end;\n                }\n            } else {\n                *passin = 0;\n                passin++;\n                if (app_passwd(passin, NULL, &passwd, NULL) == 0) {\n                    BIO_printf(bio_err, "failed to get \'%s\'\\n", opt);\n                    goto end;\n                }\n            }\n            if (EVP_PKEY_CTX_ctrl_str(ctx, opt, passwd) <= 0) {\n                BIO_printf(bio_err, "%s: Can\'t set parameter \\"%s\\":\\n",\n                           prog, opt);\n                goto end;\n            }\n            OPENSSL_free(passwd);\n        }\n    }\n    if (sigfile != NULL && (pkey_op != EVP_PKEY_OP_VERIFY)) {\n        BIO_printf(bio_err,\n                   "%s: Signature file specified for non verify\\n", prog);\n        goto end;\n    }\n    if (sigfile == NULL && (pkey_op == EVP_PKEY_OP_VERIFY)) {\n        BIO_printf(bio_err,\n                   "%s: No signature file specified for verify\\n", prog);\n        goto end;\n    }\n    if (pkey_op != EVP_PKEY_OP_DERIVE) {\n        in = bio_open_default(infile, \'r\', FORMAT_BINARY);\n        if (in == NULL)\n            goto end;\n    }\n    out = bio_open_default(outfile, \'w\', FORMAT_BINARY);\n    if (out == NULL)\n        goto end;\n    if (sigfile != NULL) {\n        BIO *sigbio = BIO_new_file(sigfile, "rb");\n        if (sigbio == NULL) {\n            BIO_printf(bio_err, "Can\'t open signature file %s\\n", sigfile);\n            goto end;\n        }\n        siglen = bio_to_mem(&sig, keysize * 10, sigbio);\n        BIO_free(sigbio);\n        if (siglen < 0) {\n            BIO_printf(bio_err, "Error reading signature data\\n");\n            goto end;\n        }\n    }\n    if (in != NULL && !rawin) {\n        buf_inlen = bio_to_mem(&buf_in, keysize * 10, in);\n        if (buf_inlen < 0) {\n            BIO_printf(bio_err, "Error reading input Data\\n");\n            goto end;\n        }\n        if (rev) {\n            size_t i;\n            unsigned char ctmp;\n            size_t l = (size_t)buf_inlen;\n            for (i = 0; i < l / 2; i++) {\n                ctmp = buf_in[i];\n                buf_in[i] = buf_in[l - 1 - i];\n                buf_in[l - 1 - i] = ctmp;\n            }\n        }\n    }\n    if (!rawin\n            && buf_inlen > EVP_MAX_MD_SIZE\n            && (pkey_op == EVP_PKEY_OP_SIGN\n                || pkey_op == EVP_PKEY_OP_VERIFY\n                || pkey_op == EVP_PKEY_OP_VERIFYRECOVER)) {\n        BIO_printf(bio_err,\n                   "Error: The input data looks too long to be a hash\\n");\n        goto end;\n    }\n    if (pkey_op == EVP_PKEY_OP_VERIFY) {\n        if (rawin) {\n            rv = do_raw_keyop(pkey_op, ctx, md, pkey, in, sig, siglen,\n                              NULL, 0);\n        } else {\n            rv = EVP_PKEY_verify(ctx, sig, (size_t)siglen,\n                                 buf_in, (size_t)buf_inlen);\n        }\n        if (rv == 1) {\n            BIO_puts(out, "Signature Verified Successfully\\n");\n            ret = 0;\n        } else {\n            BIO_puts(out, "Signature Verification Failure\\n");\n        }\n        goto end;\n    }\n    if (kdflen != 0) {\n        buf_outlen = kdflen;\n        rv = 1;\n    } else {\n        if (rawin) {\n            rv = do_raw_keyop(pkey_op, ctx, md, pkey, in, NULL, 0,\n                              &buf_out, (size_t *)&buf_outlen);\n        } else {\n            rv = do_keyop(ctx, pkey_op, NULL, (size_t *)&buf_outlen,\n                          buf_in, (size_t)buf_inlen);\n            if (rv > 0 && buf_outlen != 0) {\n                buf_out = app_malloc(buf_outlen, "buffer output");\n                rv = do_keyop(ctx, pkey_op,\n                              buf_out, (size_t *)&buf_outlen,\n                              buf_in, (size_t)buf_inlen);\n            }\n        }\n    }\n    if (rv <= 0) {\n        if (pkey_op != EVP_PKEY_OP_DERIVE) {\n            BIO_puts(bio_err, "Public Key operation error\\n");\n        } else {\n            BIO_puts(bio_err, "Key derivation failed\\n");\n        }\n        ERR_print_errors(bio_err);\n        goto end;\n    }\n    ret = 0;\n    if (asn1parse) {\n        if (!ASN1_parse_dump(out, buf_out, buf_outlen, 1, -1))\n            ERR_print_errors(bio_err);\n    } else if (hexdump) {\n        BIO_dump(out, (char *)buf_out, buf_outlen);\n    } else {\n        BIO_write(out, buf_out, buf_outlen);\n    }\n end:\n    EVP_PKEY_CTX_free(ctx);\n    release_engine(e);\n    BIO_free(in);\n    BIO_free_all(out);\n    OPENSSL_free(buf_in);\n    OPENSSL_free(buf_out);\n    OPENSSL_free(sig);\n    sk_OPENSSL_STRING_free(pkeyopts);\n    sk_OPENSSL_STRING_free(pkeyopts_passin);\n    return ret;\n}', 'int bio_to_mem(unsigned char **out, int maxlen, BIO *in)\n{\n    BIO *mem;\n    int len, ret;\n    unsigned char tbuf[1024];\n    mem = BIO_new(BIO_s_mem());\n    if (mem == NULL)\n        return -1;\n    for (;;) {\n        if ((maxlen != -1) && maxlen < 1024)\n            len = maxlen;\n        else\n            len = 1024;\n        len = BIO_read(in, tbuf, len);\n        if (len < 0) {\n            BIO_free(mem);\n            return -1;\n        }\n        if (len == 0)\n            break;\n        if (BIO_write(mem, tbuf, len) != len) {\n            BIO_free(mem);\n            return -1;\n        }\n        maxlen -= len;\n        if (maxlen == 0)\n            break;\n    }\n    ret = BIO_get_mem_data(mem, (char **)out);\n    BIO_set_flags(mem, BIO_FLAGS_MEM_RDONLY);\n    BIO_free(mem);\n    return ret;\n}']