I’m trying to generate keys for encoding and decoding using the Kyber API in an Arduino project, but I’m encountering a compilation error. My code includes the api.h
header and attempts to call crypto_kem_keypair
, crypto_kem_enc
, and crypto_kem_dec
. The functions seem to be linked correctly in the code editor, but I get the following error during compilation:
undefined reference to `crypto_kem_keypair(unsigned char*, unsigned char*)'
undefined reference to `crypto_kem_enc(unsigned char*, unsigned char*, unsigned char const*)'
undefined reference to `crypto_kem_dec(unsigned char*, unsigned char const*, unsigned char const*)'
How can I resolve this issue?
Here is a snippet of my code for reference:
#include "api.h" // Include the Kyber API header
void setup() {
Serial.begin(115200); // Start serial communication for debugging
// Kyber 1024 key exchange example
uint8_t pk[CRYPTO_PUBLICKEYBYTES];
uint8_t sk[CRYPTO_SECRETKEYBYTES];
uint8_t ct[CRYPTO_CIPHERTEXTBYTES];
uint8_t ss[CRYPTO_BYTES];
uint8_t ss_dec[CRYPTO_BYTES];
// Generate keypair
crypto_kem_keypair(pk, sk);
Serial.println("Keypair generated.");
// Encapsulate
crypto_kem_enc(ct, ss, pk);
Serial.println("Encapsulation done.");
// Decapsulate
crypto_kem_dec(ss_dec, ct, sk);
Serial.println("Decapsulation done.");
// Verify shared secret
bool valid = true;
for (int i = 0; i < CRYPTO_BYTES; i++) {
if (ss[i] != ss_dec[i]) {
valid = false;
break;
}
}
if (valid) {
Serial.println("Shared secrets match.");
} else {
Serial.println("Shared secrets do not match.");
}
}
void loop() {}
I have verified that the api.h file is included correctly, and I believe the necessary function implementations are present. Any advice on resolving the linker errors would be greatly appreciated.