Commit 9c8101df9f for frr

commit 9c8101df9fd53bce8cebafd39398fe21ccca203a
Author: Abdul Wasey <w453y.me@gmail.com>
Date:   Fri Oct 30 18:01:17 2026 +0000

    lib: add sha-1 to the key chain algorithms

    The key chain has hmac-sha-1 but no plain SHA1, and BFD keyed SHA1
    (RFC 5880 Section 6.7.4) is a plain SHA1 over the packet with the key
    in it, not an HMAC. Add "sha-1", the RFC 8177 identity for it, so a
    protocol can tell the two apart.

    ospf6d (RFC 7166) and ospfd (RFC 5709) sign with an HMAC. ospf6d
    would treat a sha-1 key as usable, and ospfd warns on every packet and
    sends a digest length with no digest; refuse it in both the way a key
    with no algorithm is refused.

    isisd (RFC 5310) lists it with the algorithms it does not support.

    Signed-off-by: Abdul Wasey <w453y.me@gmail.com>

diff --git a/bfdd/bfd.c b/bfdd/bfd.c
index 56127f6e5e..de413b2835 100644
--- a/bfdd/bfd.c
+++ b/bfdd/bfd.c
@@ -673,6 +673,7 @@ enum bfd_auth_type map_keychain_algo_to_bfd_auth_type(enum keychain_hash_algo kc
 	case KEYCHAIN_ALGO_HMAC_SHA256:
 	case KEYCHAIN_ALGO_HMAC_SHA384:
 	case KEYCHAIN_ALGO_HMAC_SHA512:
+	case KEYCHAIN_ALGO_SHA1:
 	case KEYCHAIN_ALGO_MAX:
 	default:
 		return BFD_AUTH_TYPE_RESERVED;
diff --git a/isisd/isis_tlvs.c b/isisd/isis_tlvs.c
index f68cc5e4e7..bc5b126567 100644
--- a/isisd/isis_tlvs.c
+++ b/isisd/isis_tlvs.c
@@ -5817,6 +5817,7 @@ static bool crypto_auth_algo_supported(enum keychain_hash_algo algo)
 	case KEYCHAIN_ALGO_NULL:
 	case KEYCHAIN_ALGO_CLEARTEXT:
 	case KEYCHAIN_ALGO_MD5:
+	case KEYCHAIN_ALGO_SHA1:
 	case KEYCHAIN_ALGO_MAX:
 		return false;
 	}
@@ -5839,6 +5840,7 @@ static const EVP_MD *crypto_auth_md(enum keychain_hash_algo algo)
 	case KEYCHAIN_ALGO_NULL:
 	case KEYCHAIN_ALGO_CLEARTEXT:
 	case KEYCHAIN_ALGO_MD5:
+	case KEYCHAIN_ALGO_SHA1:
 	case KEYCHAIN_ALGO_MAX:
 		break;
 	}
diff --git a/lib/keychain.c b/lib/keychain.c
index 25b0bdebd2..331c067920 100644
--- a/lib/keychain.c
+++ b/lib/keychain.c
@@ -254,6 +254,8 @@ const struct keychain_algo_info algo_info[] = {
 	{KEYCHAIN_ALGO_HMAC_SHA512, "hmac-sha-512",
 	 KEYCHAIN_HMAC_SHA512_HASH_SIZE, KEYCHAIN_ALGO_SHA512_INTERNAL_BLK_SIZE,
 	 "HMAC-SHA-512"},
+	{KEYCHAIN_ALGO_SHA1, "sha-1", KEYCHAIN_HMAC_SHA1_HASH_SIZE,
+	 KEYCHAIN_ALGO_SHA1_INTERNAL_BLK_SIZE, "SHA-1"},
 	{KEYCHAIN_ALGO_MAX, "max", KEYCHAIN_MAX_HASH_SIZE,
 	 KEYCHAIN_ALGO_MAX_INTERNAL_BLK_SIZE, "Not defined"}
 };
@@ -305,6 +307,8 @@ enum keychain_hash_algo keychain_get_algo_id_by_name(const char *name)
 		return KEYCHAIN_ALGO_HMAC_SHA384;
 	else if (!strncmp(name, "hmac-sha-5", 10))
 		return KEYCHAIN_ALGO_HMAC_SHA512;
+	else if (!strcmp(name, "sha-1"))
+		return KEYCHAIN_ALGO_SHA1;
 	else
 		return KEYCHAIN_ALGO_NULL;
 #endif
diff --git a/lib/keychain.h b/lib/keychain.h
index 01607c192d..06bb9e0289 100644
--- a/lib/keychain.h
+++ b/lib/keychain.h
@@ -22,6 +22,7 @@ enum keychain_hash_algo {
 	KEYCHAIN_ALGO_HMAC_SHA256,
 	KEYCHAIN_ALGO_HMAC_SHA384,
 	KEYCHAIN_ALGO_HMAC_SHA512,
+	KEYCHAIN_ALGO_SHA1,
 	KEYCHAIN_ALGO_MAX
 };

