Skip to content

Commit 927be07

Browse files
committed
Update MD5/SHA1 method definitions for latest ESP-IDF
1 parent 2ab974a commit 927be07

File tree

2 files changed

+10
-19
lines changed

2 files changed

+10
-19
lines changed

src/AsyncWebSocket.cpp

Lines changed: 7 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -26,18 +26,7 @@
2626
#include <libb64/cencode.h>
2727

2828
#ifndef ESP8266
29-
extern "C" {
30-
typedef struct {
31-
uint32_t state[5];
32-
uint32_t count[2];
33-
unsigned char buffer[64];
34-
} SHA1_CTX;
35-
36-
void SHA1Transform(uint32_t state[5], const unsigned char buffer[64]);
37-
void SHA1Init(SHA1_CTX* context);
38-
void SHA1Update(SHA1_CTX* context, const unsigned char* data, uint32_t len);
39-
void SHA1Final(unsigned char digest[20], SHA1_CTX* context);
40-
}
29+
#include "mbedtls/sha1.h"
4130
#else
4231
#include <Hash.h>
4332
#endif
@@ -1180,10 +1169,12 @@ AsyncWebSocketResponse::AsyncWebSocketResponse(const String& key, AsyncWebSocket
11801169
sha1(key + WS_STR_UUID, hash);
11811170
#else
11821171
(String&)key += WS_STR_UUID;
1183-
SHA1_CTX ctx;
1184-
SHA1Init(&ctx);
1185-
SHA1Update(&ctx, (const unsigned char*)key.c_str(), key.length());
1186-
SHA1Final(hash, &ctx);
1172+
mbedtls_sha1_context ctx;
1173+
mbedtls_sha1_init(&ctx);
1174+
mbedtls_sha1_starts_ret(&ctx);
1175+
mbedtls_sha1_update_ret(&ctx, (const unsigned char*)key.c_str(), key.length());
1176+
mbedtls_sha1_finish_ret(&ctx, hash);
1177+
mbedtls_sha1_free(&ctx);
11871178
#endif
11881179
base64_encodestate _state;
11891180
base64_init_encodestate(&_state);

src/WebAuthentication.cpp

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -77,9 +77,9 @@ static bool getMD5(uint8_t * data, uint16_t len, char * output){//33 bytes or mo
7777
memset(_buf, 0x00, 16);
7878
#ifdef ESP32
7979
mbedtls_md5_init(&_ctx);
80-
mbedtls_md5_starts(&_ctx);
81-
mbedtls_md5_update(&_ctx, data, len);
82-
mbedtls_md5_finish(&_ctx, _buf);
80+
mbedtls_md5_starts_ret(&_ctx);
81+
mbedtls_md5_update_ret(&_ctx, data, len);
82+
mbedtls_md5_finish_ret(&_ctx, _buf);
8383
#else
8484
MD5Init(&_ctx);
8585
MD5Update(&_ctx, data, len);

0 commit comments

Comments
 (0)