josephpal / esp32-Encrypt

ESP32 AES 128bit Encryption with SPIFFS support
48 stars 13 forks source link

compiler warning and "one last thing" #6

Open homonto opened 2 years ago

homonto commented 2 years ago

Hi, I started using your library for my project and there are 2 issues:

warning: ISO C++ forbids converting a string constant to 'char*' [-Wwrite-strings]
   char*  key = "mykey";

when my assignment looks like this:

  char*  key = "mykey";
  cipher->setKey(key);

Program compiles but warnings are there - I am sure cleaner compilation would be better ;-) Changing to: char* key = (char*)"mykey"; solves the issue but the same is with regards to hardcoded declaration in Cipher.cpp

void Cipher::setKey(char * key) {
  privateCipherKey = key;
}

Btw: thank you for your great job!

generic-beat-detector commented 2 years ago

@homonto One possible solution to storing the key in the (ELF) binary as a non-string (i.e. not be visible in the .rodata section) is to statically -- and painfully -- initialize the elements of an array of, say, type float to numerical values corresponding to the (ASCII) characters of the key. Then, at runtime, you could malloc() a char * buffer and initialize its elements (via a loop) using typecasts of the corresponding elements in the FP array. This dynamically allocated char * buffer becomes C-string key. Does this make sense?