apps/req.c:1782: error: NULL_DEREFERENCE
  pointer `mctx` last assigned on line 1771 could be null and is dereferenced by call to `EVP_MD_CTX_pkey_ctx()` at line 1782, column 16.
Showing all 69 steps of the trace


apps/req.c:1767:1: start of procedure do_X509_REQ_sign()
1765.   }
1766.   
1767. > int do_X509_REQ_sign(X509_REQ *x, EVP_PKEY *pkey, const EVP_MD *md,
1768.                        STACK_OF(OPENSSL_STRING) *sigopts)
1769.   {

apps/req.c:1771:5: 
1769.   {
1770.       int rv;
1771. >     EVP_MD_CTX *mctx = EVP_MD_CTX_new();
1772.   #ifndef OPENSSL_NO_SM2
1773.       EVP_PKEY_CTX *pctx = NULL;

crypto/evp/digest.c:74:1: start of procedure EVP_MD_CTX_new()
  72.   }
  73.   
  74. > EVP_MD_CTX *EVP_MD_CTX_new(void)
  75.   {
  76.       return OPENSSL_zalloc(sizeof(EVP_MD_CTX));

crypto/evp/digest.c:76:5: 
  74.   EVP_MD_CTX *EVP_MD_CTX_new(void)
  75.   {
  76. >     return OPENSSL_zalloc(sizeof(EVP_MD_CTX));
  77.   }
  78.   

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 true 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:197:32: Taking true 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:198:9: Skipping __function_pointer__(): unresolved function pointer
      196.       INCREMENT(malloc_count);
      197.       if (malloc_impl != NULL && malloc_impl != CRYPTO_malloc)
      198.           return malloc_impl(num, file, line);
                     ^
      199.   
      200.       if (num == 0)

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 false branch
    231.   
    232.       FAILTEST();
    233.       if (ret != NULL)
                   ^
    234.           memset(ret, 0, num);
    235.       return ret;

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:77:1: return from a call to EVP_MD_CTX_new
  75.   {
  76.       return OPENSSL_zalloc(sizeof(EVP_MD_CTX));
  77. > }
  78.   
  79.   void EVP_MD_CTX_free(EVP_MD_CTX *ctx)

apps/req.c:1773:5: 
1771.       EVP_MD_CTX *mctx = EVP_MD_CTX_new();
1772.   #ifndef OPENSSL_NO_SM2
1773. >     EVP_PKEY_CTX *pctx = NULL;
1774.   #endif
1775.   

apps/req.c:1776:5: 
1774.   #endif
1775.   
1776. >     rv = do_sign_init(mctx, pkey, md, sigopts);
1777.       if (rv > 0)
1778.           rv = X509_REQ_sign_ctx(x, mctx);

apps/req.c:1680:1: start of procedure do_sign_init()
  1678.   #endif
  1679.   
  1680. > static int do_sign_init(EVP_MD_CTX *ctx, EVP_PKEY *pkey,
  1681.                           const EVP_MD *md, STACK_OF(OPENSSL_STRING) *sigopts)
  1682.   {

apps/req.c:1683:5: 
  1681.                           const EVP_MD *md, STACK_OF(OPENSSL_STRING) *sigopts)
  1682.   {
  1683. >     EVP_PKEY_CTX *pkctx = NULL;
  1684.   #ifndef OPENSSL_NO_SM2
  1685.       EVP_PKEY_CTX *pctx = NULL;

apps/req.c:1685:5: 
  1683.       EVP_PKEY_CTX *pkctx = NULL;
  1684.   #ifndef OPENSSL_NO_SM2
  1685. >     EVP_PKEY_CTX *pctx = NULL;
  1686.   #endif
  1687.       int i, def_nid, ret = 0;

apps/req.c:1687:5: 
  1685.       EVP_PKEY_CTX *pctx = NULL;
  1686.   #endif
  1687. >     int i, def_nid, ret = 0;
  1688.   
  1689.       if (ctx == NULL)

apps/req.c:1689:9: Taking true branch
  1687.       int i, def_nid, ret = 0;
  1688.   
  1689.       if (ctx == NULL)
                  ^
  1690.           goto err;
  1691.   #ifndef OPENSSL_NO_SM2

apps/req.c:1736:2: 
  1734.   
  1735.       ret = 1;
  1736. >  err:
  1737.   #ifndef OPENSSL_NO_SM2
  1738.       if (!ret)

apps/req.c:1738:10: Taking true branch
  1736.    err:
  1737.   #ifndef OPENSSL_NO_SM2
  1738.       if (!ret)
                   ^
  1739.           EVP_PKEY_CTX_free(pctx);
  1740.   #endif

apps/req.c:1739:9: 
  1737.   #ifndef OPENSSL_NO_SM2
  1738.       if (!ret)
  1739. >         EVP_PKEY_CTX_free(pctx);
  1740.   #endif
  1741.       return ret;

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 true 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:355:9: 
    353.   {
    354.       if (ctx == NULL)
    355. >         return;
    356.       if (ctx->pmeth && ctx->pmeth->cleanup)
    357.           ctx->pmeth->cleanup(ctx);

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,

apps/req.c:1741:5: 
  1739.           EVP_PKEY_CTX_free(pctx);
  1740.   #endif
  1741. >     return ret;
  1742.   }
  1743.   

apps/req.c:1742:1: return from a call to do_sign_init
  1740.   #endif
  1741.       return ret;
  1742. > }
  1743.   
  1744.   int do_X509_sign(X509 *x, EVP_PKEY *pkey, const EVP_MD *md,

apps/req.c:1777:9: Taking false branch
1775.   
1776.       rv = do_sign_init(mctx, pkey, md, sigopts);
1777.       if (rv > 0)
                ^
1778.           rv = X509_REQ_sign_ctx(x, mctx);
1779.   #ifndef OPENSSL_NO_SM2

apps/req.c:1781:9: 
1779.   #ifndef OPENSSL_NO_SM2
1780.       /* only in SM2 case we need to free the pctx explicitly */
1781. >     if (ec_pkey_is_sm2(pkey)) {
1782.           pctx = EVP_MD_CTX_pkey_ctx(mctx);
1783.           EVP_PKEY_CTX_free(pctx);

apps/req.c:1664:1: start of procedure ec_pkey_is_sm2()
  1662.   
  1663.   #ifndef OPENSSL_NO_SM2
  1664. > static int ec_pkey_is_sm2(EVP_PKEY *pkey)
  1665.   {
  1666.       EC_KEY *eckey = NULL;

apps/req.c:1666:5: 
  1664.   static int ec_pkey_is_sm2(EVP_PKEY *pkey)
  1665.   {
  1666. >     EC_KEY *eckey = NULL;
  1667.       const EC_GROUP *group = NULL;
  1668.   

apps/req.c:1667:5: 
  1665.   {
  1666.       EC_KEY *eckey = NULL;
  1667. >     const EC_GROUP *group = NULL;
  1668.   
  1669.       if (EVP_PKEY_id(pkey) == EVP_PKEY_SM2)

apps/req.c:1669:9: 
  1667.       const EC_GROUP *group = NULL;
  1668.   
  1669. >     if (EVP_PKEY_id(pkey) == EVP_PKEY_SM2)
  1670.           return 1;
  1671.       if (EVP_PKEY_id(pkey) == EVP_PKEY_EC

crypto/evp/p_lib.c:585:1: start of procedure EVP_PKEY_id()
    583.   }
    584.   
    585. > int EVP_PKEY_id(const EVP_PKEY *pkey)
    586.   {
    587.       return pkey->type;

crypto/evp/p_lib.c:587:5: 
    585.   int EVP_PKEY_id(const EVP_PKEY *pkey)
    586.   {
    587. >     return pkey->type;
    588.   }
    589.   

crypto/evp/p_lib.c:588:1: return from a call to EVP_PKEY_id
    586.   {
    587.       return pkey->type;
    588. > }
    589.   
    590.   int EVP_PKEY_base_id(const EVP_PKEY *pkey)

apps/req.c:1669:9: Taking false branch
  1667.       const EC_GROUP *group = NULL;
  1668.   
  1669.       if (EVP_PKEY_id(pkey) == EVP_PKEY_SM2)
                  ^
  1670.           return 1;
  1671.       if (EVP_PKEY_id(pkey) == EVP_PKEY_EC

apps/req.c:1671:9: 
  1669.       if (EVP_PKEY_id(pkey) == EVP_PKEY_SM2)
  1670.           return 1;
  1671. >     if (EVP_PKEY_id(pkey) == EVP_PKEY_EC
  1672.               && (eckey = EVP_PKEY_get0_EC_KEY(pkey)) != NULL
  1673.               && (group = EC_KEY_get0_group(eckey)) != NULL

crypto/evp/p_lib.c:585:1: start of procedure EVP_PKEY_id()
    583.   }
    584.   
    585. > int EVP_PKEY_id(const EVP_PKEY *pkey)
    586.   {
    587.       return pkey->type;

crypto/evp/p_lib.c:587:5: 
    585.   int EVP_PKEY_id(const EVP_PKEY *pkey)
    586.   {
    587. >     return pkey->type;
    588.   }
    589.   

crypto/evp/p_lib.c:588:1: return from a call to EVP_PKEY_id
    586.   {
    587.       return pkey->type;
    588. > }
    589.   
    590.   int EVP_PKEY_base_id(const EVP_PKEY *pkey)

apps/req.c:1671:9: Taking true branch
  1669.       if (EVP_PKEY_id(pkey) == EVP_PKEY_SM2)
  1670.           return 1;
  1671.       if (EVP_PKEY_id(pkey) == EVP_PKEY_EC
                  ^
  1672.               && (eckey = EVP_PKEY_get0_EC_KEY(pkey)) != NULL
  1673.               && (group = EC_KEY_get0_group(eckey)) != NULL

apps/req.c:1672:16: 
  1670.           return 1;
  1671.       if (EVP_PKEY_id(pkey) == EVP_PKEY_EC
  1672. >             && (eckey = EVP_PKEY_get0_EC_KEY(pkey)) != NULL
  1673.               && (group = EC_KEY_get0_group(eckey)) != NULL
  1674.               && EC_GROUP_get_curve_name(group) == NID_sm2)

crypto/evp/p_lib.c:523:1: start of procedure EVP_PKEY_get0_EC_KEY()
    521.   }
    522.   
    523. > EC_KEY *EVP_PKEY_get0_EC_KEY(const EVP_PKEY *pkey)
    524.   {
    525.       if (pkey->type != EVP_PKEY_EC) {

crypto/evp/p_lib.c:525:9: Taking false branch
    523.   EC_KEY *EVP_PKEY_get0_EC_KEY(const EVP_PKEY *pkey)
    524.   {
    525.       if (pkey->type != EVP_PKEY_EC) {
                   ^
    526.           EVPerr(EVP_F_EVP_PKEY_GET0_EC_KEY, EVP_R_EXPECTING_A_EC_KEY);
    527.           return NULL;

crypto/evp/p_lib.c:529:5: 
    527.           return NULL;
    528.       }
    529. >     return pkey->pkey.ec;
    530.   }
    531.   

crypto/evp/p_lib.c:530:1: return from a call to EVP_PKEY_get0_EC_KEY
    528.       }
    529.       return pkey->pkey.ec;
    530. > }
    531.   
    532.   EC_KEY *EVP_PKEY_get1_EC_KEY(EVP_PKEY *pkey)

apps/req.c:1672:16: Taking true branch
  1670.           return 1;
  1671.       if (EVP_PKEY_id(pkey) == EVP_PKEY_EC
  1672.               && (eckey = EVP_PKEY_get0_EC_KEY(pkey)) != NULL
                         ^
  1673.               && (group = EC_KEY_get0_group(eckey)) != NULL
  1674.               && EC_GROUP_get_curve_name(group) == NID_sm2)

apps/req.c:1673:16: 
  1671.       if (EVP_PKEY_id(pkey) == EVP_PKEY_EC
  1672.               && (eckey = EVP_PKEY_get0_EC_KEY(pkey)) != NULL
  1673. >             && (group = EC_KEY_get0_group(eckey)) != NULL
  1674.               && EC_GROUP_get_curve_name(group) == NID_sm2)
  1675.           return 1;

crypto/ec/ec_key.c:494:1: start of procedure EC_KEY_get0_group()
    492.   }
    493.   
    494. > const EC_GROUP *EC_KEY_get0_group(const EC_KEY *key)
    495.   {
    496.       return key->group;

crypto/ec/ec_key.c:496:5: 
    494.   const EC_GROUP *EC_KEY_get0_group(const EC_KEY *key)
    495.   {
    496. >     return key->group;
    497.   }
    498.   

crypto/ec/ec_key.c:497:1: return from a call to EC_KEY_get0_group
    495.   {
    496.       return key->group;
    497. > }
    498.   
    499.   int EC_KEY_set_group(EC_KEY *key, const EC_GROUP *group)

apps/req.c:1673:16: Taking true branch
  1671.       if (EVP_PKEY_id(pkey) == EVP_PKEY_EC
  1672.               && (eckey = EVP_PKEY_get0_EC_KEY(pkey)) != NULL
  1673.               && (group = EC_KEY_get0_group(eckey)) != NULL
                         ^
  1674.               && EC_GROUP_get_curve_name(group) == NID_sm2)
  1675.           return 1;

apps/req.c:1674:16: 
  1672.               && (eckey = EVP_PKEY_get0_EC_KEY(pkey)) != NULL
  1673.               && (group = EC_KEY_get0_group(eckey)) != NULL
  1674. >             && EC_GROUP_get_curve_name(group) == NID_sm2)
  1675.           return 1;
  1676.       return 0;

crypto/ec/ec_lib.c:364:1: start of procedure EC_GROUP_get_curve_name()
    362.   }
    363.   
    364. > int EC_GROUP_get_curve_name(const EC_GROUP *group)
    365.   {
    366.       return group->curve_name;

crypto/ec/ec_lib.c:366:5: 
    364.   int EC_GROUP_get_curve_name(const EC_GROUP *group)
    365.   {
    366. >     return group->curve_name;
    367.   }
    368.   

crypto/ec/ec_lib.c:367:1: return from a call to EC_GROUP_get_curve_name
    365.   {
    366.       return group->curve_name;
    367. > }
    368.   
    369.   const BIGNUM *EC_GROUP_get0_field(const EC_GROUP *group)

apps/req.c:1674:16: Taking true branch
  1672.               && (eckey = EVP_PKEY_get0_EC_KEY(pkey)) != NULL
  1673.               && (group = EC_KEY_get0_group(eckey)) != NULL
  1674.               && EC_GROUP_get_curve_name(group) == NID_sm2)
                         ^
  1675.           return 1;
  1676.       return 0;

apps/req.c:1675:9: 
  1673.               && (group = EC_KEY_get0_group(eckey)) != NULL
  1674.               && EC_GROUP_get_curve_name(group) == NID_sm2)
  1675. >         return 1;
  1676.       return 0;
  1677.   }

apps/req.c:1677:1: return from a call to ec_pkey_is_sm2
  1675.           return 1;
  1676.       return 0;
  1677. > }
  1678.   #endif
  1679.   

apps/req.c:1781:9: Taking true branch
1779.   #ifndef OPENSSL_NO_SM2
1780.       /* only in SM2 case we need to free the pctx explicitly */
1781.       if (ec_pkey_is_sm2(pkey)) {
                ^
1782.           pctx = EVP_MD_CTX_pkey_ctx(mctx);
1783.           EVP_PKEY_CTX_free(pctx);

apps/req.c:1782:9: 
1780.       /* only in SM2 case we need to free the pctx explicitly */
1781.       if (ec_pkey_is_sm2(pkey)) {
1782. >         pctx = EVP_MD_CTX_pkey_ctx(mctx);
1783.           EVP_PKEY_CTX_free(pctx);
1784.       }

crypto/evp/evp_lib.c:602:1: start of procedure EVP_MD_CTX_pkey_ctx()
  600.   }
  601.   
  602. > EVP_PKEY_CTX *EVP_MD_CTX_pkey_ctx(const EVP_MD_CTX *ctx)
  603.   {
  604.       return ctx->pctx;

crypto/evp/evp_lib.c:604:5: 
  602.   EVP_PKEY_CTX *EVP_MD_CTX_pkey_ctx(const EVP_MD_CTX *ctx)
  603.   {
  604. >     return ctx->pctx;
  605.   }
  606.   

int do_X509_REQ_sign(X509_REQ *x, EVP_PKEY *pkey, const EVP_MD *md,
                     STACK_OF(OPENSSL_STRING) *sigopts)
{
    int rv;
    EVP_MD_CTX *mctx = EVP_MD_CTX_new();
#ifndef OPENSSL_NO_SM2
    EVP_PKEY_CTX *pctx = NULL;
#endif
    rv = do_sign_init(mctx, pkey, md, sigopts);
    if (rv > 0)
        rv = X509_REQ_sign_ctx(x, mctx);
#ifndef OPENSSL_NO_SM2
    if (ec_pkey_is_sm2(pkey)) {
        pctx = EVP_MD_CTX_pkey_ctx(mctx);
        EVP_PKEY_CTX_free(pctx);
    }
#endif
    EVP_MD_CTX_free(mctx);
    return rv > 0 ? 1 : 0;
}
['int do_X509_REQ_sign(X509_REQ *x, EVP_PKEY *pkey, const EVP_MD *md,\n                     STACK_OF(OPENSSL_STRING) *sigopts)\n{\n    int rv;\n    EVP_MD_CTX *mctx = EVP_MD_CTX_new();\n#ifndef OPENSSL_NO_SM2\n    EVP_PKEY_CTX *pctx = NULL;\n#endif\n    rv = do_sign_init(mctx, pkey, md, sigopts);\n    if (rv > 0)\n        rv = X509_REQ_sign_ctx(x, mctx);\n#ifndef OPENSSL_NO_SM2\n    if (ec_pkey_is_sm2(pkey)) {\n        pctx = EVP_MD_CTX_pkey_ctx(mctx);\n        EVP_PKEY_CTX_free(pctx);\n    }\n#endif\n    EVP_MD_CTX_free(mctx);\n    return rv > 0 ? 1 : 0;\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#if !defined(OPENSSL_NO_CRYPTO_MDEBUG) && !defined(FIPS_MODE)\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}', 'static int do_sign_init(EVP_MD_CTX *ctx, EVP_PKEY *pkey,\n                        const EVP_MD *md, STACK_OF(OPENSSL_STRING) *sigopts)\n{\n    EVP_PKEY_CTX *pkctx = NULL;\n#ifndef OPENSSL_NO_SM2\n    EVP_PKEY_CTX *pctx = NULL;\n#endif\n    int i, def_nid, ret = 0;\n    if (ctx == NULL)\n        goto err;\n#ifndef OPENSSL_NO_SM2\n    if (ec_pkey_is_sm2(pkey)) {\n        if (!EVP_PKEY_set_alias_type(pkey, EVP_PKEY_SM2)) {\n            BIO_printf(bio_err, "Internal error.\\n");\n            goto err;\n        }\n        pctx = EVP_PKEY_CTX_new(pkey, NULL);\n        if (pctx == NULL) {\n            BIO_printf(bio_err, "memory allocation failure.\\n");\n            goto err;\n        }\n        for (i = 0; i < sk_OPENSSL_STRING_num(sigopts); i++) {\n            char *sigopt = sk_OPENSSL_STRING_value(sigopts, i);\n            if (pkey_ctrl_string(pctx, sigopt) <= 0) {\n                BIO_printf(bio_err, "parameter error \\"%s\\"\\n", sigopt);\n                ERR_print_errors(bio_err);\n                goto err;\n            }\n        }\n        EVP_MD_CTX_set_pkey_ctx(ctx, pctx);\n    }\n#endif\n    if (EVP_PKEY_get_default_digest_nid(pkey, &def_nid) == 2\n            && def_nid == NID_undef) {\n        md = NULL;\n    }\n    if (!EVP_DigestSignInit(ctx, &pkctx, md, NULL, pkey))\n        goto err;\n    for (i = 0; i < sk_OPENSSL_STRING_num(sigopts); i++) {\n        char *sigopt = sk_OPENSSL_STRING_value(sigopts, i);\n        if (pkey_ctrl_string(pkctx, sigopt) <= 0) {\n            BIO_printf(bio_err, "parameter error \\"%s\\"\\n", sigopt);\n            ERR_print_errors(bio_err);\n            goto err;\n        }\n    }\n    ret = 1;\n err:\n#ifndef OPENSSL_NO_SM2\n    if (!ret)\n        EVP_PKEY_CTX_free(pctx);\n#endif\n    return ret;\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}', 'static int ec_pkey_is_sm2(EVP_PKEY *pkey)\n{\n    EC_KEY *eckey = NULL;\n    const EC_GROUP *group = NULL;\n    if (EVP_PKEY_id(pkey) == EVP_PKEY_SM2)\n        return 1;\n    if (EVP_PKEY_id(pkey) == EVP_PKEY_EC\n            && (eckey = EVP_PKEY_get0_EC_KEY(pkey)) != NULL\n            && (group = EC_KEY_get0_group(eckey)) != NULL\n            && EC_GROUP_get_curve_name(group) == NID_sm2)\n        return 1;\n    return 0;\n}', 'int EVP_PKEY_id(const EVP_PKEY *pkey)\n{\n    return pkey->type;\n}', 'EC_KEY *EVP_PKEY_get0_EC_KEY(const EVP_PKEY *pkey)\n{\n    if (pkey->type != EVP_PKEY_EC) {\n        EVPerr(EVP_F_EVP_PKEY_GET0_EC_KEY, EVP_R_EXPECTING_A_EC_KEY);\n        return NULL;\n    }\n    return pkey->pkey.ec;\n}', 'const EC_GROUP *EC_KEY_get0_group(const EC_KEY *key)\n{\n    return key->group;\n}', 'int EC_GROUP_get_curve_name(const EC_GROUP *group)\n{\n    return group->curve_name;\n}', 'EVP_PKEY_CTX *EVP_MD_CTX_pkey_ctx(const EVP_MD_CTX *ctx)\n{\n    return ctx->pctx;\n}']