static char *make_digest_auth(HTTPAuthState *state, const char *username,

                              const char *password, const char *uri,

                              const char *method)

{

    DigestParams *digest = &state->digest_params;

    int len;

    uint32_t cnonce_buf[2];

    char cnonce[17];

    char nc[9];

    int i;

    char A1hash[33], A2hash[33], response[33];

    struct AVMD5 *md5ctx;

    uint8_t hash[16];

    char *authstr;



    digest->nc++;

    snprintf(nc, sizeof(nc), "%08x", digest->nc);



    /* Generate a client nonce. */

    for (i = 0; i < 2; i++)

        cnonce_buf[i] = av_get_random_seed();

    ff_data_to_hex(cnonce, (const uint8_t*) cnonce_buf, sizeof(cnonce_buf), 1);

    cnonce[2*sizeof(cnonce_buf)] = 0;



    md5ctx = av_md5_alloc();

    if (!md5ctx)

        return NULL;



    av_md5_init(md5ctx);

    update_md5_strings(md5ctx, username, ":", state->realm, ":", password, NULL);

    av_md5_final(md5ctx, hash);

    ff_data_to_hex(A1hash, hash, 16, 1);

    A1hash[32] = 0;



    if (!strcmp(digest->algorithm, "") || !strcmp(digest->algorithm, "MD5")) {

    } else if (!strcmp(digest->algorithm, "MD5-sess")) {

        av_md5_init(md5ctx);

        update_md5_strings(md5ctx, A1hash, ":", digest->nonce, ":", cnonce, NULL);

        av_md5_final(md5ctx, hash);

        ff_data_to_hex(A1hash, hash, 16, 1);

        A1hash[32] = 0;

    } else {

        /* Unsupported algorithm */

        av_free(md5ctx);

        return NULL;

    }



    av_md5_init(md5ctx);

    update_md5_strings(md5ctx, method, ":", uri, NULL);

    av_md5_final(md5ctx, hash);

    ff_data_to_hex(A2hash, hash, 16, 1);

    A2hash[32] = 0;



    av_md5_init(md5ctx);

    update_md5_strings(md5ctx, A1hash, ":", digest->nonce, NULL);

    if (!strcmp(digest->qop, "auth") || !strcmp(digest->qop, "auth-int")) {

        update_md5_strings(md5ctx, ":", nc, ":", cnonce, ":", digest->qop, NULL);

    }

    update_md5_strings(md5ctx, ":", A2hash, NULL);

    av_md5_final(md5ctx, hash);

    ff_data_to_hex(response, hash, 16, 1);

    response[32] = 0;



    av_free(md5ctx);



    if (!strcmp(digest->qop, "") || !strcmp(digest->qop, "auth")) {

    } else if (!strcmp(digest->qop, "auth-int")) {

        /* qop=auth-int not supported */

        return NULL;

    } else {

        /* Unsupported qop value. */

        return NULL;

    }



    len = strlen(username) + strlen(state->realm) + strlen(digest->nonce) +

              strlen(uri) + strlen(response) + strlen(digest->algorithm) +

              strlen(digest->opaque) + strlen(digest->qop) + strlen(cnonce) +

              strlen(nc) + 150;



    authstr = av_malloc(len);

    if (!authstr)

        return NULL;

    snprintf(authstr, len, "Authorization: Digest ");



    /* TODO: Escape the quoted strings properly. */

    av_strlcatf(authstr, len, "username=\"%s\"",   username);

    av_strlcatf(authstr, len, ",realm=\"%s\"",     state->realm);

    av_strlcatf(authstr, len, ",nonce=\"%s\"",     digest->nonce);

    av_strlcatf(authstr, len, ",uri=\"%s\"",       uri);

    av_strlcatf(authstr, len, ",response=\"%s\"",  response);

    if (digest->algorithm[0])

        av_strlcatf(authstr, len, ",algorithm=%s",  digest->algorithm);

    if (digest->opaque[0])

        av_strlcatf(authstr, len, ",opaque=\"%s\"", digest->opaque);

    if (digest->qop[0]) {

        av_strlcatf(authstr, len, ",qop=\"%s\"",    digest->qop);

        av_strlcatf(authstr, len, ",cnonce=\"%s\"", cnonce);

        av_strlcatf(authstr, len, ",nc=%s",         nc);

    }



    av_strlcatf(authstr, len, "\r\n");



    return authstr;

}

static char *make_digest_auth(HTTPAuthState *state, const char *username,

                              const char *password, const char *uri,

                              const char *method)

