src/web_adaptor/httpauth.c
void digest_calc_response(
			hashhex_t ha1,          /* H(A1) */
			char *nonce,            /* nonce from server */
			char *nonce_count,      /* 8 hex digits */
			char *cnonce,           /* client nonce */
			char *qop,              /* qop-value: "", "auth", "auth-int" */
			char *method,           /* method from the request */
			char *digest_uri,       /* requested URL */
			hashhex_t h_entity,     /* H(entity body) if qop="auth-int" */
			hashhex_t response      /* OUT request-digest or response-digest */
			)
{
	md5context_t md5ctx;
	hash_t ha2;
	hash_t resp_hash;
	hashhex_t ha2hex;
	
	// calculate H(A2)
	md5_init(&md5ctx);
	md5_update(&md5ctx, method, strlen(method));
	md5_update(&md5ctx, ":", 1);
	md5_update(&md5ctx, digest_uri, strlen(digest_uri));
	if (strcasecmp(qop, "auth-int") == 0)
    {
		md5_update(&md5ctx, ":", 1);
		md5_update(&md5ctx, h_entity, HASHHEXLEN);
	};
	md5_final(ha2, &md5ctx);
	cvthex(ha2, ha2hex);
	
	// calculate response
	md5_init(&md5ctx);
	md5_update(&md5ctx, ha1, HASHHEXLEN);
	md5_update(&md5ctx, ":", 1);
	md5_update(&md5ctx, nonce, strlen(nonce));
	md5_update(&md5ctx, ":", 1);
    if (*qop)
    {
		md5_update(&md5ctx, nonce_count, strlen(nonce_count));
		md5_update(&md5ctx, ":", 1);
		md5_update(&md5ctx, cnonce, strlen(cnonce));
		md5_update(&md5ctx, ":", 1);
		md5_update(&md5ctx, qop, strlen(qop));
		md5_update(&md5ctx, ":", 1);
	};
	md5_update(&md5ctx, ha2hex, HASHHEXLEN);
	md5_final(resp_hash, &md5ctx);
	cvthex(resp_hash, response);
}
/* calculate request-digest/response-digest as per HTTP Digest spec */
calculate request-digest/response-digest as per HTTP Digest spec
calculate request - digest / response - digest as per HTTP Digest spec
void digest_calc_response(
			hashhex_t ha1,          
			char *nonce,            
			char *nonce_count,      
			char *cnonce,           
			char *qop,              
			char *method,           
			char *digest_uri,       
			hashhex_t h_entity,     
			hashhex_t response      
			)
{
	md5context_t md5ctx;
	hash_t ha2;
	hash_t resp_hash;
	hashhex_t ha2hex;
	md5_init(&md5ctx);
	md5_update(&md5ctx, method, strlen(method));
	md5_update(&md5ctx, ":", 1);
	md5_update(&md5ctx, digest_uri, strlen(digest_uri));
	if (strcasecmp(qop, "auth-int") == 0)
    {
		md5_update(&md5ctx, ":", 1);
		md5_update(&md5ctx, h_entity, HASHHEXLEN);
	};
	md5_final(ha2, &md5ctx);
	cvthex(ha2, ha2hex);
	md5_init(&md5ctx);
	md5_update(&md5ctx, ha1, HASHHEXLEN);
	md5_update(&md5ctx, ":", 1);
	md5_update(&md5ctx, nonce, strlen(nonce));
	md5_update(&md5ctx, ":", 1);
    if (*qop)
    {
		md5_update(&md5ctx, nonce_count, strlen(nonce_count));
		md5_update(&md5ctx, ":", 1);
		md5_update(&md5ctx, cnonce, strlen(cnonce));
		md5_update(&md5ctx, ":", 1);
		md5_update(&md5ctx, qop, strlen(qop));
		md5_update(&md5ctx, ":", 1);
	};
	md5_update(&md5ctx, ha2hex, HASHHEXLEN);
	md5_final(resp_hash, &md5ctx);
	cvthex(resp_hash, response);
}
void digest_calc_response ( hashhex_t ha1 , char * nonce , char * nonce_count , char * cnonce , char * qop , char * method , char * digest_uri , hashhex_t h_entity , hashhex_t response ) { md5context_t md5ctx ; hash_t ha2 ; hash_t resp_hash ; hashhex_t ha2hex ; md5_init ( & md5ctx ) ; md5_update ( & md5ctx , method , strlen ( method ) ) ; md5_update ( & md5ctx , " " , 1 ) ; md5_update ( & md5ctx , digest_uri , strlen ( digest_uri ) ) ; if ( strcasecmp ( qop , " " ) == 0 ) { md5_update ( & md5ctx , " " , 1 ) ; md5_update ( & md5ctx , h_entity , HASHHEXLEN ) ; } ; md5_final ( ha2 , & md5ctx ) ; cvthex ( ha2 , ha2hex ) ; md5_init ( & md5ctx ) ; md5_update ( & md5ctx , ha1 , HASHHEXLEN ) ; md5_update ( & md5ctx , " " , 1 ) ; md5_update ( & md5ctx , nonce , strlen ( nonce ) ) ; md5_update ( & md5ctx , " " , 1 ) ; if ( * qop ) { md5_update ( & md5ctx , nonce_count , strlen ( nonce_count ) ) ; md5_update ( & md5ctx , " " , 1 ) ; md5_update ( & md5ctx , cnonce , strlen ( cnonce ) ) ; md5_update ( & md5ctx , " " , 1 ) ; md5_update ( & md5ctx , qop , strlen ( qop ) ) ; md5_update ( & md5ctx , " " , 1 ) ; } ; md5_update ( & md5ctx , ha2hex , HASHHEXLEN ) ; md5_final ( resp_hash , & md5ctx ) ; cvthex ( resp_hash , response ) ; }
calculate request-digest/response-digest as per HTTP Digest spec
calculate request - digest / response - digest as per HTTP Digest spec
/* H(A1) */ /* nonce from server */ /* 8 hex digits */ /* client nonce */ /* qop-value: "", "auth", "auth-int" */ /* method from the request */ /* requested URL */ /* H(entity body) if qop="auth-int" */ /* OUT request-digest or response-digest */ // calculate H(A2) // calculate response