I tried to test out this MD5 library (https://github.com/tzikis/ArduinoMD5 ) as a hash function on arduino uno.

What I have done is that I placed the MD5.cpp and MD5.h to the folder below: C:\Program Files (x86)\Arduino\libraries\MD5

And launched arduino IDE 1.8.9 to test the example provided (https://github.com/tzikis/ArduinoMD5/blob/master/examples/MD5_Hash/MD5_Hash.ino):

#include <MD5.h>
This is en example of how to use my MD5 library. It provides two
easy-to-use methods, one for generating the MD5 hash, and the second
one to generate the hex encoding of the hash, which is frequently used.
void setup()
  //initialize serial
  //give it a second
  //generate the MD5 hash for our string
  unsigned char* hash=MD5::make_hash("hello world");
  //generate the digest (hex encoding) of our hash
  char *md5str = MD5::make_digest(hash, 16);
  //print it on our serial monitor
  //Give the Memory back to the System if you run the md5 Hash generation in a loop

void loop()

However when run verify and compile, it works but got the warnings below:

...\sketch_may02a_MD5_test.ino.ino: In function 'void setup()':

warning: ISO C++ forbids converting a string constant to 'char*' [-Wwrite-strings]

   unsigned char* hash=MD5::make_hash("hello world");


C:\Program Files (x86)\Arduino\libraries\MD5\MD5.cpp: 
In static member function 'static void MD5::MD5Update(void*, const void*, size_t)':

C:\Program Files (x86)\Arduino\libraries\MD5\MD5.cpp:207:21: 
warning: right shift count >= width of type [-Wshift-count-overflow]

  ctx->hi += size >> 29;


I know little of c++, can anyone help to fix this? Thanks a lot!!

  • size is of type size_t, which seems to be an unsigned int on the Uno, meaning 16 bits. Shifting it by 29 bits would always result in zero, I think. And that seems a complicated way to write 0. – chrisl May 2 '19 at 20:06
  • 1
    @chrisl: Shifting by too much does not result in 0. It results in undefined behavior. – AnT May 2 '19 at 20:30
  • You better don't mess with the arduino system files at C:\Program Files (x86)\Arduino. Can you uninstall arduino, delete C:\Program Files (x86)\Arduino and reinstall it? Are your sketches located at Documents\Arduino? There is a libraries folder in that folder alongside the folders of your projects. That libraries folder is meant to put libraries into that you have downloaded. When using the arduino library manager and a library is downloaded, it will be put there as well. – Jot May 3 '19 at 8:59
  • @Jot Thanks for the tips. I noticed that it will also grab the libraries from the Document\Arduino\libraries which I thought it was only used with the arduino installed from windows app store. As you suggest, I should just use it for all the libraries to be deployed in the future. – Harry May 3 '19 at 10:44

....\sketch_may02a_MD5_test.ino\sketch_may02a_MD5_test.ino.ino:15:51: warning: ISO C++ forbids converting a string constant to 'char*' [-Wwrite-strings]

That is a flaw in the library. The author defined the function as taking a char * instead of a const char *. You can ignore it, it's just a warning - however maybe raising the issue with the author could be a good idea.

C:\Program Files (x86)\Arduino\libraries\MD5\MD5.cpp:207:21: warning: right shift count >= width of type [-Wshift-count-overflow]

This one is a little more awkward. The size variable is defined as type size_t. That varies in length depending on the architecture the software is compiled on. On the 8-bit Arduinos that's a 16 bit variable. On 32-bit Arduinos, like the Due, it's a 32-bit variable.

It is probable that the author developed the library using a 32-bit Arudino (or Arduino-compatible) device - in which case he would never see that warning (since 29 is less than 32). However anyone that then uses an 8-bit Arduino gets the warning, and probably a corrupt hash.

However, it looks like it should only be a problem if size is too big - and it can't be on an 8-bit Arduino. So again you can ignore it, but the author should really be made aware of the issue.

| improve this answer | |
  • OK, before I consider this is answered. Can it be fixed by a couple lines such as replacing the size_t with something else from the .cpp file? If so, I would perhaps give it a try and push it to a public github project. – Harry May 2 '19 at 20:17
  • Shifting past bitwidth is undefined behavior. It should not be ignored. – Edgar Bonet May 2 '19 at 20:20
  • @EdgarBonet While I agree it shouldn't be ignored in general terms, but in this situation it will be shifting nothing anyway, so with nothing to shift it doesn't really matter. Raising an issue with the author should still be done, of course. – Majenko May 2 '19 at 20:33
  • @Harry You could do a search and replace of size_t to uint32_t, and change the parameter of make_hash() to const char *. – Majenko May 2 '19 at 20:35

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.