{

    DigestParams *digest = &state->digest_params;

    int len;

    uint32_t cnonce_buf[2];

    char cnonce[17];

    char nc[9];

    int i;

    char A1hash[33], A2hash[33], response[33];

    struct AVMD5 *md5ctx;

    uint8_t hash[16];

    char *authstr;



    digest->nc++;

    snprintf(nc, sizeof(nc), "%08x", digest->nc);



    

    for (i = 0; i < 2; i++)

        cnonce_buf[i] = av_get_random_seed();

    ff_data_to_hex(cnonce, (const uint8_t*) cnonce_buf, sizeof(cnonce_buf), 1);

    cnonce[2*sizeof(cnonce_buf)] = 0;



    md5ctx = av_md5_alloc();

    if (!md5ctx)

        return NULL;



    av_md5_init(md5ctx);

    update_md5_strings(md5ctx, username, ":", state->realm, ":", password, NULL);

    av_md5_final(md5ctx, hash);

    ff_data_to_hex(A1hash, hash, 16, 1);

    A1hash[32] = 0;



    if (!strcmp(digest->algorithm, "") || !strcmp(digest->algorithm, "MD5")) {

    } else if (!strcmp(digest->algorithm, "MD5-sess")) {

        av_md5_init(md5ctx);

        update_md5_strings(md5ctx, A1hash, ":", digest->nonce, ":", cnonce, NULL);

        av_md5_final(md5ctx, hash);

        ff_data_to_hex(A1hash, hash, 16, 1);

        A1hash[32] = 0;

    } else {

        

        av_free(md5ctx);

        return NULL;

    }



    av_md5_init(md5ctx);

    update_md5_strings(md5ctx, method, ":", uri, NULL);

    av_md5_final(md5ctx, hash);

    ff_data_to_hex(A2hash, hash, 16, 1);

    A2hash[32] = 0;



    av_md5_init(md5ctx);

    update_md5_strings(md5ctx, A1hash, ":", digest->nonce, NULL);

    if (!strcmp(digest->qop, "auth") || !strcmp(digest->qop, "auth-int")) {

        update_md5_strings(md5ctx, ":", nc, ":", cnonce, ":", digest->qop, NULL);

    }

    update_md5_strings(md5ctx, ":", A2hash, NULL);

    av_md5_final(md5ctx, hash);

    ff_data_to_hex(response, hash, 16, 1);

    response[32] = 0;



    av_free(md5ctx);



    if (!strcmp(digest->qop, "") || !strcmp(digest->qop, "auth")) {

    } else if (!strcmp(digest->qop, "auth-int")) {

        

        return NULL;

    } else {

        

        return NULL;

    }



    len = strlen(username) + strlen(state->realm) + strlen(digest->nonce) +

              strlen(uri) + strlen(response) + strlen(digest->algorithm) +

              strlen(digest->opaque) + strlen(digest->qop) + strlen(cnonce) +

              strlen(nc) + 150;



    authstr = av_malloc(len);

    if (!authstr)

        return NULL;

    snprintf(authstr, len, "Authorization: Digest ");



    

    av_strlcatf(authstr, len, "username=\"%s\"",   username);

    av_strlcatf(authstr, len, ",realm=\"%s\"",     state->realm);

    av_strlcatf(authstr, len, ",nonce=\"%s\"",     digest->nonce);

    av_strlcatf(authstr, len, ",uri=\"%s\"",       uri);

    av_strlcatf(authstr, len, ",response=\"%s\"",  response);

    if (digest->algorithm[0])

        av_strlcatf(authstr, len, ",algorithm=%s",  digest->algorithm);

    if (digest->opaque[0])

        av_strlcatf(authstr, len, ",opaque=\"%s\"", digest->opaque);

    if (digest->qop[0]) {

        av_strlcatf(authstr, len, ",qop=\"%s\"",    digest->qop);

        av_strlcatf(authstr, len, ",cnonce=\"%s\"", cnonce);

        av_strlcatf(authstr, len, ",nc=%s",         nc);

    }



    av_strlcatf(authstr, len, "\r\n");



    return authstr;

}

static char *FUNC_0(HTTPAuthState *VAR_0, const char *VAR_1,

                              const char *VAR_2, const char *VAR_3,

                              const char *VAR_4)

