undefined reference to `mbedtls_cipher_cmac' using ESP32 and VSC with PlatformIO

540 Views Asked by At

I'm trying to write a LoRaWAN library from scratch. Using the function mbedtls_cipher_cmac from mbedtls/cmac.h to generate the Join-Request frame. I get the error

undefined reference to `mbedtls_cipher_cmac'

I have attempted the solution in this post: AES-CMAC using mbedtls: undefined reference error by defining CONFIG_MBEDTLS_CMAC_C in my main.cpp file.
When I look in esp_config.h, the inactive region colorization (VSC feature) confirms that MBEDTLS_CMAC_C is now defined, however a clean build still turns up the undefined reference error.


I am aware that the linker cannot find the corresponding .cpp file that goes along with cmac.h, but here I am lost as I cannot find aes.cpp either, however it builds just fine. I have no idea where VSC stores the .cpp files. They appear to be built in, but a search in the PlatformIO libraries tab returns nothing. Here is my code (with fake appkey):

#define CONFIG_MBEDTLS_CMAC_C
#include <Arduino.h>
#include <mbedtls/cmac.h>

void setup() {
  static const uint8_t APPKEY[] = {0xB6, 0xB5, 0x3F, 0x4A, 0x16, 0x8A, 0x7A, 0x88, 0xBD, 0xF7, 0xEA, 0x13, 0x5C, 0xE9, 0xCF, 0xCA};
  uint8_t testPHYPayload[] = {0x00, 0xDC, 0x00, 0x00, 0xD0, 0x7E, 0xD5, 0xB3, 0x70, 0x1E, 0x6F, 0xED, 0xF5, 0x7C, 0xEE, 0xAF, 0x00, 0xC8, 0x86, 0x03, 0x0A, 0xF2, 0xC9};
  unsigned char cmac[100] = {0};
  const mbedtls_cipher_info_t* cipher_info;
  cipher_info = mbedtls_cipher_info_from_type(MBEDTLS_CIPHER_AES_128_ECB);
  mbedtls_cipher_cmac(cipher_info, APPKEY, 128, testPHYPayload, 19, cmac);
}

void loop() {
  
}
0

There are 0 best solutions below