Received: from list by lists.gnu.org with archive (Exim 4.90_1) id 1lOTQO-0002AP-Gj for mharc-grub-devel@gnu.org; Mon, 22 Mar 2021 18:53:28 -0400 Received: from eggs.gnu.org ([2001:470:142:3::10]:35744) by lists.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.90_1) (envelope-from ) id 1lOTQL-00026r-N3 for grub-devel@gnu.org; Mon, 22 Mar 2021 18:53:26 -0400 Received: from ionic.de ([87.98.244.45]:57597 helo=mail.ionic.de) by eggs.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1lOTQI-0006K2-He for grub-devel@gnu.org; Mon, 22 Mar 2021 18:53:25 -0400 Authentication-Results: root24.eu; spf=softfail (domain owner discourages use of this host) smtp.mailfrom=ionic.de (client-ip=217.92.117.31; helo=home.ionic.de; envelope-from=ionic@ionic.de; receiver=) Received: from [192.168.0.46] (home.ionic.de [217.92.117.31]) by mail.ionic.de (Postfix) with ESMTPSA id 532424F0006D; Mon, 22 Mar 2021 22:53:17 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=ionic.de; s=default; t=1616453597; bh=k7R4POxWXMgaIWZXDGfWvvePTFdCVvo2/Tdfb4mJeBc=; h=To:References:From:Subject:Date:In-Reply-To:From; b=VOF55WmGZssZLcx5m4ItqGHTjaeo1O9nBtpMP8sFXq4N5qRv+K73GRQKZ4Xlbkd6U yFXW310TrNa38uII59j3wXTHJX+8svNVkvJUf87BDvl39sLU8p2wDwkLKHVxNCBVNo 7mBiO+hIlohX6T6gGVh3oaEHN5d9p8zGQrmIigyM= To: The development of GNU GRUB , Glenn Washburn , Daniel Kiper References: From: Mihai Moldovan Subject: Re: [PATCH v2 0/2] cryptodisk: Allows UUIDs to be compared in a dash-insensitive manner Message-ID: Date: Mon, 22 Mar 2021 23:53:16 +0100 User-Agent: Mozilla/5.0 (X11; Linux x86_64; rv:78.0) Gecko/20100101 Thunderbird/78.6.0 MIME-Version: 1.0 In-Reply-To: Content-Type: multipart/signed; micalg=pgp-sha256; protocol="application/pgp-signature"; boundary="05XHJLf6nxaNvNckCptCNyEvJ0fQfrcrF" Received-SPF: pass client-ip=87.98.244.45; envelope-from=ionic@ionic.de; helo=mail.ionic.de X-Spam_score_int: -20 X-Spam_score: -2.1 X-Spam_bar: -- X-Spam_report: (-2.1 / 5.0 requ) BAYES_00=-1.9, DKIM_SIGNED=0.1, DKIM_VALID=-0.1, DKIM_VALID_AU=-0.1, DKIM_VALID_EF=-0.1, NICE_REPLY_A=-0.001, SPF_HELO_NONE=0.001, SPF_PASS=-0.001 autolearn=ham autolearn_force=no X-Spam_action: no action X-BeenThere: grub-devel@gnu.org X-Mailman-Version: 2.1.23 Precedence: list List-Id: The development of GNU GRUB List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , X-List-Received-Date: Mon, 22 Mar 2021 22:53:26 -0000 This is an OpenPGP/MIME signed message (RFC 4880 and 3156) --05XHJLf6nxaNvNckCptCNyEvJ0fQfrcrF Content-Type: multipart/mixed; boundary="muKcyhGyoRDJNkVMd26mKHtHVpSvM7QFy"; protected-headers="v1" From: Mihai Moldovan To: The development of GNU GRUB , Glenn Washburn , Daniel Kiper Message-ID: Subject: Re: [PATCH v2 0/2] cryptodisk: Allows UUIDs to be compared in a dash-insensitive manner References: In-Reply-To: --muKcyhGyoRDJNkVMd26mKHtHVpSvM7QFy Content-Type: text/plain; charset=utf-8 Content-Language: en-US Content-Transfer-Encoding: quoted-printable * On 3/21/21 9:06 PM, Glenn Washburn wrote: > I have another version of grub_uuidcasecmp which is more efficient by n= ot > copying the UUID bytes to another buffer to strip out the dashes. [...]= At first, I didn't understand why you would need to copy the original UUI= Ds in the first place, but then ... > However, I'm not sure we're so memory constrained that the added comple= xity > (its not trivial to verify correctness) is worth it here, so I've chose= n to > submit this simpler version. I don't think that memory is so scarce that allocating two tiny string bu= ffers on the stack would be problematic, but ... > If that assumption isn't valid, I can submit > the more complex version. This current version uses an extra buffer cop= y in > grub_uuidcasecmp to strip out dashes so that grub_strncasecmp can be ca= lled. Do you do all of that just to be able to use grub_strncasecmp()? Wouldn't it make more sense to just duplicate a bit of code in this case = and do away with all additional buffers and complexities? Untested, written from the top of my head without any syntax check or the= like: static inline int grub_uuidcasecmp (const char *uuid1, const char *uuid2, grub_size_t n) { const char *s1 =3D uuid1, *s2 =3D uuid2; /* * Assume that n is the number of valid non-dash characters in a UUID * and that both UUIDs are sized the same. */ for (grub_size_t i =3D 0; i < n; ++i) { /* Skip forward to non-dash on both UUIDs. */ while ('-' =3D=3D *s1) { ++s1; } while ('-' =3D=3D *s2) { ++s2; } if (grub_tolower (*s1) !=3D grub_tolower (*s2)) { break; } ++s1; ++s2; } return (int) grub_tolower ((grub_uint8_t) *s1) - (int) grub_tolower ((grub_uint8_t) *s2); } That is, admittedly, copying the actual part of grub_strncasecmp(), but w= e're doing away with all copies and additional buffers and it's different enou= gh to warrant being a different function, I figure. Mihai --muKcyhGyoRDJNkVMd26mKHtHVpSvM7QFy-- --05XHJLf6nxaNvNckCptCNyEvJ0fQfrcrF Content-Type: application/pgp-signature; name="OpenPGP_signature.asc" Content-Description: OpenPGP digital signature Content-Disposition: attachment; filename="OpenPGP_signature" -----BEGIN PGP SIGNATURE----- wsF5BAABCAAjFiEEbhHQj3UzgcdE8cg8H9Yu2W4lOocFAmBZH9wFAwAAAAAACgkQH9Yu2W4lOoeE lxAAu6JW5iu1XN93RhKUtcclztNWzJjLqo/4CysU6QpVL3wjA+45kep2duovGzWaAWOZM6YkzHNJ 9ViW7viKS5ccWQh1kbPbOouZrbOqijk4DHmpcGUVCZdMrXbayuooycd8uTS1n4IM9yISZV+ykC/Q wAS5uklE2r6OehjNPbPeoWnD4IGqqBC863gJE+KS7CPpo/3C22dWd+YitXhYVIrXZJRX8lqxP2f4 JBYxs5mRLwQs8h8nzC95YleFCeNGvEYGnGfyreVf5ZGhuQfaToEX+gIxSjkZVJPby4pA4O5JWPbq LgafXS0AQCr0YTU3Yf403X3XEISB9ZZm7xZbo56xMfCWWezSijaIL7kveeHjiZs8GUmj5N5NH3TG ehhTnJNQnXruBL7e8qVCfci74EBXKlc3rj/eRHkpUGWqHUKFSKzd2b3l+EpnO+YTzzHVTq58svwa pnoOdp7MG1rRRxi63gwcvl/g5vqbKr6q6QEBlVH4aFy/M2m+XCwV+9z6htly3x45sHpb6QAMzD/R lULUoAyevSmh3KDBBai5k8HkVdeTugJJ109MccUIc1gznEqQmjYZza3OukgWm46J61ylwIP7EhqM ZusX92E16qPQ8qyRKLf7lsT0e+EfeIq9h3jaFQEx5e8PGBIsPOPZDqqhni9Q5QxNfN72Qy/MKH43 j0A= =9T5U -----END PGP SIGNATURE----- --05XHJLf6nxaNvNckCptCNyEvJ0fQfrcrF--