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).
pull/4119/head
Hasnain Virk 2017-05-16 18:20:35 +03:00
parent c8933e4c71
commit b51fbe817b
3 changed files with 11 additions and 10 deletions

View File

@ -76,19 +76,21 @@
#include <string.h>
/* pull in md5 of ppp? */
#if !PPP_SUPPORT
#undef PPP_SUPPORT
#define PPP_SUPPORT 1
#define PPP_FAKED_ON 1
#endif
#include "netif/ppp/ppp_opts.h"
#include "netif/ppp/ppp.h"
#include "netif/ppp/pppcrypt.h"
#if !LWIP_USE_EXTERNAL_POLARSSL && !LWIP_USE_EXTERNAL_MBEDTLS
#if PPP_FAKED_ON && !LWIP_USE_EXTERNAL_POLARSSL && !LWIP_USE_EXTERNAL_MBEDTLS
#undef LWIP_INCLUDED_POLARSSL_MD5
#define LWIP_INCLUDED_POLARSSL_MD5 1
#include "netif/ppp/polarssl/lwip_md5.c"
#endif
#if LWIP_USE_EXTERNAL_MBEDTLS
#include "mbedtls/inc/mbedtls/md5.h"
#define md5_context mbedtls_md5_context
#endif
static u8_t input[64];
static u32_t base_time;
@ -124,7 +126,7 @@ u32_t
lwip_hook_tcp_isn(const ip_addr_t *local_ip, u16_t local_port,
const ip_addr_t *remote_ip, u16_t remote_port)
{
md5_context ctx;
lwip_md5_context ctx;
u8_t output[16];
u32_t isn;

View File

@ -111,7 +111,7 @@ static void mbed_lwip_socket_callback(struct netconn *nc, enum netconn_evt eh, u
/* TCP/IP and Network Interface Initialisation */
static struct netif lwip_netif;
#if LWIP_IPV4
#if LWIP_DHCP
static bool lwip_dhcp = false;
#endif
static char lwip_mac_address[NSAPI_MAC_SIZE];

View File

@ -283,8 +283,6 @@
#define PRINTPKT_SUPPORT 0
#define PPP_LOGIT_BUFSIZE 512
//Hate the config hassle.
//#define LWIP_USE_EXTERNAL_MBEDTLS 1
// Broadcast
#define IP_SOF_BROADCAST 0
#define IP_SOF_BROADCAST_RECV 0
@ -312,7 +310,8 @@
#include "lwip_random.h"
#include "lwip_tcp_isn.h"
#define LWIP_HOOK_TCP_ISN lwip_hook_tcp_isn
#if MBEDTLS_MD5_C
#ifdef MBEDTLS_MD5_C
#include "mbedtls/inc/mbedtls/md5.h"
#define LWIP_USE_EXTERNAL_MBEDTLS 1
#endif