|
3 | 3 | #include "spi_flash_mmap.h"
|
4 | 4 | #include "esp_ota_ops.h"
|
5 | 5 | #include "esp_image_format.h"
|
| 6 | +#include "mbedtls/aes.h" |
6 | 7 |
|
7 | 8 | static const char * _err2str(uint8_t _error){
|
8 | 9 | if(_error == UPDATE_ERROR_OK){
|
@@ -312,17 +313,27 @@ bool UpdateClass::_decryptBuffer(){
|
312 | 313 | uint8_t tweaked_key[ENCRYPTED_KEY_SIZE]; //tweaked crypt key
|
313 | 314 | int done = 0;
|
314 | 315 |
|
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 ); |
317 | 325 | while((_bufferLen - done) >= ENCRYPTED_BLOCK_SIZE){
|
318 | 326 | for(int i=0; i < ENCRYPTED_BLOCK_SIZE; i++) _cryptBuffer[(ENCRYPTED_BLOCK_SIZE - 1) - i] = _buffer[i + done]; //reverse order 16 bytes to decrypt
|
319 | 327 | if( ((_cryptAddress + _progress + done) % ENCRYPTED_TWEAK_BLOCK_SIZE) == 0 || done == 0 ){
|
320 | 328 | _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 ) ){ |
322 | 333 | return false;
|
323 | 334 | }
|
324 | 335 | }
|
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 |
326 | 337 | return false;
|
327 | 338 | }
|
328 | 339 | 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