apps/pkeyutl.c:712: error: MEMORY_LEAK
  memory dynamically allocated by call to `EVP_MD_CTX_new()` at line 660, column 17 is not reachable after line 712, column 5.
Showing all 84 steps of the trace


apps/pkeyutl.c:650:1: start of procedure do_raw_keyop()
648.   #define TBUF_MAXSIZE 2048
649.   
650. > static int do_raw_keyop(int pkey_op, EVP_PKEY_CTX *ctx,
651.                           const EVP_MD *md, EVP_PKEY *pkey, BIO *in,
652.                           unsigned char *sig, int siglen,

apps/pkeyutl.c:655:5: 
653.                           unsigned char **out, size_t *poutlen)
654.   {
655. >     int rv = 0;
656.       EVP_MD_CTX *mctx = NULL;
657.       unsigned char tbuf[TBUF_MAXSIZE];

apps/pkeyutl.c:656:5: 
654.   {
655.       int rv = 0;
656. >     EVP_MD_CTX *mctx = NULL;
657.       unsigned char tbuf[TBUF_MAXSIZE];
658.       int tbuf_len = 0;

apps/pkeyutl.c:658:5: 
656.       EVP_MD_CTX *mctx = NULL;
657.       unsigned char tbuf[TBUF_MAXSIZE];
658. >     int tbuf_len = 0;
659.   
660.       if ((mctx = EVP_MD_CTX_new()) == NULL) {

apps/pkeyutl.c:660:9: 
658.       int tbuf_len = 0;
659.   
660. >     if ((mctx = EVP_MD_CTX_new()) == NULL) {
661.           BIO_printf(bio_err, "Error: out of memory\n");
662.           return rv;

crypto/evp/digest.c:49:1: start of procedure EVP_MD_CTX_new()
  47.   }
  48.   
  49. > EVP_MD_CTX *EVP_MD_CTX_new(void)
  50.   {
  51.       return OPENSSL_zalloc(sizeof(EVP_MD_CTX));

crypto/evp/digest.c:51:5: 
  49.   EVP_MD_CTX *EVP_MD_CTX_new(void)
  50.   {
  51. >     return OPENSSL_zalloc(sizeof(EVP_MD_CTX));
  52.   }
  53.   

crypto/mem.c:228:1: start of procedure CRYPTO_zalloc()
    226.   }
    227.   
    228. > void *CRYPTO_zalloc(size_t num, const char *file, int line)
    229.   {
    230.       void *ret = CRYPTO_malloc(num, file, line);

crypto/mem.c:230:5: 
    228.   void *CRYPTO_zalloc(size_t num, const char *file, int line)
    229.   {
    230. >     void *ret = CRYPTO_malloc(num, file, line);
    231.   
    232.       FAILTEST();

crypto/mem.c:192:1: start of procedure CRYPTO_malloc()
      190.   #endif
      191.   
      192. > void *CRYPTO_malloc(size_t num, const char *file, int line)
      193.   {
      194.       void *ret = NULL;

crypto/mem.c:194:5: 
      192.   void *CRYPTO_malloc(size_t num, const char *file, int line)
      193.   {
      194. >     void *ret = NULL;
      195.   
      196.       INCREMENT(malloc_count);

crypto/mem.c:197:9: Taking false branch
      195.   
      196.       INCREMENT(malloc_count);
      197.       if (malloc_impl != NULL && malloc_impl != CRYPTO_malloc)
                     ^
      198.           return malloc_impl(num, file, line);
      199.   

crypto/mem.c:200:9: Taking false branch
      198.           return malloc_impl(num, file, line);
      199.   
      200.       if (num == 0)
                     ^
      201.           return NULL;
      202.   

crypto/mem.c:204:9: Taking true branch
      202.   
      203.       FAILTEST();
      204.       if (allow_customize) {
                     ^
      205.           /*
      206.            * Disallow customization after the first allocation. We only set this

crypto/mem.c:210:9: 
      208.            * allocation.
      209.            */
      210. >         allow_customize = 0;
      211.       }
      212.   #ifndef OPENSSL_NO_CRYPTO_MDEBUG

crypto/mem.c:221:5: 
      219.       }
      220.   #else
      221. >     (void)(file); (void)(line);
      222.       ret = malloc(num);
      223.   #endif

crypto/mem.c:221:19: 
      219.       }
      220.   #else
      221. >     (void)(file); (void)(line);
      222.       ret = malloc(num);
      223.   #endif

crypto/mem.c:222:5: 
      220.   #else
      221.       (void)(file); (void)(line);
      222. >     ret = malloc(num);
      223.   #endif
      224.   

crypto/mem.c:225:5: 
      223.   #endif
      224.   
      225. >     return ret;
      226.   }
      227.   

crypto/mem.c:226:1: return from a call to CRYPTO_malloc
      224.   
      225.       return ret;
      226. > }
      227.   
      228.   void *CRYPTO_zalloc(size_t num, const char *file, int line)

crypto/mem.c:233:9: Taking true branch
    231.   
    232.       FAILTEST();
    233.       if (ret != NULL)
                   ^
    234.           memset(ret, 0, num);
    235.       return ret;

crypto/mem.c:234:9: 
    232.       FAILTEST();
    233.       if (ret != NULL)
    234. >         memset(ret, 0, num);
    235.       return ret;
    236.   }

crypto/mem.c:235:5: 
    233.       if (ret != NULL)
    234.           memset(ret, 0, num);
    235. >     return ret;
    236.   }
    237.   

crypto/mem.c:236:1: return from a call to CRYPTO_zalloc
    234.           memset(ret, 0, num);
    235.       return ret;
    236. > }
    237.   
    238.   void *CRYPTO_realloc(void *str, size_t num, const char *file, int line)

