I have the following simple openssl program:
#include <stdio.h>
#include <stdlib.h>
#include <string.h>
#include <openssl/aes.h>
int main() {
AES_KEY aes;
unsigned char key[] = {0x5A, 0x5A, 0x5A, 0x5A, 0x5A, 0x5A, 0x5A, 0x5A,
0x5A, 0x5A, 0x5A, 0x5A, 0x5A, 0x5A, 0x5A, 0x5A};
int result;
result = AES_set_encrypt_key(key, 128, &aes);
if (result < 0) {
printf(Unable to generate key: "%i", result);
exit(-1);
}
// Each round is 16 bytes (128 bits)
for (int i = 0; i < (aes.rounds + 1) * 4; i = i + 4) {
printf("0x%x 0x%x 0x%x 0x%x\n", aes.rd_key[i], aes.rd_key[i+1], aes.rd_key[i+2], aes.rd_key[i+3]);
}
return 0;
}
and I'm trying to compile it with the command
gcc -I/usr/local/include/openssl -o generateKey -lcrypto -lssl -L/usr/local/lib generatekey.c
/usr/local/include/openssl
contains aes.h
so that's why I think I need that. usr/local/lib
contains libcrypto.a
, libcrypto.so
, libssl.a
, and libssl.so
so that's why I think I need those too. When I try to compile I get the error
generate_key.c: undefined reference to `AES_set_encrypt_key`
collect2: error: ld returned 1 exit status
Is there somewhere else I should be linking to for finding the openssl libraries? I'm running this on Ubuntu 16.04.
I've tried sudo apt-get install libssl-dev
to ensure openssl is installed for development.