diff --git a/lib/keychain_cli.c b/lib/keychain_cli.c
index 9691dc804d..1f3097125d 100644
--- a/lib/keychain_cli.c
+++ b/lib/keychain_cli.c
@@ -118,7 +118,7 @@ DEFPY_YANG(
       cryptographic_algorithm,
       cryptographic_algorithm_cmd,
       "cryptographic-algorithm "
-      "<null|cleartext|md5|hmac-sha-1|hmac-sha-256|hmac-sha-384|hmac-sha-512>$algo",
+      "<null|cleartext|md5|hmac-sha-1|hmac-sha-256|hmac-sha-384|hmac-sha-512|sha-1>$algo",
       "Cryptographic-algorithm\n"
       "null\n"
       "Use cleartext password\n"
@@ -126,7 +126,8 @@ DEFPY_YANG(
       "Use HMAC-SHA-1 algorithm\n"
       "Use HMAC-SHA-256 algorithm\n"
       "Use HMAC-SHA-384 algorithm\n"
-      "Use HMAC-SHA-512 algorithm\n")
+      "Use HMAC-SHA-512 algorithm\n"
+      "Use SHA-1 algorithm\n")
 {
 	nb_cli_enqueue_change(vty, "./crypto-algorithm", NB_OP_CREATE, algo);
 	return nb_cli_apply_changes(vty, NULL);
@@ -136,7 +137,7 @@ DEFPY_YANG(
       no_cryptographic_algorithm,
       no_cryptographic_algorithm_cmd,
       "no cryptographic-algorithm "
-      "[<null|cleartext|md5|hmac-sha-1|hmac-sha-256|hmac-sha-384|hmac-sha-512>$algo]",
+      "[<null|cleartext|md5|hmac-sha-1|hmac-sha-256|hmac-sha-384|hmac-sha-512|sha-1>$algo]",
       NO_STR
       "Cryptographic-algorithm\n"
       "null\n"
@@ -145,7 +146,8 @@ DEFPY_YANG(
       "Use HMAC-SHA-1 algorithm\n"
       "Use HMAC-SHA-256 algorithm\n"
       "Use HMAC-SHA-384 algorithm\n"
-      "Use HMAC-SHA-512 algorithm\n")
+      "Use HMAC-SHA-512 algorithm\n"
+      "Use SHA-1 algorithm\n")
 {
 	nb_cli_enqueue_change(vty, "./crypto-algorithm", NB_OP_DESTROY, algo);
 	return nb_cli_apply_changes(vty, NULL);
diff --git a/ospf6d/ospf6_auth_trailer.c b/ospf6d/ospf6_auth_trailer.c
index a87a3810e7..2b0bdb506b 100644
--- a/ospf6d/ospf6_auth_trailer.c
+++ b/ospf6d/ospf6_auth_trailer.c
@@ -284,6 +284,7 @@ static void ospf6_hash_hmac_sha_digest(enum keychain_hash_algo key,
 		break;
 	case KEYCHAIN_ALGO_CLEARTEXT:
 	case KEYCHAIN_ALGO_NULL:
+	case KEYCHAIN_ALGO_SHA1:
 	case KEYCHAIN_ALGO_MAX:
 	default:
 		/* no action */
@@ -308,8 +309,7 @@ uint16_t ospf6_auth_len_get(struct ospf6_interface *oi)
 			keychain = keychain_lookup(keychain_name);
 			if (keychain) {
 				key = key_lookup_for_send(keychain);
-				if (key && key->string
-				    && key->hash_algo != KEYCHAIN_ALGO_NULL) {
+				if (key && key->string && ospf6_auth_algo_usable(key->hash_algo)) {
 					at_len = OSPF6_AUTH_HDR_MIN_SIZE
 						 + keychain_get_hash_len(
 							   key->hash_algo);
@@ -523,8 +523,7 @@ int ospf6_auth_check_digest(struct ospf6_header *oh, struct ospf6_interface *oi,
 			return OSPF6_AUTH_VALIDATE_FAILURE;
 		}

-		if (key && key->string
-		    && key->hash_algo != KEYCHAIN_ALGO_NULL) {
+		if (key && key->string && ospf6_auth_algo_usable(key->hash_algo)) {
 			auth_str = key->string;
 			hash_algo = key->hash_algo;
 		} else {
@@ -628,8 +627,7 @@ void ospf6_auth_digest_send(struct in6_addr *src, struct ospf6_interface *oi,
 			keychain = keychain_lookup(keychain_name);
 			if (keychain) {
 				key = key_lookup_for_send(keychain);
-				if (key && key->string
-				    && key->hash_algo != KEYCHAIN_ALGO_NULL) {
+				if (key && key->string && ospf6_auth_algo_usable(key->hash_algo)) {
 					auth_str = key->string;
 					hash_algo = key->hash_algo;
 					key_id = key->index;
diff --git a/ospf6d/ospf6_auth_trailer.h b/ospf6d/ospf6_auth_trailer.h
index 57298ec4f8..08ff9b5774 100644
--- a/ospf6d/ospf6_auth_trailer.h
+++ b/ospf6d/ospf6_auth_trailer.h
@@ -74,4 +74,10 @@ void install_element_ospf6_debug_auth(void);
 int config_write_ospf6_debug_auth(struct vty *vty);
 void install_element_ospf6_clear_intf_auth(void);

+/* The trailer is an HMAC (RFC 7166); a key with a plain hash cannot sign it. */
+static inline bool ospf6_auth_algo_usable(enum keychain_hash_algo algo)
+{
+	return algo != KEYCHAIN_ALGO_NULL && algo != KEYCHAIN_ALGO_SHA1;
+}
+
 #endif /* __OSPF6_AUTH_TRAILER_H__ */
diff --git a/ospf6d/ospf6_message.c b/ospf6d/ospf6_message.c
index c5fdd37e65..3e5412c7b7 100644
--- a/ospf6d/ospf6_message.c
+++ b/ospf6d/ospf6_message.c
@@ -2104,8 +2104,7 @@ static void ospf6_auth_trailer_copy_keychain_key(struct ospf6_interface *oi)
 	keychain = keychain_lookup(keychain_name);
 	if (keychain) {
 		key = key_lookup_for_send(keychain);
-		if (key && key->string &&
-		    key->hash_algo != KEYCHAIN_ALGO_NULL) {
+		if (key && key->string && ospf6_auth_algo_usable(key->hash_algo)) {
 			/* storing the values so that further
 			 * lookup can be avoided. after
 			 * processing the digest need to reset
diff --git a/ospfd/ospf_auth.c b/ospfd/ospf_auth.c
index e0ad4f0466..70ef64ee82 100644
--- a/ospfd/ospf_auth.c
+++ b/ospfd/ospf_auth.c
@@ -95,6 +95,12 @@ static int ospf_check_sum(struct ospf_header *ospfh)
 	return 1;
 }

+/* The digest is an HMAC (RFC 5709); a key with a plain hash cannot make it. */
+static bool ospf_auth_algo_usable(enum keychain_hash_algo algo)
+{
+	return algo != KEYCHAIN_ALGO_NULL && algo != KEYCHAIN_ALGO_SHA1;
+}
+
 #ifdef CRYPTO_OPENSSL
 static const char *ospf_auth_get_digest_name_from_key(struct key *key)
 {
@@ -456,7 +462,7 @@ int ospf_auth_check_digest(struct ospf_interface *oi, struct ip *iph, struct osp
 		return 0;
 	}

-	if (key->string == NULL || key->hash_algo == KEYCHAIN_ALGO_NULL) {
+	if (key->string == NULL || !ospf_auth_algo_usable(key->hash_algo)) {
 		if (IS_DEBUG_OSPF_PACKET(ospfh->type - 1, RECV))
 			flog_warn(EC_OSPF_AUTH,
 				  "interface %s: Key ID %d in keychain %s is incomplete, Router-ID %pI4",
@@ -522,7 +528,7 @@ int ospf_auth_make_digest(struct ospf_interface *oi, struct ospf_packet *op)
 		return 0;
 	}

-	if (key->string == NULL || key->hash_algo == KEYCHAIN_ALGO_NULL) {
+	if (key->string == NULL || !ospf_auth_algo_usable(key->hash_algo)) {
 		if (IS_DEBUG_OSPF_PACKET(ospfh->type - 1, SEND))
 			flog_warn(EC_OSPF_AUTH,
 				  "interface %s: Key ID %d in keychain %s is incomplete, Router-ID %pI4",
@@ -768,7 +774,10 @@ int ospf_auth_make_data(struct ospf_interface *oi, struct ospf_header *ospfh)
 			if (oi->key) {
 				ospfh->u.crypt.zero = 0;
 				ospfh->u.crypt.key_id = oi->key->index;
-				ospfh->u.crypt.auth_data_len = keychain_get_hash_len(oi->key->hash_algo);
+				ospfh->u.crypt.auth_data_len =
+					ospf_auth_algo_usable(oi->key->hash_algo)
+						? keychain_get_hash_len(oi->key->hash_algo)
+						: 0;
 			} else {
 				/* If key is not set, then set 0. */
 				ospfh->u.crypt.zero = 0;