crypto/evp/digest.c:52:1: return from a call to EVP_MD_CTX_new
  50.   {
  51.       return OPENSSL_zalloc(sizeof(EVP_MD_CTX));
  52. > }
  53.   
  54.   void EVP_MD_CTX_free(EVP_MD_CTX *ctx)

apps/pkeyutl.c:660:9: Taking false branch
658.       int tbuf_len = 0;
659.   
660.       if ((mctx = EVP_MD_CTX_new()) == NULL) {
               ^
661.           BIO_printf(bio_err, "Error: out of memory\n");
662.           return rv;

apps/pkeyutl.c:664:5: 
662.           return rv;
663.       }
664. >     EVP_MD_CTX_set_pkey_ctx(mctx, ctx);
665.   
666.       switch(pkey_op) {

crypto/evp/evp_lib.c:463:1: start of procedure EVP_MD_CTX_set_pkey_ctx()
  461.   }
  462.   
  463. > void EVP_MD_CTX_set_pkey_ctx(EVP_MD_CTX *ctx, EVP_PKEY_CTX *pctx)
  464.   {
  465.       /*

crypto/evp/evp_lib.c:469:10: 
  467.        * we have to deal with the cleanup job here.
  468.        */
  469. >     if (!EVP_MD_CTX_test_flags(ctx, EVP_MD_CTX_FLAG_KEEP_PKEY_CTX))
  470.           EVP_PKEY_CTX_free(ctx->pctx);
  471.   

crypto/evp/evp_lib.c:510:1: start of procedure EVP_MD_CTX_test_flags()
    508.   }
    509.   
    510. > int EVP_MD_CTX_test_flags(const EVP_MD_CTX *ctx, int flags)
    511.   {
    512.       return (ctx->flags & flags);

crypto/evp/evp_lib.c:512:5: 
    510.   int EVP_MD_CTX_test_flags(const EVP_MD_CTX *ctx, int flags)
    511.   {
    512. >     return (ctx->flags & flags);
    513.   }
    514.   

crypto/evp/evp_lib.c:513:1: return from a call to EVP_MD_CTX_test_flags
    511.   {
    512.       return (ctx->flags & flags);
    513. > }
    514.   
    515.   void EVP_CIPHER_CTX_set_flags(EVP_CIPHER_CTX *ctx, int flags)

crypto/evp/evp_lib.c:469:10: Taking true branch
  467.        * we have to deal with the cleanup job here.
  468.        */
  469.       if (!EVP_MD_CTX_test_flags(ctx, EVP_MD_CTX_FLAG_KEEP_PKEY_CTX))
                  ^
  470.           EVP_PKEY_CTX_free(ctx->pctx);
  471.   

crypto/evp/evp_lib.c:470:9: 
  468.        */
  469.       if (!EVP_MD_CTX_test_flags(ctx, EVP_MD_CTX_FLAG_KEEP_PKEY_CTX))
  470. >         EVP_PKEY_CTX_free(ctx->pctx);
  471.   
  472.       ctx->pctx = pctx;

crypto/evp/pmeth_lib.c:352:1: start of procedure EVP_PKEY_CTX_free()
    350.   }
    351.   
    352. > void EVP_PKEY_CTX_free(EVP_PKEY_CTX *ctx)
    353.   {
    354.       if (ctx == NULL)

crypto/evp/pmeth_lib.c:354:9: Taking false branch
    352.   void EVP_PKEY_CTX_free(EVP_PKEY_CTX *ctx)
    353.   {
    354.       if (ctx == NULL)
                   ^
    355.           return;
    356.       if (ctx->pmeth && ctx->pmeth->cleanup)

crypto/evp/pmeth_lib.c:356:9: Taking true branch
    354.       if (ctx == NULL)
    355.           return;
    356.       if (ctx->pmeth && ctx->pmeth->cleanup)
                   ^
    357.           ctx->pmeth->cleanup(ctx);
    358.       EVP_PKEY_free(ctx->pkey);

crypto/evp/pmeth_lib.c:356:23: Taking true branch
    354.       if (ctx == NULL)
    355.           return;
    356.       if (ctx->pmeth && ctx->pmeth->cleanup)
                                 ^
    357.           ctx->pmeth->cleanup(ctx);
    358.       EVP_PKEY_free(ctx->pkey);

crypto/evp/pmeth_lib.c:357:9: Skipping __function_pointer__(): unresolved function pointer
    355.           return;
    356.       if (ctx->pmeth && ctx->pmeth->cleanup)
    357.           ctx->pmeth->cleanup(ctx);
                   ^
    358.       EVP_PKEY_free(ctx->pkey);
    359.       EVP_PKEY_free(ctx->peerkey);

crypto/evp/pmeth_lib.c:358:5: 
    356.       if (ctx->pmeth && ctx->pmeth->cleanup)
    357.           ctx->pmeth->cleanup(ctx);
    358. >     EVP_PKEY_free(ctx->pkey);
    359.       EVP_PKEY_free(ctx->peerkey);
    360.   #ifndef OPENSSL_NO_ENGINE

crypto/evp/p_lib.c:590:1: start of procedure EVP_PKEY_free()
      588.   }
      589.   
      590. > void EVP_PKEY_free(EVP_PKEY *x)
      591.   {
      592.       int i;

crypto/evp/p_lib.c:594:9: Taking true branch
      592.       int i;
      593.   
      594.       if (x == NULL)
                     ^
      595.           return;
      596.   

crypto/evp/p_lib.c:595:9: 
      593.   
      594.       if (x == NULL)
      595. >         return;
      596.   
      597.       CRYPTO_DOWN_REF(&x->references, &i, x->lock);

crypto/evp/p_lib.c:606:1: return from a call to EVP_PKEY_free
      604.       sk_X509_ATTRIBUTE_pop_free(x->attributes, X509_ATTRIBUTE_free);
      605.       OPENSSL_free(x);
      606. > }
      607.   
      608.   static void EVP_PKEY_free_it(EVP_PKEY *x)

crypto/evp/pmeth_lib.c:359:5: 
    357.           ctx->pmeth->cleanup(ctx);
    358.       EVP_PKEY_free(ctx->pkey);
    359. >     EVP_PKEY_free(ctx->peerkey);
    360.   #ifndef OPENSSL_NO_ENGINE
    361.       ENGINE_finish(ctx->engine);

crypto/evp/p_lib.c:590:1: start of procedure EVP_PKEY_free()
      588.   }
      589.   
      590. > void EVP_PKEY_free(EVP_PKEY *x)
      591.   {
      592.       int i;

crypto/evp/p_lib.c:594:9: Taking true branch
      592.       int i;
      593.   
      594.       if (x == NULL)
                     ^
      595.           return;
      596.   

crypto/evp/p_lib.c:595:9: 
      593.   
      594.       if (x == NULL)
      595. >         return;
      596.   
      597.       CRYPTO_DOWN_REF(&x->references, &i, x->lock);

crypto/evp/p_lib.c:606:1: return from a call to EVP_PKEY_free
      604.       sk_X509_ATTRIBUTE_pop_free(x->attributes, X509_ATTRIBUTE_free);
      605.       OPENSSL_free(x);
      606. > }
      607.   
      608.   static void EVP_PKEY_free_it(EVP_PKEY *x)

