Pi Pico HMAC_SHA1 help

Good evening everyone. As the title suggests... I need help with a working example of HMAC_SHA1. I've found a few libraries, but none seem to work with the RP2040 (pi Pico). It could very well be me (not ruling that out). I'm at a loss and my brain hurts. closest I got was simpleHOTP... but I don't think that is true HMAC_SHA1 (at least my hash didn't come out the same as my known hash). again... any help would be GREATLY appreciated.

This is a pure C implementation of the two algorithms, so that should run on the Pico.

You know that SHA1 shouldn't be used for new projects as it has to be considered cracked, don't you?

Thank you! I did come across that, but thought it required OpenSSL. I’ll look further into it. Thank you again.

I do know it’s not secure… but it’s actually recreating something from 20 years ago so I have no choice as that was the route they took :). I do appreciate the heads up though

Ok... I tried it... but it fails :frowning:

#include "hmac/hmac.h"

byte key[] = { 0x00, 0x01, 0x02, 0x03, 0x04, 0x05, 0x06, 0x07 };
byte data[] = { 't', 'e', 's', 't' };

void setup() {
  Serial.begin(115200);
  delay(7000);
}

void loop() {
  byte result[20];
  int len = sizeof(result);
  hmac_sha1(key, sizeof(key), data, sizeof(data), result, (size_t*)len);
  
  Serial.print("HMAC-SHA1: ");
  
  for (int i = 0; i < sizeof(result); i++) {
    Serial.print(result[i], HEX);
    Serial.print(" ");
  }
  
  Serial.println();
  
  delay(1000);
}

Here is the error:

c:/users/dtomc/appdata/local/arduino15/packages/rp2040/tools/pqt-gcc/1.5.0-b-c7bab52/bin/../lib/gcc/arm-none-eabi/10.3.0/../../../../arm-none-eabi/bin/ld.exe: sketch\encode.ino.cpp.o: in function `loop':
D:\Windows\Documents\Arduino\encode/encode.ino:14: undefined reference to `_Z9hmac_sha1PKhjS0_jPhPj'
collect2.exe: error: ld returned 1 exit status
exit status 1
Error compiling for board Generic RP2040.

As the linked library is pure C code it might need a bit more work to get it automatically compiling in the Arduino IDE. It's definitely not an Arduino library so just copying it to the libraries folder might not succeed. How did you install the library?

I put it into the same folder as my project. I ended up randomly finding a different library in some random post and it ended up working. I really appreciate you trying to help. The project is complete (firmware wise). Now to finish hardware :slight_smile:
Thank you again!

If I can find the post again (lost the link) I’ll post it here for others