{

    DigestParams *digest = &VAR_0->digest_params;

    int VAR_5;

    uint32_t cnonce_buf[2];

    char VAR_6[17];

    char VAR_7[9];

    int VAR_8;

    char VAR_9[33], VAR_10[33], VAR_11[33];

    struct AVMD5 *VAR_12;

    uint8_t hash[16];

    char *VAR_13;



    digest->VAR_7++;

    snprintf(VAR_7, sizeof(VAR_7), "%08x", digest->VAR_7);



    

    for (VAR_8 = 0; VAR_8 < 2; VAR_8++)

        cnonce_buf[VAR_8] = av_get_random_seed();

    ff_data_to_hex(VAR_6, (const uint8_t*) cnonce_buf, sizeof(cnonce_buf), 1);

    VAR_6[2*sizeof(cnonce_buf)] = 0;



    VAR_12 = av_md5_alloc();

    if (!VAR_12)

        return NULL;



    av_md5_init(VAR_12);

    update_md5_strings(VAR_12, VAR_1, ":", VAR_0->realm, ":", VAR_2, NULL);

    av_md5_final(VAR_12, hash);

    ff_data_to_hex(VAR_9, hash, 16, 1);

    VAR_9[32] = 0;



    if (!strcmp(digest->algorithm, "") || !strcmp(digest->algorithm, "MD5")) {

    } else if (!strcmp(digest->algorithm, "MD5-sess")) {

        av_md5_init(VAR_12);

        update_md5_strings(VAR_12, VAR_9, ":", digest->nonce, ":", VAR_6, NULL);

        av_md5_final(VAR_12, hash);

        ff_data_to_hex(VAR_9, hash, 16, 1);

        VAR_9[32] = 0;

    } else {

        

        av_free(VAR_12);

        return NULL;

    }



    av_md5_init(VAR_12);

    update_md5_strings(VAR_12, VAR_4, ":", VAR_3, NULL);

    av_md5_final(VAR_12, hash);

    ff_data_to_hex(VAR_10, hash, 16, 1);

    VAR_10[32] = 0;



    av_md5_init(VAR_12);

    update_md5_strings(VAR_12, VAR_9, ":", digest->nonce, NULL);

    if (!strcmp(digest->qop, "auth") || !strcmp(digest->qop, "auth-int")) {

        update_md5_strings(VAR_12, ":", VAR_7, ":", VAR_6, ":", digest->qop, NULL);

    }

    update_md5_strings(VAR_12, ":", VAR_10, NULL);

    av_md5_final(VAR_12, hash);

    ff_data_to_hex(VAR_11, hash, 16, 1);

    VAR_11[32] = 0;



    av_free(VAR_12);



    if (!strcmp(digest->qop, "") || !strcmp(digest->qop, "auth")) {

    } else if (!strcmp(digest->qop, "auth-int")) {

        

        return NULL;

    } else {

        

        return NULL;

    }



    VAR_5 = strlen(VAR_1) + strlen(VAR_0->realm) + strlen(digest->nonce) +

              strlen(VAR_3) + strlen(VAR_11) + strlen(digest->algorithm) +

              strlen(digest->opaque) + strlen(digest->qop) + strlen(VAR_6) +

              strlen(VAR_7) + 150;



    VAR_13 = av_malloc(VAR_5);

    if (!VAR_13)

        return NULL;

    snprintf(VAR_13, VAR_5, "Authorization: Digest ");



    

    av_strlcatf(VAR_13, VAR_5, "VAR_1=\"%s\"",   VAR_1);

    av_strlcatf(VAR_13, VAR_5, ",realm=\"%s\"",     VAR_0->realm);

    av_strlcatf(VAR_13, VAR_5, ",nonce=\"%s\"",     digest->nonce);

    av_strlcatf(VAR_13, VAR_5, ",VAR_3=\"%s\"",       VAR_3);

    av_strlcatf(VAR_13, VAR_5, ",VAR_11=\"%s\"",  VAR_11);

    if (digest->algorithm[0])

        av_strlcatf(VAR_13, VAR_5, ",algorithm=%s",  digest->algorithm);

    if (digest->opaque[0])

        av_strlcatf(VAR_13, VAR_5, ",opaque=\"%s\"", digest->opaque);

    if (digest->qop[0]) {

        av_strlcatf(VAR_13, VAR_5, ",qop=\"%s\"",    digest->qop);

        av_strlcatf(VAR_13, VAR_5, ",VAR_6=\"%s\"", VAR_6);

        av_strlcatf(VAR_13, VAR_5, ",VAR_7=%s",         VAR_7);

    }



    av_strlcatf(VAR_13, VAR_5, "\r\n");



    return VAR_13;

}