crypto/evp/pmeth_lib.c:361:5: 
    359.       EVP_PKEY_free(ctx->peerkey);
    360.   #ifndef OPENSSL_NO_ENGINE
    361. >     ENGINE_finish(ctx->engine);
    362.   #endif
    363.       OPENSSL_free(ctx);

crypto/engine/eng_init.c:95:1: start of procedure ENGINE_finish()
      93.   
      94.   /* The API (locked) version of "finish" */
      95. > int ENGINE_finish(ENGINE *e)
      96.   {
      97.       int to_return = 1;

crypto/engine/eng_init.c:97:5: 
      95.   int ENGINE_finish(ENGINE *e)
      96.   {
      97. >     int to_return = 1;
      98.   
      99.       if (e == NULL)

crypto/engine/eng_init.c:99:9: Taking true branch
      97.       int to_return = 1;
      98.   
      99.       if (e == NULL)
                     ^
      100.           return 1;
      101.       CRYPTO_THREAD_write_lock(global_engine_lock);

crypto/engine/eng_init.c:100:9: 
      98.   
      99.       if (e == NULL)
      100. >         return 1;
      101.       CRYPTO_THREAD_write_lock(global_engine_lock);
      102.       to_return = engine_unlocked_finish(e, 1);

crypto/engine/eng_init.c:109:1: return from a call to ENGINE_finish
      107.       }
      108.       return to_return;
      109. > }

