mirror of
https://github.com/espressif/esp-idf.git
synced 2024-10-05 20:47:46 -04:00
tcp_isn: use ROM APIs for md5 calculations
This commit is contained in:
parent
b8925ab48b
commit
8099dd089d
@ -74,17 +74,10 @@
|
||||
#include "lwip/ip_addr.h"
|
||||
#include "lwip/sys.h"
|
||||
#include <string.h>
|
||||
#include "esp_rom_md5.h"
|
||||
|
||||
#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 u32_t base_time;
|
||||
|
||||
@ -119,7 +112,6 @@ 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;
|
||||
u8_t output[16];
|
||||
u32_t isn;
|
||||
|
||||
@ -167,10 +159,21 @@ lwip_hook_tcp_isn(const ip_addr_t *local_ip, u16_t local_port,
|
||||
|
||||
/* The secret and padding are already filled in. */
|
||||
|
||||
/* Generate the hash, using MD5. */
|
||||
md5_starts(&ctx);
|
||||
md5_update(&ctx, input, sizeof(input));
|
||||
md5_finish(&ctx, output);
|
||||
/*
|
||||
* Generate the hash using ROM MD5 APIs
|
||||
* This hook is invoked in the context of TCP/IP (tiT) task and
|
||||
* 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;
|
||||
esp_rom_md5_init(&ctx);
|
||||
esp_rom_md5_update(&ctx, input, sizeof(input));
|
||||
esp_rom_md5_final(output, &ctx);
|
||||
|
||||
/* Arbitrarily take the first 32 bits from the generated hash. */
|
||||
MEMCPY(&isn, output, sizeof(isn));
|
||||
|
@ -27,8 +27,8 @@
|
||||
* Author: David van Moolenbroek <david@minix3.org>
|
||||
*/
|
||||
|
||||
#ifndef LWIP_HDR_CONTRIB_ADDONS_TCP_ISN_H
|
||||
#define LWIP_HDR_CONTRIB_ADDONS_TCP_ISN_H
|
||||
#ifndef LWIP_TCP_ISN_H
|
||||
#define LWIP_TCP_ISN_H
|
||||
|
||||
#include "lwip/opt.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 /* LWIP_HDR_CONTRIB_ADDONS_TCP_ISN_H */
|
||||
#endif /* LWIP_TCP_ISN_H */
|
||||
|
Loading…
Reference in New Issue
Block a user