tcp_isn: use ROM APIs for md5 calculations
This commit is contained in:
parent
a4ad6f7547
commit
59112bbd76
|
@ -74,17 +74,11 @@
|
||||||
#include "lwip/ip_addr.h"
|
#include "lwip/ip_addr.h"
|
||||||
#include "lwip/sys.h"
|
#include "lwip/sys.h"
|
||||||
#include <string.h>
|
#include <string.h>
|
||||||
|
#include "rom/md5_hash.h"
|
||||||
|
#include "soc/soc_memory_layout.h"
|
||||||
|
|
||||||
#ifdef LWIP_HOOK_TCP_ISN
|
#ifdef LWIP_HOOK_TCP_ISN
|
||||||
|
|
||||||
/* pull in md5 of ppp? */
|
|
||||||
#include "netif/ppp/ppp_opts.h"
|
|
||||||
#if !PPP_SUPPORT || (!LWIP_USE_EXTERNAL_POLARSSL && !LWIP_USE_EXTERNAL_MBEDTLS)
|
|
||||||
#undef LWIP_INCLUDED_POLARSSL_MD5
|
|
||||||
#define LWIP_INCLUDED_POLARSSL_MD5 1
|
|
||||||
#include "netif/ppp/polarssl/md5.h"
|
|
||||||
#endif
|
|
||||||
|
|
||||||
static u8_t input[64];
|
static u8_t input[64];
|
||||||
static u32_t base_time;
|
static u32_t base_time;
|
||||||
|
|
||||||
|
@ -119,7 +113,6 @@ u32_t
|
||||||
lwip_hook_tcp_isn(const ip_addr_t *local_ip, u16_t local_port,
|
lwip_hook_tcp_isn(const ip_addr_t *local_ip, u16_t local_port,
|
||||||
const ip_addr_t *remote_ip, u16_t remote_port)
|
const ip_addr_t *remote_ip, u16_t remote_port)
|
||||||
{
|
{
|
||||||
md5_context ctx;
|
|
||||||
u8_t output[16];
|
u8_t output[16];
|
||||||
u32_t isn;
|
u32_t isn;
|
||||||
|
|
||||||
|
@ -167,10 +160,21 @@ lwip_hook_tcp_isn(const ip_addr_t *local_ip, u16_t local_port,
|
||||||
|
|
||||||
/* The secret and padding are already filled in. */
|
/* The secret and padding are already filled in. */
|
||||||
|
|
||||||
/* Generate the hash, using MD5. */
|
/*
|
||||||
md5_starts(&ctx);
|
* Generate the hash using ROM MD5 APIs
|
||||||
md5_update(&ctx, input, sizeof(input));
|
* This hook is invoked in the context of TCP/IP (tiT) task and
|
||||||
md5_finish(&ctx, output);
|
* it is unlikely that its stack would be placed in SPIRAM. Hence
|
||||||
|
* even with SPIRAM enabled case and ESP32 revision < 3, using ROM
|
||||||
|
* APIs should not create any issues.
|
||||||
|
*/
|
||||||
|
#if CONFIG_SPIRAM_ALLOW_STACK_EXTERNAL_MEMORY
|
||||||
|
assert(!esp_ptr_external_ram(get_sp()));
|
||||||
|
#endif
|
||||||
|
|
||||||
|
struct MD5Context ctx;
|
||||||
|
MD5Init(&ctx);
|
||||||
|
MD5Update(&ctx, input, sizeof(input));
|
||||||
|
MD5Final(output, &ctx);
|
||||||
|
|
||||||
/* Arbitrarily take the first 32 bits from the generated hash. */
|
/* Arbitrarily take the first 32 bits from the generated hash. */
|
||||||
MEMCPY(&isn, output, sizeof(isn));
|
MEMCPY(&isn, output, sizeof(isn));
|
||||||
|
|
|
@ -27,8 +27,8 @@
|
||||||
* Author: David van Moolenbroek <david@minix3.org>
|
* Author: David van Moolenbroek <david@minix3.org>
|
||||||
*/
|
*/
|
||||||
|
|
||||||
#ifndef LWIP_HDR_CONTRIB_ADDONS_TCP_ISN_H
|
#ifndef LWIP_TCP_ISN_H
|
||||||
#define LWIP_HDR_CONTRIB_ADDONS_TCP_ISN_H
|
#define LWIP_TCP_ISN_H
|
||||||
|
|
||||||
#include "lwip/opt.h"
|
#include "lwip/opt.h"
|
||||||
#include "lwip/ip_addr.h"
|
#include "lwip/ip_addr.h"
|
||||||
|
@ -45,4 +45,4 @@ u32_t lwip_hook_tcp_isn(const ip_addr_t *local_ip, u16_t local_port,
|
||||||
}
|
}
|
||||||
#endif
|
#endif
|
||||||
|
|
||||||
#endif /* LWIP_HDR_CONTRIB_ADDONS_TCP_ISN_H */
|
#endif /* LWIP_TCP_ISN_H */
|
||||||
|
|
Loading…
Reference in a new issue