static void rtmp_calc_digest(const uint8_t *src, int len, int gap,
                             const uint8_t *key, int keylen, uint8_t *dst)
{
    struct AVSHA *sha;
    uint8_t hmac_buf[64+32] = {0};
    int i;
    sha = av_mallocz(av_sha_size);
    if (keylen < 64) {
        memcpy(hmac_buf, key, keylen);
    } else {
        av_sha_init(sha, 256);
        av_sha_update(sha,key, keylen);
        av_sha_final(sha, hmac_buf);
    }
    for (i = 0; i < 64; i++)
        hmac_buf[i] ^= HMAC_IPAD_VAL;
    av_sha_init(sha, 256);
    av_sha_update(sha, hmac_buf, 64);
    if (gap <= 0) {
        av_sha_update(sha, src, len);
    } else {
        av_sha_update(sha, src, gap);
        av_sha_update(sha, src + gap + 32, len - gap - 32);
    }
    av_sha_final(sha, hmac_buf + 64);
    for (i = 0; i < 64; i++)
        hmac_buf[i] ^= HMAC_IPAD_VAL ^ HMAC_OPAD_VAL;
    av_sha_init(sha, 256);
    av_sha_update(sha, hmac_buf, 64+32);
    av_sha_final(sha, dst);
    av_free(sha);
}
['static void rtmp_calc_digest(const uint8_t *src, int len, int gap,\n                             const uint8_t *key, int keylen, uint8_t *dst)\n{\n    struct AVSHA *sha;\n    uint8_t hmac_buf[64+32] = {0};\n    int i;\n    sha = av_mallocz(av_sha_size);\n    if (keylen < 64) {\n        memcpy(hmac_buf, key, keylen);\n    } else {\n        av_sha_init(sha, 256);\n        av_sha_update(sha,key, keylen);\n        av_sha_final(sha, hmac_buf);\n    }\n    for (i = 0; i < 64; i++)\n        hmac_buf[i] ^= HMAC_IPAD_VAL;\n    av_sha_init(sha, 256);\n    av_sha_update(sha, hmac_buf, 64);\n    if (gap <= 0) {\n        av_sha_update(sha, src, len);\n    } else {\n        av_sha_update(sha, src, gap);\n        av_sha_update(sha, src + gap + 32, len - gap - 32);\n    }\n    av_sha_final(sha, hmac_buf + 64);\n    for (i = 0; i < 64; i++)\n        hmac_buf[i] ^= HMAC_IPAD_VAL ^ HMAC_OPAD_VAL;\n    av_sha_init(sha, 256);\n    av_sha_update(sha, hmac_buf, 64+32);\n    av_sha_final(sha, dst);\n    av_free(sha);\n}', 'void *av_mallocz(size_t size)\n{\n    void *ptr = av_malloc(size);\n    if (ptr)\n        memset(ptr, 0, size);\n    return ptr;\n}', 'void *av_malloc(size_t size)\n{\n    void *ptr = NULL;\n#if CONFIG_MEMALIGN_HACK\n    long diff;\n#endif\n    assert(size);\n    if (size > (INT_MAX-32) || !size)\n        return NULL;\n#if CONFIG_MEMALIGN_HACK\n    ptr = malloc(size+32);\n    if(!ptr)\n        return ptr;\n    diff= ((-(long)ptr - 1)&31) + 1;\n    ptr = (char*)ptr + diff;\n    ((char*)ptr)[-1]= diff;\n#elif HAVE_POSIX_MEMALIGN\n    if (posix_memalign(&ptr,32,size))\n        ptr = NULL;\n#elif HAVE_MEMALIGN\n    ptr = memalign(32,size);\n#else\n    ptr = malloc(size);\n#endif\n    return ptr;\n}', 'int av_sha_init(AVSHA* ctx, int bits)\n{\n    ctx->digest_len = bits >> 5;\n    switch (bits) {\n    case 160:\n        ctx->state[0] = 0x67452301;\n        ctx->state[1] = 0xEFCDAB89;\n        ctx->state[2] = 0x98BADCFE;\n        ctx->state[3] = 0x10325476;\n        ctx->state[4] = 0xC3D2E1F0;\n        ctx->transform = sha1_transform;\n        break;\n    case 224:\n        ctx->state[0] = 0xC1059ED8;\n        ctx->state[1] = 0x367CD507;\n        ctx->state[2] = 0x3070DD17;\n        ctx->state[3] = 0xF70E5939;\n        ctx->state[4] = 0xFFC00B31;\n        ctx->state[5] = 0x68581511;\n        ctx->state[6] = 0x64F98FA7;\n        ctx->state[7] = 0xBEFA4FA4;\n        ctx->transform = sha256_transform;\n        break;\n    case 256:\n        ctx->state[0] = 0x6A09E667;\n        ctx->state[1] = 0xBB67AE85;\n        ctx->state[2] = 0x3C6EF372;\n        ctx->state[3] = 0xA54FF53A;\n        ctx->state[4] = 0x510E527F;\n        ctx->state[5] = 0x9B05688C;\n        ctx->state[6] = 0x1F83D9AB;\n        ctx->state[7] = 0x5BE0CD19;\n        ctx->transform = sha256_transform;\n        break;\n    default:\n        return -1;\n    }\n    ctx->count = 0;\n    return 0;\n}']