]> git.ipfire.org Git - thirdparty/gnutls.git/commitdiff
hpke-key-management: use memcmp instead of manual comparison
authorDaiki Ueno <ueno@gnu.org>
Tue, 21 Apr 2026 08:10:12 +0000 (17:10 +0900)
committerDaiki Ueno <ueno@gnu.org>
Sun, 26 Apr 2026 09:31:33 +0000 (18:31 +0900)
Signed-off-by: Daiki Ueno <ueno@gnu.org>
lib/hpke/hpke-key-management.c

index dc49f0c1e16adb0f81aa5c64bdc43cadb0df5c45..8c35972f554bc92a3589a944692a391877aab79d 100644 (file)
@@ -236,20 +236,6 @@ static const unsigned char *get_kem_order(const gnutls_hpke_kem_t kem)
        }
 }
 
-static int be_lt(const unsigned char *a, const unsigned char *b, size_t len)
-{
-       size_t i;
-
-       for (i = 0; i < len; i++) {
-               if (a[i] < b[i])
-                       return 1;
-               if (a[i] > b[i])
-                       return 0;
-       }
-
-       return 0;
-}
-
 static int prime_curve_keypair_from_raw_privkey(
        const gnutls_mac_algorithm_t mac, const gnutls_hpke_kem_t kem,
        const gnutls_datum_t *dkp_prk, const gnutls_ecc_curve_t curve,
@@ -302,8 +288,7 @@ static int prime_curve_keypair_from_raw_privkey(
                        goto cleanup;
                }
 
-               ret = be_lt(sk.data, order, sk.size);
-               if (!ret) {
+               if (memcmp(sk.data, order, sk.size) >= 0) {
                        continue;
                }