[PATCH v2 1/7] lib: uuid: add UUID v5 support
Ilias Apalodimas
ilias.apalodimas at linaro.org
Thu May 30 17:08:00 CEST 2024
Hi Caleb,
> diff --git a/lib/uuid.c b/lib/uuid.c
> index dfa2320ba267..6ef006cca1da 100644
> --- a/lib/uuid.c
> +++ b/lib/uuid.c
> @@ -21,8 +21,9 @@
> #include <part_efi.h>
> #include <malloc.h>
> #include <dm/uclass.h>
> #include <rng.h>
> +#include <u-boot/sha1.h>
>
> int uuid_str_valid(const char *uuid)
> {
> int i, valid;
> @@ -368,8 +369,44 @@ void uuid_bin_to_str(const unsigned char *uuid_bin, char *uuid_str,
> }
> }
> }
>
> +#if IS_ENABLED(CONFIG_UUID_GEN_V5)
> +void gen_uuid_v5(const struct uuid *namespace, struct uuid *uuid, ...)
> +{
> + sha1_context ctx;
> + va_list args;
> + const uint8_t *data;
> + uint8_t hash[SHA1_SUM_LEN];
> + uint32_t tmp;
> +
> + sha1_starts(&ctx);
> + /* Hash the namespace UUID as salt */
> + sha1_update(&ctx, (unsigned char *)namespace, UUID_BIN_LEN);
> + va_start(args, uuid);
> +
> + while ((data = va_arg(args, const uint8_t *))) {
> + size_t len = va_arg(args, size_t);
sha1_update takes an unsigned int
so i'd prefer
unsigned int len = .... etc
> +
> + sha1_update(&ctx, data, len);
> + }
> +
> + va_end(args);
> + sha1_finish(&ctx, hash);
> +
> + /* Truncate the hash into output UUID, it is already big endian */
> + memcpy(uuid, hash, sizeof(*uuid));
> +
> + /* Configure variant/version bits */
> + tmp = be32_to_cpu(uuid->time_hi_and_version);
> + tmp = (tmp & ~UUID_VERSION_MASK) | (5 << UUID_VERSION_SHIFT);
> + uuid->time_hi_and_version = cpu_to_be32(tmp);
> +
> + uuid->clock_seq_hi_and_reserved &= UUID_VARIANT_MASK;
> + uuid->clock_seq_hi_and_reserved |= UUID_VARIANT << UUID_VARIANT_SHIFT;
> +}
> +#endif
> +
> #if defined(CONFIG_RANDOM_UUID) || defined(CONFIG_CMD_UUID)
> void gen_rand_uuid(unsigned char *uuid_bin)
> {
> u32 ptr[4];
>
> --
> 2.45.0
>
Thanks
/Ilias
More information about the U-Boot
mailing list