diff options
Diffstat (limited to 'src/core/settings.c')
-rw-r--r-- | src/core/settings.c | 47 |
1 files changed, 47 insertions, 0 deletions
diff --git a/src/core/settings.c b/src/core/settings.c index 9fbf753a..aa4bbae2 100644 --- a/src/core/settings.c +++ b/src/core/settings.c @@ -45,6 +45,7 @@ FILE_LICENCE ( GPL2_OR_LATER_OR_UBDL ); #include <ipxe/init.h> #include <ipxe/version.h> #include <ipxe/settings.h> +#include <ipxe/md5.h> /** @file * @@ -2133,6 +2134,46 @@ static int format_hex_raw_setting ( const struct setting_type *type __unused, return hex_encode ( 0, raw, raw_len, buf, len ); } +/** + * Parsing md5 setting doesn't make any sense + * + * @v type Setting type + * @v value Formatted setting value + * @v buf Buffer to contain raw value + * @v len Length of buffer + * @v size Integer size, in bytes + * @ret len Length of raw value, or negative error + */ +static int parse_md5_setting ( const struct setting_type *type __unused, + const char *value __unused, void *buf __unused, + size_t len __unused ) { + return -ENOTSUP; +} + +/** + * Format setting value as md5 hash (hex representation) + * + * @v type Setting type + * @v raw Raw setting value + * @v raw_len Length of raw setting value + * @v buf Buffer to contain formatted value + * @v len Length of buffer + * @ret len Length of formatted value, or negative error + */ +static int format_md5_setting ( const struct setting_type *type __unused, + const void *raw, size_t raw_len, + char *buf, size_t len ) { + struct md5_context ctx; + uint8_t digest[MD5_DIGEST_SIZE]; + + if ( len < MD5_DIGEST_SIZE * 2 ) + return MD5_DIGEST_SIZE * 2; + digest_init ( &md5_algorithm, &ctx ); + digest_update ( &md5_algorithm, &ctx, raw, raw_len ); + digest_final ( &md5_algorithm, &ctx, digest ); + return hex_encode ( 0, digest, sizeof(digest), buf, len ); +} + /** A hex-string setting (colon-delimited) */ const struct setting_type setting_type_hex __setting_type = { .name = "hex", @@ -2154,6 +2195,12 @@ const struct setting_type setting_type_hexraw __setting_type = { .format = format_hex_raw_setting, }; +const struct setting_type setting_type_md5 __setting_type = { + .name = "md5", + .parse = parse_md5_setting, + .format = format_md5_setting, +}; + /** * Parse Base64-encoded setting value * |