mirror of
https://github.com/ipxe/ipxe
synced 2026-02-14 02:31:26 +03:00
[base16] Add buffer size parameter to base16_encode() and base16_decode()
The current API for Base16 (and Base64) encoding requires the caller to always provide sufficient buffer space. This prevents the use of the generic encoding/decoding functionality in some situations, such as in formatting the hex setting types. Implement a generic hex_encode() (based on the existing format_hex_setting()), implement base16_encode() and base16_decode() in terms of the more generic hex_encode() and hex_decode(), and update all callers to provide the additional buffer length parameter. Signed-off-by: Michael Brown <mcb30@ipxe.org>
This commit is contained in:
@@ -1122,12 +1122,14 @@ static void http_digest_update ( struct md5_context *ctx, const char *string ) {
|
||||
*
|
||||
* @v ctx Digest context
|
||||
* @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 md5_context *ctx, char *out,
|
||||
size_t len ) {
|
||||
uint8_t digest[MD5_DIGEST_SIZE];
|
||||
|
||||
digest_final ( &md5_algorithm, ctx, digest );
|
||||
base16_encode ( digest, sizeof ( digest ), out );
|
||||
base16_encode ( digest, sizeof ( digest ), out, len );
|
||||
}
|
||||
|
||||
/**
|
||||
@@ -1172,20 +1174,20 @@ static char * http_digest_auth ( struct http_request *http,
|
||||
http_digest_update ( &ctx, user );
|
||||
http_digest_update ( &ctx, realm );
|
||||
http_digest_update ( &ctx, password );
|
||||
http_digest_final ( &ctx, ha1 );
|
||||
http_digest_final ( &ctx, ha1, sizeof ( ha1 ) );
|
||||
if ( md5sess ) {
|
||||
http_digest_init ( &ctx );
|
||||
http_digest_update ( &ctx, ha1 );
|
||||
http_digest_update ( &ctx, nonce );
|
||||
http_digest_update ( &ctx, cnonce );
|
||||
http_digest_final ( &ctx, ha1 );
|
||||
http_digest_final ( &ctx, ha1, sizeof ( ha1 ) );
|
||||
}
|
||||
|
||||
/* Generate HA2 */
|
||||
http_digest_init ( &ctx );
|
||||
http_digest_update ( &ctx, method );
|
||||
http_digest_update ( &ctx, uri );
|
||||
http_digest_final ( &ctx, ha2 );
|
||||
http_digest_final ( &ctx, ha2, sizeof ( ha2 ) );
|
||||
|
||||
/* Generate response */
|
||||
http_digest_init ( &ctx );
|
||||
@@ -1197,7 +1199,7 @@ static char * http_digest_auth ( struct http_request *http,
|
||||
http_digest_update ( &ctx, "auth" /* qop */ );
|
||||
}
|
||||
http_digest_update ( &ctx, ha2 );
|
||||
http_digest_final ( &ctx, response );
|
||||
http_digest_final ( &ctx, response, sizeof ( response ) );
|
||||
|
||||
/* Generate the authorisation string */
|
||||
len = asprintf ( &auth, "Authorization: Digest username=\"%s\", "
|
||||
|
||||
Reference in New Issue
Block a user