From c3146543d08d80a5a169c6b2291e0874974e0384 Mon Sep 17 00:00:00 2001
From: Shawn Silverman <shawn@pobox.com>
Date: Sun, 26 Nov 2023 19:52:26 -0800
Subject: [PATCH] mbedtls: Replace deprecated calls with non-deprecated calls

---
 src/apps/altcp_tls/altcp_tls_mbedtls.c |  4 ++--
 src/apps/snmp/snmpv3_mbedtls.c         | 24 ++++++++++++------------
 src/include/netif/ppp/pppcrypt.h       | 12 ++++++------
 3 files changed, 20 insertions(+), 20 deletions(-)

diff --git a/src/apps/altcp_tls/altcp_tls_mbedtls.c b/src/apps/altcp_tls/altcp_tls_mbedtls.c
index 9e619126..67ee93a6 100644
--- a/src/apps/altcp_tls/altcp_tls_mbedtls.c
+++ b/src/apps/altcp_tls/altcp_tls_mbedtls.c
@@ -1198,7 +1198,7 @@ altcp_mbedtls_sndbuf(struct altcp_pcb *conn)
           size_t ret;
 #if defined(MBEDTLS_SSL_MAX_FRAGMENT_LENGTH)
           /* @todo: adjust ssl_added to real value related to negotiated cipher */
-          size_t max_frag_len = mbedtls_ssl_get_max_frag_len(&state->ssl_context);
+          size_t max_frag_len = mbedtls_ssl_get_output_max_frag_len(&state->ssl_context);
           max_len = LWIP_MIN(max_frag_len, max_len);
 #endif
           /* Adjust sndbuf of inner_conn with what added by SSL */
@@ -1317,7 +1317,7 @@ altcp_mbedtls_mss(struct altcp_pcb *conn)
   if (conn == NULL) {
     return 0;
   }
-  /* @todo: LWIP_MIN(mss, mbedtls_ssl_get_max_frag_len()) ? */
+  /* @todo: LWIP_MIN(mss, mbedtls_ssl_get_output_max_frag_len()) ? */
   return altcp_mss(conn->inner_conn);
 }
 
diff --git a/src/apps/snmp/snmpv3_mbedtls.c b/src/apps/snmp/snmpv3_mbedtls.c
index 48c1a81f..dddd5e38 100644
--- a/src/apps/snmp/snmpv3_mbedtls.c
+++ b/src/apps/snmp/snmpv3_mbedtls.c
@@ -249,7 +249,7 @@ snmpv3_password_to_key_md5(
   u32_t count = 0;
 
   mbedtls_md5_init(&MD); /* initialize MD5 */
-  mbedtls_md5_starts(&MD);
+  mbedtls_md5_starts_ret(&MD);
 
   /**********************************************/
   /* Use while loop until we've done 1 Megabyte */
@@ -263,10 +263,10 @@ snmpv3_password_to_key_md5(
       /*************************************************/
       *cp++ = password[password_index++ % passwordlen];
     }
-    mbedtls_md5_update(&MD, password_buf, 64);
+    mbedtls_md5_update_ret(&MD, password_buf, 64);
     count += 64;
   }
-  mbedtls_md5_finish(&MD, key); /* tell MD5 we're done */
+  mbedtls_md5_finish_ret(&MD, key); /* tell MD5 we're done */
 
   /*****************************************************/
   /* Now localize the key with the engineID and pass   */
@@ -278,9 +278,9 @@ snmpv3_password_to_key_md5(
   MEMCPY(password_buf + 16, engineID, engineLength);
   SMEMCPY(password_buf + 16 + engineLength, key, 16);
 
-  mbedtls_md5_starts(&MD);
-  mbedtls_md5_update(&MD, password_buf, 32 + engineLength);
-  mbedtls_md5_finish(&MD, key);
+  mbedtls_md5_starts_ret(&MD);
+  mbedtls_md5_update_ret(&MD, password_buf, 32 + engineLength);
+  mbedtls_md5_finish_ret(&MD, key);
 
   mbedtls_md5_free(&MD);
   return;
@@ -302,7 +302,7 @@ snmpv3_password_to_key_sha(
   u32_t count = 0;
 
   mbedtls_sha1_init(&SH); /* initialize SHA */
-  mbedtls_sha1_starts(&SH);
+  mbedtls_sha1_starts_ret(&SH);
 
   /**********************************************/
   /* Use while loop until we've done 1 Megabyte */
@@ -316,10 +316,10 @@ snmpv3_password_to_key_sha(
       /*************************************************/
       *cp++ = password[password_index++ % passwordlen];
     }
-    mbedtls_sha1_update(&SH, password_buf, 64);
+    mbedtls_sha1_update_ret(&SH, password_buf, 64);
     count += 64;
   }
-  mbedtls_sha1_finish(&SH, key); /* tell SHA we're done */
+  mbedtls_sha1_finish_ret(&SH, key); /* tell SHA we're done */
 
   /*****************************************************/
   /* Now localize the key with the engineID and pass   */
@@ -331,9 +331,9 @@ snmpv3_password_to_key_sha(
   MEMCPY(password_buf + 20, engineID, engineLength);
   SMEMCPY(password_buf + 20 + engineLength, key, 20);
 
-  mbedtls_sha1_starts(&SH);
-  mbedtls_sha1_update(&SH, password_buf, 40 + engineLength);
-  mbedtls_sha1_finish(&SH, key);
+  mbedtls_sha1_starts_ret(&SH);
+  mbedtls_sha1_update_ret(&SH, password_buf, 40 + engineLength);
+  mbedtls_sha1_finish_ret(&SH, key);
 
   mbedtls_sha1_free(&SH);
   return;
diff --git a/src/include/netif/ppp/pppcrypt.h b/src/include/netif/ppp/pppcrypt.h
index c0230bbc..f938e16e 100644
--- a/src/include/netif/ppp/pppcrypt.h
+++ b/src/include/netif/ppp/pppcrypt.h
@@ -100,9 +100,9 @@ extern "C" {
 
 #define lwip_md4_context mbedtls_md4_context
 #define lwip_md4_init mbedtls_md4_init
-#define lwip_md4_starts mbedtls_md4_starts
-#define lwip_md4_update mbedtls_md4_update
-#define lwip_md4_finish mbedtls_md4_finish
+#define lwip_md4_starts mbedtls_md4_starts_ret
+#define lwip_md4_update mbedtls_md4_update_ret
+#define lwip_md4_finish mbedtls_md4_finish_ret
 #define lwip_md4_free mbedtls_md4_free
 
 #define lwip_md5_context mbedtls_md5_context
@@ -114,9 +114,9 @@ extern "C" {
 
 #define lwip_sha1_context mbedtls_sha1_context
 #define lwip_sha1_init mbedtls_sha1_init
-#define lwip_sha1_starts mbedtls_sha1_starts
-#define lwip_sha1_update mbedtls_sha1_update
-#define lwip_sha1_finish mbedtls_sha1_finish
+#define lwip_sha1_starts mbedtls_sha1_starts_ret
+#define lwip_sha1_update mbedtls_sha1_update_ret
+#define lwip_sha1_finish mbedtls_sha1_finish_ret
 #define lwip_sha1_free mbedtls_sha1_free
 
 #define lwip_des_context mbedtls_des_context
-- 
2.39.3 (Apple Git-145)

