digest: support SHA-512/256

Also fix the tests. New implementation tested with GNU libmicrohttpd.
The new numbers in tests are real SHA-512/256 numbers (not just some
random ;) numbers ).
This commit is contained in:
Evgeny Grin 2024-02-08 10:31:12 +01:00 committed by Daniel Stenberg
parent 6d6113e122
commit e3461bbd05
No known key found for this signature in database
GPG key ID: 5CC908FDB71E12C2
5 changed files with 40 additions and 13 deletions

View file

@ -38,6 +38,7 @@
#include "curl_hmac.h"
#include "curl_md5.h"
#include "curl_sha256.h"
#include "curl_sha512_256.h"
#include "vtls/vtls.h"
#include "warnless.h"
#include "strtok.h"
@ -150,7 +151,7 @@ static void auth_digest_md5_to_ascii(unsigned char *source, /* 16 bytes */
msnprintf((char *) &dest[i * 2], 3, "%02x", source[i]);
}
/* Convert sha256 chunk to RFC7616 -suitable ascii string */
/* Convert sha256 or SHA-512/256 chunk to RFC7616 -suitable ascii string */
static void auth_digest_sha256_to_ascii(unsigned char *source, /* 32 bytes */
unsigned char *dest) /* 65 bytes */
{
@ -601,10 +602,20 @@ CURLcode Curl_auth_decode_digest_http_message(const char *chlg,
digest->algo = ALGO_SHA256;
else if(strcasecompare(content, "SHA-256-SESS"))
digest->algo = ALGO_SHA256SESS;
else if(strcasecompare(content, "SHA-512-256"))
else if(strcasecompare(content, "SHA-512-256")) {
#ifdef CURL_HAVE_SHA512_256
digest->algo = ALGO_SHA512_256;
else if(strcasecompare(content, "SHA-512-256-SESS"))
#else /* ! CURL_HAVE_SHA512_256 */
return CURLE_NOT_BUILT_IN;
#endif /* ! CURL_HAVE_SHA512_256 */
}
else if(strcasecompare(content, "SHA-512-256-SESS")) {
#ifdef CURL_HAVE_SHA512_256
digest->algo = ALGO_SHA512_256SESS;
#else /* ! CURL_HAVE_SHA512_256 */
return CURLE_NOT_BUILT_IN;
#endif /* ! CURL_HAVE_SHA512_256 */
}
else
return CURLE_BAD_CONTENT_ENCODING;
}
@ -957,12 +968,24 @@ CURLcode Curl_auth_create_digest_http_message(struct Curl_easy *data,
outptr, outlen,
auth_digest_md5_to_ascii,
Curl_md5it);
DEBUGASSERT(digest->algo <= ALGO_SHA512_256SESS);
return auth_create_digest_http_message(data, userp, passwdp,
request, uripath, digest,
outptr, outlen,
auth_digest_sha256_to_ascii,
Curl_sha256it);
if(digest->algo <= ALGO_SHA256SESS)
return auth_create_digest_http_message(data, userp, passwdp,
request, uripath, digest,
outptr, outlen,
auth_digest_sha256_to_ascii,
Curl_sha256it);
#ifdef CURL_HAVE_SHA512_256
if(digest->algo <= ALGO_SHA512_256SESS)
return auth_create_digest_http_message(data, userp, passwdp,
request, uripath, digest,
outptr, outlen,
auth_digest_sha256_to_ascii,
Curl_sha512_256it);
#endif /* CURL_HAVE_SHA512_256 */
/* Should be unreachable */
return CURLE_BAD_CONTENT_ENCODING;
}
/*