diff --git a/components/esp8266/include/rom/md5_hash.h b/components/esp8266/include/rom/md5_hash.h index f116f1e6..9111a0e3 100644 --- a/components/esp8266/include/rom/md5_hash.h +++ b/components/esp8266/include/rom/md5_hash.h @@ -16,17 +16,21 @@ #define _ROM_MD5_HASH_H_ #include +#include "sdkconfig.h" #ifdef __cplusplus extern "C" { #endif +#ifdef CONFIG_ESP_MD5 +#include "esp_md5.h" +#else struct MD5Context { uint32_t buf[4]; uint32_t bits[2]; uint8_t in[64]; }; - +#endif void MD5Init(struct MD5Context *context); void MD5Update(struct MD5Context *context, unsigned char const *buf, unsigned len); void MD5Final(unsigned char digest[16], struct MD5Context *context); diff --git a/components/ssl/mbedtls/port/esp8266/include/mbedtls/esp_config.h b/components/ssl/mbedtls/port/esp8266/include/mbedtls/esp_config.h index 40bf850b..6243a73b 100644 --- a/components/ssl/mbedtls/port/esp8266/include/mbedtls/esp_config.h +++ b/components/ssl/mbedtls/port/esp8266/include/mbedtls/esp_config.h @@ -286,7 +286,6 @@ //#define MBEDTLS_GCM_ALT //#define MBEDTLS_MD2_ALT //#define MBEDTLS_MD4_ALT -//#define MBEDTLS_MD5_ALT //#define MBEDTLS_RIPEMD160_ALT //#define MBEDTLS_RSA_ALT //#define MBEDTLS_XTEA_ALT @@ -301,6 +300,9 @@ #define MBEDTLS_SHA512_ALT #endif +#ifdef CONFIG_ESP_MD5 +#define MBEDTLS_MD5_ALT +#endif /* * When replacing the elliptic curve module, pleace consider, that it is * implemented with two .c files: diff --git a/components/ssl/mbedtls/port/esp8266/include/md5_alt.h b/components/ssl/mbedtls/port/esp8266/include/md5_alt.h new file mode 100644 index 00000000..8a0b808b --- /dev/null +++ b/components/ssl/mbedtls/port/esp8266/include/md5_alt.h @@ -0,0 +1,51 @@ +/* + * Copyright (C) 2006-2015, ARM Limited, All Rights Reserved + * SPDX-License-Identifier: Apache-2.0 + * + * Licensed under the Apache License, Version 2.0 (the "License"); you may + * not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, WITHOUT + * WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + * + * + */ +#ifndef MD5_ALT_H +#define MD5_ALT_H + +#ifdef __cplusplus +extern "C" { +#endif + +#if defined(MBEDTLS_MD5_ALT) +#include "esp_md5.h" + +typedef esp_md5_context_t mbedtls_md5_context; + +#define mbedtls_md5_init(_ctx) { } + +#define mbedtls_md5_free(_ctx) { } + +#define mbedtls_md5_clone(_d, _s) { *(_d) = *(_s); } + +#define mbedtls_md5_starts_ret(_ctx) esp_md5_init(_ctx) + +#define mbedtls_md5_update_ret(_ctx, _s, _l) esp_md5_update(_ctx, _s, _l) + +#define mbedtls_md5_finish_ret(_ctx, _d) esp_md5_final(_ctx, _d) + +#define mbedtls_internal_md5_process(_ctx, _s) esp_md5_update(_ctx, _s, 64) +#endif /* MBEDTLS_MD5_ALT */ + +#ifdef __cplusplus +} +#endif + +#endif + diff --git a/components/util/Kconfig b/components/util/Kconfig index 4ca14603..620a46ad 100644 --- a/components/util/Kconfig +++ b/components/util/Kconfig @@ -36,4 +36,19 @@ config ESP_AES Disabling the "assert" function at menuconfig can speed up the calculation. +config ESP_MD5 + bool "Enable Espressif MD5" + default y + help + Enable Espressif MD5 for other components to + speed up process speed and save code size. + + ESP8285 is like ESP8266 + 1MB flash, but its internal I/O connection from CPU + core to flash is DIO not QIO, which makes it read flash data slower. + So the function will speed up ESP8285 obviously. + + The calculation uses "ibus_data" to speed up load data from instruction bus. + + Disabling the "assert" function at menuconfig can speed up the calculation. + endmenu # Util diff --git a/components/util/include/esp_md5.h b/components/util/include/esp_md5.h index 4532fa0c..edbca1f5 100644 --- a/components/util/include/esp_md5.h +++ b/components/util/include/esp_md5.h @@ -23,7 +23,7 @@ extern "C" { /** * @brief MD5 context structure */ -typedef struct esp_md5_context { +typedef struct MD5Context{ uint32_t total[2]; /*!< number of bytes processed */ uint32_t state[4]; /*!< intermediate digest state */ uint8_t buffer[64]; /*!< data block being processed */ diff --git a/components/wpa_supplicant/src/crypto/md5-internal.c b/components/wpa_supplicant/src/crypto/md5-internal.c index a430e297..c4dbd00b 100644 --- a/components/wpa_supplicant/src/crypto/md5-internal.c +++ b/components/wpa_supplicant/src/crypto/md5-internal.c @@ -12,6 +12,10 @@ * See README and COPYING for more details. */ +#include "sdkconfig.h" + +#ifndef CONFIG_ESP_MD5 + #include "crypto/includes.h" #include "crypto/common.h" @@ -296,3 +300,34 @@ MD5Transform(u32 buf[4], u32 const in[16]) buf[3] += d; } /* ===== end - public domain MD5 implementation ===== */ +#else /* CONFIG_ESP_AES */ +#include "esp_md5.h" + +int md5_vector(size_t num_elem, const uint8_t *addr[], const size_t *len, uint8_t *mac) +{ + esp_md5_context_t ctx; + size_t i; + + esp_md5_init(&ctx); + for (i = 0; i < num_elem; i++) + esp_md5_update(&ctx, addr[i], len[i]); + esp_md5_final(&ctx, mac); + return 0; +} + +void MD5Init(esp_md5_context_t *context) +{ + esp_md5_init(context); +} + +void MD5Update(esp_md5_context_t *context, uint8_t const *buf, size_t len) +{ + esp_md5_update(context, buf, len); +} + +void MD5Final(uint8_t digest[16], esp_md5_context_t *context) +{ + esp_md5_final(context, digest); +} +#endif +