Skip to content

Commit 58bea5c

Browse files
authored
Fix C2 compilation for Updater.cpp (espressif#9228)
1 parent f18b690 commit 58bea5c

File tree

2 files changed

+15
-5
lines changed

2 files changed

+15
-5
lines changed

libraries/Update/src/Update.h

-1
Original file line numberDiff line numberDiff line change
@@ -5,7 +5,6 @@
55
#include <MD5Builder.h>
66
#include <functional>
77
#include "esp_partition.h"
8-
#include "aes/esp_aes.h"
98

109
#define UPDATE_ERROR_OK (0)
1110
#define UPDATE_ERROR_WRITE (1)

libraries/Update/src/Updater.cpp

+15-4
Original file line numberDiff line numberDiff line change
@@ -3,6 +3,7 @@
33
#include "spi_flash_mmap.h"
44
#include "esp_ota_ops.h"
55
#include "esp_image_format.h"
6+
#include "mbedtls/aes.h"
67

78
static const char * _err2str(uint8_t _error){
89
if(_error == UPDATE_ERROR_OK){
@@ -312,17 +313,27 @@ bool UpdateClass::_decryptBuffer(){
312313
uint8_t tweaked_key[ENCRYPTED_KEY_SIZE]; //tweaked crypt key
313314
int done = 0;
314315

315-
esp_aes_context ctx; //initialize AES
316-
esp_aes_init( &ctx );
316+
/*
317+
Mbedtls functions will be replaced with esp_aes functions when hardware acceleration is available
318+
319+
To Do:
320+
Replace mbedtls for the cases where there's no hardware acceleration
321+
*/
322+
323+
mbedtls_aes_context ctx; //initialize AES
324+
mbedtls_aes_init( &ctx );
317325
while((_bufferLen - done) >= ENCRYPTED_BLOCK_SIZE){
318326
for(int i=0; i < ENCRYPTED_BLOCK_SIZE; i++) _cryptBuffer[(ENCRYPTED_BLOCK_SIZE - 1) - i] = _buffer[i + done]; //reverse order 16 bytes to decrypt
319327
if( ((_cryptAddress + _progress + done) % ENCRYPTED_TWEAK_BLOCK_SIZE) == 0 || done == 0 ){
320328
_cryptKeyTweak(_cryptAddress + _progress + done, tweaked_key); //update tweaked crypt key
321-
if( esp_aes_setkey( &ctx, tweaked_key, 256 ) ){
329+
if( mbedtls_aes_setkey_enc( &ctx, tweaked_key, 256 ) ){
330+
return false;
331+
}
332+
if( mbedtls_aes_setkey_dec( &ctx, tweaked_key, 256 ) ){
322333
return false;
323334
}
324335
}
325-
if( esp_aes_crypt_ecb( &ctx, ESP_AES_ENCRYPT, _cryptBuffer, _cryptBuffer ) ){ //use ESP_AES_ENCRYPT to decrypt flash code
336+
if( mbedtls_aes_crypt_ecb( &ctx, MBEDTLS_AES_ENCRYPT, _cryptBuffer, _cryptBuffer ) ){ //use MBEDTLS_AES_ENCRYPT to decrypt flash code
326337
return false;
327338
}
328339
for(int i=0; i < ENCRYPTED_BLOCK_SIZE; i++) _buffer[i + done] = _cryptBuffer[(ENCRYPTED_BLOCK_SIZE - 1) - i]; //reverse order 16 bytes from decrypt

0 commit comments

Comments
 (0)