__einfo_uniqify ( EINFO_EACCES, 0x01, \
"No username available for Digest authentication" )
+/** An HTTP Digest algorithm context */
+struct http_digest_context {
+ /** MD5 context */
+ uint8_t md5[MD5_CTX_SIZE];
+ /** Length of colon field separator before next field */
+ size_t colon_len;
+};
+
/** An HTTP Digest "WWW-Authenticate" response field */
struct http_digest_field {
/** Name */
* @v ctx Digest context
* @v string Initial string
*/
-static void http_digest_init ( struct md5_context *ctx ) {
+static void http_digest_init ( struct http_digest_context *ctx ) {
/* Initialise MD5 digest */
- digest_init ( &md5_algorithm, ctx );
+ digest_init ( &md5_algorithm, ctx->md5 );
+
+ /* Omit colon before first field */
+ ctx->colon_len = 0;
}
/**
* @v ctx Digest context
* @v string String to append
*/
-static void http_digest_update ( struct md5_context *ctx, const char *string ) {
+static void http_digest_update ( struct http_digest_context *ctx,
+ const char *string ) {
static const char colon = ':';
/* Add (possibly colon-separated) field to MD5 digest */
- if ( ctx->len )
- digest_update ( &md5_algorithm, ctx, &colon, sizeof ( colon ) );
- digest_update ( &md5_algorithm, ctx, string, strlen ( string ) );
+ digest_update ( &md5_algorithm, ctx->md5, &colon, ctx->colon_len );
+ digest_update ( &md5_algorithm, ctx->md5, string, strlen ( string ) );
+
+ /* Include colon before any subsequent fields */
+ ctx->colon_len = sizeof ( colon );
}
/**
* @v out Buffer for digest output
* @v len Buffer length
*/
-static void http_digest_final ( struct md5_context *ctx, char *out,
+static void http_digest_final ( struct http_digest_context *ctx, char *out,
size_t len ) {
uint8_t digest[MD5_DIGEST_SIZE];
/* Finalise and base16-encode MD5 digest */
- digest_final ( &md5_algorithm, ctx, digest );
+ digest_final ( &md5_algorithm, ctx->md5, digest );
base16_encode ( digest, sizeof ( digest ), out, len );
}
char ha2[ base16_encoded_len ( MD5_DIGEST_SIZE ) + 1 /* NUL */ ];
static const char md5sess[] = "MD5-sess";
static const char md5[] = "MD5";
- struct md5_context ctx;
+ struct http_digest_context ctx;
const char *password;
/* Check for required response parameters */