crypto/evp/pmeth_lib.c:363:5: 
    361.       ENGINE_finish(ctx->engine);
    362.   #endif
    363. >     OPENSSL_free(ctx);
    364.   }
    365.   

crypto/mem.c:295:1: start of procedure CRYPTO_free()
      293.   }
      294.   
      295. > void CRYPTO_free(void *str, const char *file, int line)
      296.   {
      297.       INCREMENT(free_count);

crypto/mem.c:298:9: Taking false branch
      296.   {
      297.       INCREMENT(free_count);
      298.       if (free_impl != NULL && free_impl != &CRYPTO_free) {
                     ^
      299.           free_impl(str, file, line);
      300.           return;

crypto/mem.c:312:5: 
      310.       }
      311.   #else
      312. >     free(str);
      313.   #endif
      314.   }

crypto/mem.c:314:1: return from a call to CRYPTO_free
      312.       free(str);
      313.   #endif
      314. > }
      315.   
      316.   void CRYPTO_clear_free(void *str, size_t num, const char *file, int line)

crypto/evp/pmeth_lib.c:364:1: return from a call to EVP_PKEY_CTX_free
    362.   #endif
    363.       OPENSSL_free(ctx);
    364. > }
    365.   
    366.   int EVP_PKEY_CTX_ctrl(EVP_PKEY_CTX *ctx, int keytype, int optype,

crypto/evp/evp_lib.c:472:5: 
  470.           EVP_PKEY_CTX_free(ctx->pctx);
  471.   
  472. >     ctx->pctx = pctx;
  473.   
  474.       if (pctx != NULL) {

crypto/evp/evp_lib.c:474:9: Taking true branch
  472.       ctx->pctx = pctx;
  473.   
  474.       if (pctx != NULL) {
                 ^
  475.           /* make sure pctx is not freed when destroying EVP_MD_CTX */
  476.           EVP_MD_CTX_set_flags(ctx, EVP_MD_CTX_FLAG_KEEP_PKEY_CTX);

crypto/evp/evp_lib.c:476:9: 
  474.       if (pctx != NULL) {
  475.           /* make sure pctx is not freed when destroying EVP_MD_CTX */
  476. >         EVP_MD_CTX_set_flags(ctx, EVP_MD_CTX_FLAG_KEEP_PKEY_CTX);
  477.       } else {
  478.           EVP_MD_CTX_clear_flags(ctx, EVP_MD_CTX_FLAG_KEEP_PKEY_CTX);

crypto/evp/evp_lib.c:500:1: start of procedure EVP_MD_CTX_set_flags()
    498.   }
    499.   
    500. > void EVP_MD_CTX_set_flags(EVP_MD_CTX *ctx, int flags)
    501.   {
    502.       ctx->flags |= flags;

crypto/evp/evp_lib.c:502:5: 
    500.   void EVP_MD_CTX_set_flags(EVP_MD_CTX *ctx, int flags)
    501.   {
    502. >     ctx->flags |= flags;
    503.   }
    504.   

crypto/evp/evp_lib.c:503:1: return from a call to EVP_MD_CTX_set_flags
    501.   {
    502.       ctx->flags |= flags;
    503. > }
    504.   
    505.   void EVP_MD_CTX_clear_flags(EVP_MD_CTX *ctx, int flags)

crypto/evp/evp_lib.c:474:5: 
  472.       ctx->pctx = pctx;
  473.   
  474. >     if (pctx != NULL) {
  475.           /* make sure pctx is not freed when destroying EVP_MD_CTX */
  476.           EVP_MD_CTX_set_flags(ctx, EVP_MD_CTX_FLAG_KEEP_PKEY_CTX);

crypto/evp/evp_lib.c:480:1: return from a call to EVP_MD_CTX_set_pkey_ctx
  478.           EVP_MD_CTX_clear_flags(ctx, EVP_MD_CTX_FLAG_KEEP_PKEY_CTX);
  479.       }
  480. > }
  481.   
  482.   void *EVP_MD_CTX_md_data(const EVP_MD_CTX *ctx)

apps/pkeyutl.c:666:5: 
664.       EVP_MD_CTX_set_pkey_ctx(mctx, ctx);
665.   
666. >     switch(pkey_op) {
667.       case EVP_PKEY_OP_VERIFY:
668.           if (EVP_DigestVerifyInit(mctx, NULL, md, NULL, pkey) != 1)

apps/pkeyutl.c:667:5: Switch condition is false. Skipping switch case
665.   
666.       switch(pkey_op) {
667.       case EVP_PKEY_OP_VERIFY:
           ^
668.           if (EVP_DigestVerifyInit(mctx, NULL, md, NULL, pkey) != 1)
669.               goto end;

apps/pkeyutl.c:686:5: Switch condition is false. Skipping switch case
684.           rv = EVP_DigestVerifyFinal(mctx, sig, (size_t)siglen);
685.           break;
686.       case EVP_PKEY_OP_SIGN:
           ^
687.           if (EVP_DigestSignInit(mctx, NULL, md, NULL, pkey) != 1)
688.               goto end;

apps/pkeyutl.c:711:2: 
709.       }
710.   
711. >  end:
712.       EVP_MD_CTX_free(mctx);
713.       return rv;

apps/pkeyutl.c:712:5: 
710.   
711.    end:
712. >     EVP_MD_CTX_free(mctx);
713.       return rv;
714.   }

crypto/evp/digest.c:54:1: start of procedure EVP_MD_CTX_free()
  52.   }
  53.   
  54. > void EVP_MD_CTX_free(EVP_MD_CTX *ctx)
  55.   {
  56.       EVP_MD_CTX_reset(ctx);

crypto/evp/digest.c:56:5: Skipping EVP_MD_CTX_reset(): empty list of specs
  54.   void EVP_MD_CTX_free(EVP_MD_CTX *ctx)
  55.   {
  56.       EVP_MD_CTX_reset(ctx);
            ^
  57.       OPENSSL_free(ctx);
  58.   }

crypto/evp/digest.c:57:5: 
  55.   {
  56.       EVP_MD_CTX_reset(ctx);
  57. >     OPENSSL_free(ctx);
  58.   }
  59.   

crypto/mem.c:295:1: start of procedure CRYPTO_free()
    293.   }
    294.   
    295. > void CRYPTO_free(void *str, const char *file, int line)
    296.   {
    297.       INCREMENT(free_count);

crypto/mem.c:298:9: Taking true branch
    296.   {
    297.       INCREMENT(free_count);
    298.       if (free_impl != NULL && free_impl != &CRYPTO_free) {
                   ^
    299.           free_impl(str, file, line);
    300.           return;

crypto/mem.c:298:30: Taking true branch
    296.   {
    297.       INCREMENT(free_count);
    298.       if (free_impl != NULL && free_impl != &CRYPTO_free) {
                                        ^
    299.           free_impl(str, file, line);
    300.           return;

crypto/mem.c:299:9: Skipping __function_pointer__(): unresolved function pointer
    297.       INCREMENT(free_count);
    298.       if (free_impl != NULL && free_impl != &CRYPTO_free) {
    299.           free_impl(str, file, line);
                   ^
    300.           return;
    301.       }

crypto/mem.c:300:9: 
    298.       if (free_impl != NULL && free_impl != &CRYPTO_free) {
    299.           free_impl(str, file, line);
    300. >         return;
    301.       }
    302.   

crypto/mem.c:314:1: return from a call to CRYPTO_free
    312.       free(str);
    313.   #endif
    314. > }
    315.   
    316.   void CRYPTO_clear_free(void *str, size_t num, const char *file, int line)

crypto/evp/digest.c:58:1: return from a call to EVP_MD_CTX_free
  56.       EVP_MD_CTX_reset(ctx);
  57.       OPENSSL_free(ctx);
  58. > }
  59.   
  60.   int EVP_DigestInit(EVP_MD_CTX *ctx, const EVP_MD *type)

static int do_raw_keyop(int pkey_op, EVP_PKEY_CTX *ctx,
                        const EVP_MD *md, EVP_PKEY *pkey, BIO *in,
                        unsigned char *sig, int siglen,
                        unsigned char **out, size_t *poutlen)
{
    int rv = 0;
    EVP_MD_CTX *mctx = NULL;
    unsigned char tbuf[TBUF_MAXSIZE];
    int tbuf_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);
    switch(pkey_op) {
    case EVP_PKEY_OP_VERIFY:
        if (EVP_DigestVerifyInit(mctx, NULL, md, NULL, pkey) != 1)
            goto end;
        for (;;) {
            tbuf_len = BIO_read(in, tbuf, TBUF_MAXSIZE);
            if (tbuf_len == 0)
                break;
            if (tbuf_len < 0) {
                BIO_printf(bio_err, "Error reading raw input data\n");
                goto end;
            }
            rv = EVP_DigestVerifyUpdate(mctx, tbuf, (size_t)tbuf_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 (;;) {
            tbuf_len = BIO_read(in, tbuf, TBUF_MAXSIZE);
            if (tbuf_len == 0)
                break;
            if (tbuf_len < 0) {
                BIO_printf(bio_err, "Error reading raw input data\n");
                goto end;
            }
            rv = EVP_DigestSignUpdate(mctx, tbuf, (size_t)tbuf_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                        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    int tbuf_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    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            tbuf_len = BIO_read(in, tbuf, TBUF_MAXSIZE);\n            if (tbuf_len == 0)\n                break;\n            if (tbuf_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)tbuf_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            tbuf_len = BIO_read(in, tbuf, TBUF_MAXSIZE);\n            if (tbuf_len == 0)\n                break;\n            if (tbuf_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)tbuf_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_PKEY_CTX_free(EVP_PKEY_CTX *ctx)\n{\n    if (ctx == NULL)\n        return;\n    if (ctx->pmeth && ctx->pmeth->cleanup)\n        ctx->pmeth->cleanup(ctx);\n    EVP_PKEY_free(ctx->pkey);\n    EVP_PKEY_free(ctx->peerkey);\n#ifndef OPENSSL_NO_ENGINE\n    ENGINE_finish(ctx->engine);\n#endif\n    OPENSSL_free(ctx);\n}', 'void EVP_PKEY_free(EVP_PKEY *x)\n{\n    int i;\n    if (x == NULL)\n        return;\n    CRYPTO_DOWN_REF(&x->references, &i, x->lock);\n    REF_PRINT_COUNT("EVP_PKEY", x);\n    if (i > 0)\n        return;\n    REF_ASSERT_ISNT(i < 0);\n    EVP_PKEY_free_it(x);\n    CRYPTO_THREAD_lock_free(x->lock);\n    sk_X509_ATTRIBUTE_pop_free(x->attributes, X509_ATTRIBUTE_free);\n    OPENSSL_free(x);\n}', 'int ENGINE_finish(ENGINE *e)\n{\n    int to_return = 1;\n    if (e == NULL)\n        return 1;\n    CRYPTO_THREAD_write_lock(global_engine_lock);\n    to_return = engine_unlocked_finish(e, 1);\n    CRYPTO_THREAD_unlock(global_engine_lock);\n    if (!to_return) {\n        ENGINEerr(ENGINE_F_ENGINE_FINISH, ENGINE_R_FINISH_FAILED);\n        return 0;\n    }\n    return to_return;\n}', 'void CRYPTO_free(void *str, const char *file, int line)\n{\n    INCREMENT(free_count);\n    if (free_impl != NULL && free_impl != &CRYPTO_free) {\n        free_impl(str, file, line);\n        return;\n    }\n#ifndef OPENSSL_NO_CRYPTO_MDEBUG\n    if (call_malloc_debug) {\n        CRYPTO_mem_debug_free(str, 0, file, line);\n        free(str);\n        CRYPTO_mem_debug_free(str, 1, file, line);\n    } else {\n        free(str);\n    }\n#else\n    free(str);\n#endif\n}', 'void EVP_MD_CTX_set_flags(EVP_MD_CTX *ctx, int flags)\n{\n    ctx->flags |= flags;\n}', 'void EVP_MD_CTX_free(EVP_MD_CTX *ctx)\n{\n    EVP_MD_CTX_reset(ctx);\n    OPENSSL_free(ctx);\n}']