error: aes_setkey was not declared in this scope

917 views Asked by At

I am attempting to compile the mbedtls for the mbed LPC1768 microcontroller using the gcc4mbed offline compiler.

I would like to get a basic AESCBC encrypt and decrypt example to learn from; I am not sure if I am missing an include or if I didn't instantiate correctly. error:
error: 'aes_setkey' was not declared in this scope

I am working from this guide in the knowledge base: knowledge base

Code:

#include "mbed.h"
#include "crypto/include/polarssl/config.h"
#include "crypto/include/polarssl/platform.h"
#include "crypto/include/polarssl/aes.h"

DigitalOut myled(LED1);

aes_context aes;

Serial pc(USBTX, USBRX);

unsigned char key[32] = { 0x31, 0x31, 0x31, 0x31, 0x31, 0x31, 0x31, 0x31, 0x31, 0x31, 0x31, 0x31, 0x31, 0x31, 0x31, 0x31,
                          0x31, 0x31, 0x31, 0x31, 0x31, 0x31, 0x31, 0x31, 0x31, 0x31, 0x31, 0x31, 0x31, 0x31, 0x31, 0x31 };

unsigned char iv[16]  = { 0x31, 0x31, 0x31, 0x31, 0x31, 0x31, 0x31, 0x31, 0x31, 0x31, 0x31, 0x31, 0x31, 0x31, 0x31, 0x31 };

unsigned char input[128] = { 0x6b, 0xc1, 0xbe, 0xe2, 0x2e, 0x40, 0x9f, 0x96,
                             0xe9, 0x3d, 0x7e, 0x11, 0x73, 0x93, 0x17, 0x2a,
                             0xae, 0x2d, 0x8a, 0x57, 0x1e, 0x03, 0xac, 0x9c,
                             0x9e, 0xb7, 0x6f, 0xac, 0x45, 0xaf, 0x8e, 0x51,
                             0x30, 0xc8, 0x1c, 0x46, 0xa3, 0x5c, 0xe4, 0x11,
                             0xe5, 0xfb, 0xc1, 0x19, 0x1a, 0x0a, 0x52, 0xef,
                             0xf6, 0x9f, 0x24, 0x45, 0xdf, 0x4f, 0x9b, 0x17,
                             0xad, 0x2b, 0x41, 0x7b, 0xe6, 0x6c, 0x37, 0x10 };
unsigned char output[128];

size_t input_len = 40;
size_t output_len = 0;

int main() {
    pc.baud(115200);
    aes_setkey(&aes, key, 256);
    aes_crypt_cbc(&aes, AES_ENCRYPT, 24, iv, input, output);

    pc.printf("\r\n\r\nFirst run\r\n");

    /*while(1) {
        myled = 1;
        wait(0.2);
        myled = 0;
        wait(0.2);
    }*/
}
1

There are 1 answers

1
TheUndeadFish On

Looking at their source (https://tls.mbed.org/aes-source-code linked from the page you linked) I don't see any aes_setkey. But I do see aes_setkey_enc and aes_setkey_dec. So perhaps that example is wrong or outdated. You could try using those other functions and see if they do what you want.