Skip to contentSkip to conversation

sctp: Add optional SHA256 hmac cookie generation

PATCH New Petr Vorel 1 participant 1 message Dec 23, 2021

Subsystems (2)
lore
Share & tools
lore

Petr Vorel

author
#0 lore raw

PATCH 1/1 sctp: Add optional SHA256 hmac cookie generation

---
Hi,

WARNING: While I tested this with LTP SCTP and IPsec over SCTP tests, it'd be good to review carefully.

Also this may not be that useful given that CRYPTO_SHA256 will be most likely enabled due being selected by ENCRYPTED_KEYS [=y] && KEYS [=y] or BT [=m] && NET [=y] && !S390 && (RFKILL [=m] || !RFKILL [=m]).

Kind regards,
Petr

 net/sctp/Kconfig    | 13 +++++++++++++
 net/sctp/protocol.c |  2 ++
 net/sctp/sysctl.c   |  6 ++++++
 3 files changed, 21 insertions(+)
net/sctp/Kconfig +13 -0
index 5da599ff84a9..0f508d0b1864 100644
@@ -68,6 +68,12 @@ config SCTP_DEFAULT_COOKIE_HMAC_SHA1
 	  Enable optional SHA1 hmac based SCTP cookie generation
 	select SCTP_COOKIE_HMAC_SHA1
 
+config SCTP_DEFAULT_COOKIE_HMAC_SHA256
+	bool "Enable optional SHA256 hmac cookie generation"
+	help
+	  Enable optional SHA256 hmac based SCTP cookie generation
+	select SCTP_COOKIE_HMAC_SHA256
+
 config SCTP_DEFAULT_COOKIE_HMAC_NONE
 	bool "Use no hmac alg in SCTP cookie generation"
 	help
@@ -89,6 +95,13 @@ config SCTP_COOKIE_HMAC_SHA1
 	select CRYPTO_HMAC if SCTP_COOKIE_HMAC_SHA1
 	select CRYPTO_SHA1 if SCTP_COOKIE_HMAC_SHA1
 
+config SCTP_COOKIE_HMAC_SHA256
+	bool "Enable optional SHA256 hmac cookie generation"
+	help
+	  Enable optional SHA256 hmac based SCTP cookie generation
+	select CRYPTO_HMAC if SCTP_COOKIE_HMAC_SHA256
+	select CRYPTO_SHA256 if SCTP_COOKIE_HMAC_SHA256
+
 config INET_SCTP_DIAG
 	depends on INET_DIAG
 	def_tristate INET_DIAG
net/sctp/protocol.c +2 -0
index 35928fefae33..3a0b76e26878 100644
@@ -1317,6 +1317,8 @@ static int __net_init sctp_defaults_init(struct net *net)
 	net->sctp.sctp_hmac_alg			= "md5";
 #elif defined (CONFIG_SCTP_DEFAULT_COOKIE_HMAC_SHA1)
 	net->sctp.sctp_hmac_alg			= "sha1";
+#elif defined (CONFIG_SCTP_DEFAULT_COOKIE_HMAC_SHA256)
+	net->sctp.sctp_hmac_alg			= "sha256";
 #else
 	net->sctp.sctp_hmac_alg			= NULL;
 #endif
net/sctp/sysctl.c +6 -0
index b46a416787ec..05bfc66effeb 100644
@@ -400,6 +400,12 @@ static int proc_sctp_do_hmac_alg(struct ctl_table *ctl, int write,
 			net->sctp.sctp_hmac_alg = "sha1";
 			changed = true;
 		}
+#endif
+#ifdef CONFIG_CRYPTO_SHA256
+		if (!strncmp(tmp, "sha256", 6)) {
+			net->sctp.sctp_hmac_alg = "sha256";
+			changed = true;
+		}
 #endif
 		if (!strncmp(tmp, "none", 4)) {
 			net->sctp.sctp_hmac_alg = NULL;
Signature · 1 line
2.34.1