static int SSHKDF(const EVP_MD *evp_md,
                  const unsigned char *key, size_t key_len,
                  const unsigned char *xcghash, size_t xcghash_len,
                  const unsigned char *session_id, size_t session_id_len,
                  char type, unsigned char *okey, size_t okey_len)
{
    EVP_MD_CTX *md = NULL;
    unsigned char digest[EVP_MAX_MD_SIZE];
    unsigned int dsize = 0;
    size_t cursize = 0;
    int ret = 0;
    md = EVP_MD_CTX_new();
    if (md == NULL)
        return 0;
    if (!EVP_DigestInit_ex(md, evp_md, NULL))
        goto out;
    if (!EVP_DigestUpdate(md, key, key_len))
        goto out;
    if (!EVP_DigestUpdate(md, xcghash, xcghash_len))
        goto out;
    if (!EVP_DigestUpdate(md, &type, 1))
        goto out;
    if (!EVP_DigestUpdate(md, session_id, session_id_len))
        goto out;
    if (!EVP_DigestFinal_ex(md, digest, &dsize))
        goto out;
    if (okey_len < dsize) {
        memcpy(okey, digest, okey_len);
        ret = 1;
        goto out;
    }
    memcpy(okey, digest, dsize);
    for (cursize = dsize; cursize < okey_len; cursize += dsize) {
        if (!EVP_DigestInit_ex(md, evp_md, NULL))
            goto out;
        if (!EVP_DigestUpdate(md, key, key_len))
            goto out;
        if (!EVP_DigestUpdate(md, xcghash, xcghash_len))
            goto out;
        if (!EVP_DigestUpdate(md, okey, cursize))
            goto out;
        if (!EVP_DigestFinal_ex(md, digest, &dsize))
            goto out;
        if (okey_len < cursize + dsize) {
            memcpy(okey + cursize, digest, okey_len - cursize);
            ret = 1;
            goto out;
        }
        memcpy(okey + cursize, digest, dsize);
    }
    ret = 1;
out:
    EVP_MD_CTX_free(md);
    OPENSSL_cleanse(digest, EVP_MAX_MD_SIZE);
    return ret;
}
['static int SSHKDF(const EVP_MD *evp_md,\n                  const unsigned char *key, size_t key_len,\n                  const unsigned char *xcghash, size_t xcghash_len,\n                  const unsigned char *session_id, size_t session_id_len,\n                  char type, unsigned char *okey, size_t okey_len)\n{\n    EVP_MD_CTX *md = NULL;\n    unsigned char digest[EVP_MAX_MD_SIZE];\n    unsigned int dsize = 0;\n    size_t cursize = 0;\n    int ret = 0;\n    md = EVP_MD_CTX_new();\n    if (md == NULL)\n        return 0;\n    if (!EVP_DigestInit_ex(md, evp_md, NULL))\n        goto out;\n    if (!EVP_DigestUpdate(md, key, key_len))\n        goto out;\n    if (!EVP_DigestUpdate(md, xcghash, xcghash_len))\n        goto out;\n    if (!EVP_DigestUpdate(md, &type, 1))\n        goto out;\n    if (!EVP_DigestUpdate(md, session_id, session_id_len))\n        goto out;\n    if (!EVP_DigestFinal_ex(md, digest, &dsize))\n        goto out;\n    if (okey_len < dsize) {\n        memcpy(okey, digest, okey_len);\n        ret = 1;\n        goto out;\n    }\n    memcpy(okey, digest, dsize);\n    for (cursize = dsize; cursize < okey_len; cursize += dsize) {\n        if (!EVP_DigestInit_ex(md, evp_md, NULL))\n            goto out;\n        if (!EVP_DigestUpdate(md, key, key_len))\n            goto out;\n        if (!EVP_DigestUpdate(md, xcghash, xcghash_len))\n            goto out;\n        if (!EVP_DigestUpdate(md, okey, cursize))\n            goto out;\n        if (!EVP_DigestFinal_ex(md, digest, &dsize))\n            goto out;\n        if (okey_len < cursize + dsize) {\n            memcpy(okey + cursize, digest, okey_len - cursize);\n            ret = 1;\n            goto out;\n        }\n        memcpy(okey + cursize, digest, dsize);\n    }\n    ret = 1;\nout:\n    EVP_MD_CTX_free(md);\n    OPENSSL_cleanse(digest, EVP_MAX_MD_SIZE);\n    return ret;\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}', 'int EVP_DigestUpdate(EVP_MD_CTX *ctx, const void *data, size_t count)\n{\n    return ctx->update(ctx, data, count);\n}', 'void EVP_MD_CTX_free(EVP_MD_CTX *ctx)\n{\n    EVP_MD_CTX_reset(ctx);\n    OPENSSL_free(ctx);\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}']