static char *FUNC_0(HTTPAuthState *VAR_0, const char *VAR_1,
const char *VAR_2, const char *VAR_3,
const char *VAR_4)
{ DigestParams *digest = &VAR_0->digest_params; int VAR_5; uint32_t cnonce_buf[2]; char VAR_6[17]; char VAR_7[9]; int VAR_8; char VAR_9[33], VAR_10[33], VAR_11[33]; struct AVMD5 *VAR_12; uint8_t hash[16]; char *VAR_13; digest->VAR_7++; snprintf(VAR_7, sizeof(VAR_7), "%08x", digest->VAR_7); for (VAR_8 = 0; VAR_8 < 2; VAR_8++) cnonce_buf[VAR_8] = av_get_random_seed(); ff_data_to_hex(VAR_6, (const uint8_t*) cnonce_buf, sizeof(cnonce_buf), 1); VAR_6[2*sizeof(cnonce_buf)] = 0; VAR_12 = av_md5_alloc(); if (!VAR_12)
return NULL; av_md5_init(VAR_12); update_md5_strings(VAR_12, VAR_1, ":", VAR_0->realm, ":", VAR_2, NULL); av_md5_final(VAR_12, hash); ff_data_to_hex(VAR_9, hash, 16, 1); VAR_9[32] = 0; if (!strcmp(digest->algorithm, "") || !strcmp(digest->algorithm, "MD5")) { } else if (!strcmp(digest->algorithm, "MD5-sess")) { av_md5_init(VAR_12); update_md5_strings(VAR_12, VAR_9, ":", digest->nonce, ":", VAR_6, NULL); av_md5_final(VAR_12, hash); ff_data_to_hex(VAR_9, hash, 16, 1); VAR_9[32] = 0; } else { av_free(VAR_12); return NULL; } av_md5_init(VAR_12); update_md5_strings(VAR_12, VAR_4, ":", VAR_3, NULL); av_md5_final(VAR_12, hash); ff_data_to_hex(VAR_10, hash, 16, 1); VAR_10[32] = 0; av_md5_init(VAR_12); update_md5_strings(VAR_12, VAR_9, ":", digest->nonce, NULL); if (!strcmp(digest->qop, "auth") || !strcmp(digest->qop, "auth-int")) { update_md5_strings(VAR_12, ":", VAR_7, ":", VAR_6, ":", digest->qop, NULL); } update_md5_strings(VAR_12, ":", VAR_10, NULL); av_md5_final(VAR_12, hash); ff_data_to_hex(VAR_11, hash, 16, 1); VAR_11[32] = 0; av_free(VAR_12); if (!strcmp(digest->qop, "") || !strcmp(digest->qop, "auth")) { } else if (!strcmp(digest->qop, "auth-int")) { return NULL; } else { return NULL; } VAR_5 = strlen(VAR_1) + strlen(VAR_0->realm) + strlen(digest->nonce) +
strlen(VAR_3) + strlen(VAR_11) + strlen(digest->algorithm) +
strlen(digest->opaque) + strlen(digest->qop) + strlen(VAR_6) +
strlen(VAR_7) + 150; VAR_13 = av_malloc(VAR_5); if (!VAR_13)
return NULL; snprintf(VAR_13, VAR_5, "Authorization: Digest "); av_strlcatf(VAR_13, VAR_5, "VAR_1=\"%s\"",   VAR_1); av_strlcatf(VAR_13, VAR_5, ",realm=\"%s\"",     VAR_0->realm); av_strlcatf(VAR_13, VAR_5, ",nonce=\"%s\"",     digest->nonce); av_strlcatf(VAR_13, VAR_5, ",VAR_3=\"%s\"",       VAR_3); av_strlcatf(VAR_13, VAR_5, ",VAR_11=\"%s\"",  VAR_11); if (digest->algorithm[0])
av_strlcatf(VAR_13, VAR_5, ",algorithm=%s",  digest->algorithm); if (digest->opaque[0])
av_strlcatf(VAR_13, VAR_5, ",opaque=\"%s\"", digest->opaque); if (digest->qop[0]) { av_strlcatf(VAR_13, VAR_5, ",qop=\"%s\"",    digest->qop); av_strlcatf(VAR_13, VAR_5, ",VAR_6=\"%s\"", VAR_6); av_strlcatf(VAR_13, VAR_5, ",VAR_7=%s",         VAR_7); } av_strlcatf(VAR_13, VAR_5, "\r\n"); return VAR_13; }