#if C
#
#include <mbedtls/aes.h>
#include "mbedtls/md.h"
char ivc[16];
void Encrypt (B4R::Object* o) {
char *pw = (char*)b4r_main::_pw->data;
char *ivc = (char*)b4r_main::_iv->data; //don't want that
//256Hash the PW (32 Bytes)
byte shaResult[32];
mbedtls_md_context_t hash;
mbedtls_md_type_t md_type = MBEDTLS_MD_SHA256;
const size_t pwLength = strlen(pw);
mbedtls_md_init(&hash);
mbedtls_md_setup(&hash, mbedtls_md_info_from_type(md_type), 0);
mbedtls_md_starts(&hash);
mbedtls_md_update(&hash, (const unsigned char *) pw, pwLength);
mbedtls_md_finish(&hash, shaResult);
mbedtls_md_free(&hash);
uint8_t key[32];
memcpy(key, shaResult, 32);
//***********************************************************************************
//Set IV don't want that, too
uint8_t ivu[16];
int i;
for( i = 0; i < 16; i++ )
{
ivu[i]=ivc[i];
}
esp_aes_context ctx;
esp_aes_init( &ctx );
esp_aes_setkey( &ctx, key, 256 );
printf("Before encryption...\n");
esp_aes_crypt_cbc( &ctx, ESP_AES_ENCRYPT, b4r_main::_dec_len, ivu, (uint8_t*)b4r_main::_aesdecrypted->data, (uint8_t*)b4r_main::_aesencrypted->data );
esp_aes_free( &ctx );
}