2

I am doing a school project and wanted to implement HMAC on a arduino UNO like board. I have been testing the Cryptosuite, but none of the examples work for me. Such as this one: https://github.com/Cathedrow/Cryptosuite/blob/master/Sha/examples/hmacsha256test/hmacsha256test.pde

This one https://github.com/simonratner/Arduino-SHA-256, a trimmed-down version, which sounds good but there's none working example.

Can any one point me to the right direction? Thanks a lot!!

2

When you are asking a question, here or on a forum, then please tell what you did and what the result was. When you say that it is not working, then we have not enough information and your question might not get answered.

I have tested the first link that you gave to Cryptosuite. It is outdated and needs to be fixed.
I renamed "hmacsha256test.pde" to "hmacsha256test.ino".
The compiler errors and warnings are in the lower part of the Arduino IDE. Scroll up to find the first problem and fix that. Repeat it until it works.

The PROGMEM requires that the 'const' keyword is used. For example in "sha256.cpp":

const uint32_t sha256K[] PROGMEM = {

The 'write' function should return a size_t value.

In sha256.h:

// virtual void write(uint8_t);
virtual size_t write(uint8_t);

In sha256.cpp:

size_t Sha256Class::write(uint8_t data) {
  ++byteCount;
  addUncounted(data);
  return 1;
}

Then it compiles and runs on a Arduino Uno, although there is a warning for low memory because 75% of the sram is used.

The second link is a changed version of the same Cryptosuite. It should be able to use the examples of the Cryptosuite, but it does not.
I can make that work as well.

Using the same example of the Cryptosuite "hmacsha256test.pde" (I renamed it to "hmacsha256test.ino"), create a object 'sha' after including the "sha256.h":

#include "sha256.h"
Sha256 sha;

In the example, replace all "Sha256" function calls with "sha" function calls:

sha.initHmac(hmacKey1,20);
sha.print("Hi There");

Then it works as well.

1
  • Thank you very much!! You are a great teacher! I have Arduino IDE 1.8.9 downloaded and installed. And added a SHA folder inside "C:\Program Files (x86)\Arduino\libraries\" to install the libraries (sha256.cpp and sha256.h) adopted from the second link and use the example (hmacsha256test.pde) from the first link, and made changes as you suggested. It works well!! Although I am getting "Low memory available, stability problems may occur" due to the sketch is taking up 22% of the storage space. But that is fine for a test of the HMAC for arduino. Thanks again! Merci! Gracias! Vielen Dank! 谢谢!
    – Harry
    May 2 '19 at 10:29
1

I have used the https://github.com/Cathedrow/Cryptosuite/ on ESP8266. For that in addition to the changes desribed by Jot it is enough to remove

#include <avr/io.h>
#include <avr/pgmspace.h>

from the header files. Then it is working fine.

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.