From patchwork Wed Sep 3 13:36:02 2025 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Simon Glass X-Patchwork-Id: 191 Return-Path: X-Original-To: u-boot-concept@u-boot.org Delivered-To: u-boot-concept@u-boot.org DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=u-boot.org; s=default; t=1756906619; bh=bLsKRI9MMnD8pEgoOPEYmnwBfw5sUT49HB4nXMjUvmA=; h=From:To:Date:In-Reply-To:References:CC:Subject:List-Id: List-Archive:List-Help:List-Owner:List-Post:List-Subscribe: List-Unsubscribe:From; b=gPrDDgpDohJMAsN/WZJ7cZwW5aXcgzeUMFSmxrwjFX1ZGm8bvFkj7efEjIzgmkeM/ Zw4womo4oucu3Pa+qhibe7EosQ9Rp9n0puePxdRPh3m3A7zCL1bdjhOfwPBDKCVpqV I9jzuPk/Z4JX/+rtST1NYvKeEQV5+Yxj80C1hDpgVXE2c/jFUasZzPqcDi+mlusr70 xMRS/IMi9oSCfngJEN+wTw2bnTtPca8XsTL3T0LY7n9ufSvtpq4kfR3lo5RPvOPgmN LCunXjjZyNI73VyWWiBbCNmYUU8w8aR9+MxqB+XeLE310anZthibqy+Q4p59PBAIcS +F0q2it0IDWzQ== Received: from localhost (localhost [127.0.0.1]) by mail.u-boot.org (Postfix) with ESMTP id 28A6667915 for ; Wed, 3 Sep 2025 07:36:59 -0600 (MDT) X-Virus-Scanned: Debian amavis at Received: from mail.u-boot.org ([127.0.0.1]) by localhost (mail.u-boot.org [127.0.0.1]) (amavis, port 10024) with ESMTP id OsHG49iI6y4L for ; Wed, 3 Sep 2025 07:36:59 -0600 (MDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=u-boot.org; s=default; t=1756906618; bh=bLsKRI9MMnD8pEgoOPEYmnwBfw5sUT49HB4nXMjUvmA=; h=From:To:Date:In-Reply-To:References:CC:Subject:List-Id: List-Archive:List-Help:List-Owner:List-Post:List-Subscribe: List-Unsubscribe:From; b=IO1VywOJRQaS/YLd3gIlqH59PndnO4JLjYA/LAIg7JBaUrpj/6idxxZNU+2y9++iO lo7xuaarUKMXAvDr59ei5SEi7Pn+INaBuMheiELEkyrQH2X09Gv55x2gTg1VAiapVD 0p1STqzB0waGlLrXrmdxgcy7uUinCd3ZPmDXVfHoaHdehcaS0+4jeGthImplzEeHCd Jnj8TEvDcuhz40lNmUpOMY59FKH+pS/W6RpLbfEV5JAYoK/3lVy5jdkkQC0r0p9Vj5 3uZeY/5NoANWNbLUrC+PZ9Mq82EWPVETOlE4yWzirBWYzxapObXEI/BgrnZxETrRU3 FUDmP4Q0RUHvw== Received: from mail.u-boot.org (localhost [127.0.0.1]) by mail.u-boot.org (Postfix) with ESMTP id 18A0C678B2 for ; Wed, 3 Sep 2025 07:36:58 -0600 (MDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=u-boot.org; s=default; t=1756906616; bh=2GK0Gzz5bRJp7EcAJD5K+QHtzk3tu1SmVrZldvyQdV8=; h=From:To:Cc:Subject:Date:In-Reply-To:References:From; b=sB8aKgI3n5e89hirpy43Cf31U58PbdK+mOn6L/ewuRPelBoXwBviDkAPsfdtr76Qi a89oqe3jISMqBr2PEuxggtA8lURP5XjTtLauhMMp3No/jMFzBs6jAuPBZ934h9TUuD oxDaBwThnl7IXw6EANKaZD2VmsSBtdmAv3vWhvqEd4UOCamGNB9h/9hWyyr/xzqDvx VeZO3eJhjBsXle9+oraNZJrSTcsC7DsQcCCEWMoJCc4gIq6Sd5NomvkUoQvvl+0d/s f0QCcAOR4wwRNA4GdkJ7zoStss9duEjLB8GvtpLeA8H0B6rUvg8SdFe/0XeOiKx39L Iz1x1V4mAFkkg== Received: from localhost (localhost [127.0.0.1]) by mail.u-boot.org (Postfix) with ESMTP id A3D0C5FE1B; Wed, 3 Sep 2025 07:36:56 -0600 (MDT) X-Virus-Scanned: Debian amavis at Received: from mail.u-boot.org ([127.0.0.1]) by localhost (mail.u-boot.org [127.0.0.1]) (amavis, port 10026) with ESMTP id 8AQijs9R2axE; Wed, 3 Sep 2025 07:36:56 -0600 (MDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=u-boot.org; s=default; t=1756906616; bh=T0mUZM2yGuLMIc4rPsKPvDe3SPDa7blwty6j/TlclXM=; h=From:To:Cc:Subject:Date:In-Reply-To:References:From; b=ITgsuSN81bxhCu5MstdiFpd5sHf6x4w4n01WitWG6EdctQHgcK+DIt5LuL4y/TTPt Pf9zqfnLG54iZIXcN+KKq625HzD3G9CaQM3P1n/tfFT7NR859CG72Ljz+C/mG80RNi 5SL0nxzeJNpXo8XH82OxcXaZKwke68TsOFcz4/lPaSs5ekFZ+vNNfVBaMo4EPjeEWB 326L6RUt9e2OgX5ph4RI7MUCPR0iVQSnFkqOy4DvtkIdQkQEX5uVd+FWtoiQ8ihIpd IgCTddbwkFbqAqC53xzeX1zRs57M5hw5Qq6uxtJGKRHSEnqRsYt8M44qKsb1yWsVrZ 2VCR4A7imRIow== Received: from u-boot.org (unknown [73.34.74.121]) by mail.u-boot.org (Postfix) with ESMTPSA id 0E58B5FCF5; Wed, 3 Sep 2025 07:36:56 -0600 (MDT) From: Simon Glass To: U-Boot Concept Date: Wed, 3 Sep 2025 07:36:02 -0600 Message-ID: <20250903133639.3235920-3-sjg@u-boot.org> X-Mailer: git-send-email 2.43.0 In-Reply-To: <20250903133639.3235920-1-sjg@u-boot.org> References: <20250903133639.3235920-1-sjg@u-boot.org> MIME-Version: 1.0 Message-ID-Hash: 3YAJY3ZJISYX6H2WIPLWUOPVBQUXQVSG X-Message-ID-Hash: 3YAJY3ZJISYX6H2WIPLWUOPVBQUXQVSG X-MailFrom: sjg@u-boot.org X-Mailman-Rule-Misses: dmarc-mitigation; no-senders; approved; loop; banned-address; emergency; member-moderation; nonmember-moderation; administrivia; implicit-dest; max-recipients; max-size; news-moderation; no-subject; digests; suspicious-header CC: Simon Glass , Claude X-Mailman-Version: 3.3.10 Precedence: list Subject: [Concept] [PATCH 02/25] uuid: Refactor v5 GUID generation into BE and LE variants List-Id: Discussion and patches related to U-Boot Concept Archived-At: List-Archive: List-Help: List-Owner: List-Post: List-Subscribe: List-Unsubscribe: From: Simon Glass Split the v5 GUID generation into separate big-endian and little-endian functions with shared common code. The big-endian version is used for CHIDs and standard UUID v5 operations, while the little-endian version seems to be needed for EFI GUID compatibility. Co-developed-by: Claude Signed-off-by: Simon Glass --- include/u-boot/uuid.h | 10 ++++++++++ lib/uuid.c | 30 ++++++++++++++++++++++++------ 2 files changed, 34 insertions(+), 6 deletions(-) diff --git a/include/u-boot/uuid.h b/include/u-boot/uuid.h index 124a42da297..940e7a32fe8 100644 --- a/include/u-boot/uuid.h +++ b/include/u-boot/uuid.h @@ -146,6 +146,16 @@ void gen_rand_uuid_str(char *uuid_str, int str_format); struct efi_guid; +/** + * gen_v5_guid_be() - generate big-endian v5 GUID from namespace and data + * + * @namespace: pointer to UUID namespace salt + * @guid: pointer to allocated GUID output + * @...: NULL terminated list of seed data as pairs of pointers + * to data and their lengths + */ +void gen_v5_guid_be(const struct uuid *namespace, struct efi_guid *guid, ...); + /** * gen_v5_guid_le() - generate little-endian v5 GUID from namespace and data * diff --git a/lib/uuid.c b/lib/uuid.c index 4ca36530710..70633f42aa0 100644 --- a/lib/uuid.c +++ b/lib/uuid.c @@ -432,19 +432,16 @@ static void configure_uuid(struct uuid *uuid, unsigned char version) uuid->clock_seq_hi_and_reserved |= (UUID_VARIANT << UUID_VARIANT_SHIFT); } -void gen_v5_guid_le(const struct uuid *namespace, struct efi_guid *guid, ...) +static void gen_v5_guid_common(const struct uuid *namespace, + struct efi_guid *guid, va_list args) { sha1_context ctx; - va_list args; const uint8_t *data; - uint32_t *tmp32; - uint16_t *tmp16; uint8_t hash[SHA1_SUM_LEN]; sha1_starts(&ctx); /* Hash the namespace UUID as salt */ sha1_update(&ctx, (unsigned char *)namespace, UUID_BIN_LEN); - va_start(args, guid); while ((data = va_arg(args, const uint8_t *))) { unsigned int len = va_arg(args, size_t); @@ -452,13 +449,34 @@ void gen_v5_guid_le(const struct uuid *namespace, struct efi_guid *guid, ...) sha1_update(&ctx, data, len); } - va_end(args); sha1_finish(&ctx, hash); /* Truncate the hash into output UUID, it is already big endian */ memcpy(guid, hash, sizeof(*guid)); configure_uuid((struct uuid *)guid, 5); +} + +void gen_v5_guid_be(const struct uuid *namespace, struct efi_guid *guid, ...) +{ + va_list args; + + va_start(args, guid); + gen_v5_guid_common(namespace, guid, args); + va_end(args); + + /* Keep big endian - no conversion needed */ +} + +void gen_v5_guid_le(const struct uuid *namespace, struct efi_guid *guid, ...) +{ + va_list args; + uint32_t *tmp32; + uint16_t *tmp16; + + va_start(args, guid); + gen_v5_guid_common(namespace, guid, args); + va_end(args); /* Make little endian */ tmp32 = (uint32_t *)&guid->b[0];