Skip to content

Commit b51fbe8

Browse files
author
Hasnain Virk
committed
mbedtls md5 or lwip internal crypt Fudge
Some targets define MBEDTLS_md5_C in targets.json in order to force the system to use external mbedtls instead of lwip internal crypt, i.e., polarssl. LWIP's internal md5 mechanism is tied to PPP for some reason. In a previosly merged commit an attempt was made to steal md5 functions by faking that PPP was turned on. However that solution was broken in case of really turning on PPP functionality. This commit fixes the breakage and also corrects the logic in case a target decides to use external md5 implementation from mbedtls or otherwise (i.e, wants to stick to the internal implementation).
1 parent c8933e4 commit b51fbe8

File tree

3 files changed

+11
-10
lines changed

3 files changed

+11
-10
lines changed

features/FEATURE_LWIP/lwip-interface/lwip-sys/lwip_tcp_isn.c

Lines changed: 8 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -76,19 +76,21 @@
7676
#include <string.h>
7777

7878
/* pull in md5 of ppp? */
79+
#if !PPP_SUPPORT
80+
#undef PPP_SUPPORT
7981
#define PPP_SUPPORT 1
82+
#define PPP_FAKED_ON 1
83+
#endif
84+
8085
#include "netif/ppp/ppp_opts.h"
8186
#include "netif/ppp/ppp.h"
8287
#include "netif/ppp/pppcrypt.h"
83-
#if !LWIP_USE_EXTERNAL_POLARSSL && !LWIP_USE_EXTERNAL_MBEDTLS
88+
89+
#if PPP_FAKED_ON && !LWIP_USE_EXTERNAL_POLARSSL && !LWIP_USE_EXTERNAL_MBEDTLS
8490
#undef LWIP_INCLUDED_POLARSSL_MD5
8591
#define LWIP_INCLUDED_POLARSSL_MD5 1
8692
#include "netif/ppp/polarssl/lwip_md5.c"
8793
#endif
88-
#if LWIP_USE_EXTERNAL_MBEDTLS
89-
#include "mbedtls/inc/mbedtls/md5.h"
90-
#define md5_context mbedtls_md5_context
91-
#endif
9294

9395
static u8_t input[64];
9496
static u32_t base_time;
@@ -124,7 +126,7 @@ u32_t
124126
lwip_hook_tcp_isn(const ip_addr_t *local_ip, u16_t local_port,
125127
const ip_addr_t *remote_ip, u16_t remote_port)
126128
{
127-
md5_context ctx;
129+
lwip_md5_context ctx;
128130
u8_t output[16];
129131
u32_t isn;
130132

features/FEATURE_LWIP/lwip-interface/lwip_stack.c

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -111,7 +111,7 @@ static void mbed_lwip_socket_callback(struct netconn *nc, enum netconn_evt eh, u
111111

112112
/* TCP/IP and Network Interface Initialisation */
113113
static struct netif lwip_netif;
114-
#if LWIP_IPV4
114+
#if LWIP_DHCP
115115
static bool lwip_dhcp = false;
116116
#endif
117117
static char lwip_mac_address[NSAPI_MAC_SIZE];

features/FEATURE_LWIP/lwip-interface/lwipopts.h

Lines changed: 2 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -283,8 +283,6 @@
283283
#define PRINTPKT_SUPPORT 0
284284
#define PPP_LOGIT_BUFSIZE 512
285285

286-
//Hate the config hassle.
287-
//#define LWIP_USE_EXTERNAL_MBEDTLS 1
288286
// Broadcast
289287
#define IP_SOF_BROADCAST 0
290288
#define IP_SOF_BROADCAST_RECV 0
@@ -312,7 +310,8 @@
312310
#include "lwip_random.h"
313311
#include "lwip_tcp_isn.h"
314312
#define LWIP_HOOK_TCP_ISN lwip_hook_tcp_isn
315-
#if MBEDTLS_MD5_C
313+
#ifdef MBEDTLS_MD5_C
314+
#include "mbedtls/inc/mbedtls/md5.h"
316315
#define LWIP_USE_EXTERNAL_MBEDTLS 1
317316
#endif
318317

0 commit comments

Comments
 (0)