mirror of
https://github.com/espressif/ESP8266_RTOS_SDK.git
synced 2025-05-30 06:59:02 +08:00
feat(util): Add faster MD5 for ESP8266 SoC
This commit is contained in:
@ -16,17 +16,21 @@
|
||||
#define _ROM_MD5_HASH_H_
|
||||
|
||||
#include <stdint.h>
|
||||
#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);
|
||||
|
@ -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:
|
||||
|
51
components/ssl/mbedtls/port/esp8266/include/md5_alt.h
Normal file
51
components/ssl/mbedtls/port/esp8266/include/md5_alt.h
Normal file
@ -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
|
||||
|
@ -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
|
||||
|
@ -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 */
|
||||
|
@ -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
|
||||
|
||||
|
Reference in New Issue
Block a user