diff --git a/meson.build b/meson.build index e1dd7c5..56a7a96 100644 --- a/meson.build +++ b/meson.build @@ -7,7 +7,7 @@ incdir = include_directories('src') cmake = import('cmake') mbedtls_proj = cmake.subproject('mbedtls') -mbedtls_dep = mbedtls_proj.dependency('mbedtls') +mbedtls_dep = mbedtls_proj.dependency('mbedcrypto') executable('ex01', ['src/ex01/main.c', 'src/utils.c'], dependencies: m_dep, include_directories: incdir) executable('ex02', ['src/ex02/main.c', 'src/utils.c'], dependencies: m_dep, include_directories: incdir) diff --git a/src/ex07/main.c b/src/ex07/main.c index 5a2800e..abd3162 100644 --- a/src/ex07/main.c +++ b/src/ex07/main.c @@ -1,9 +1,9 @@ +#include "mbedtls/aes.h" #include "utils.h" #include #include #include #include -#include "mbedtls/aes.h" #define BUF_SIZE 4096 @@ -37,6 +37,20 @@ int main(int argc, char *argv[]) { } mbedtls_aes_context aes; + mbedtls_aes_init(&aes); + int err = + mbedtls_aes_setkey_dec(&aes, (const unsigned char *)key, strlen(key) * 8); + if (err) { + printf("Key should be 16, 24, or 32 bytes long\n"); + return EXIT_FAILURE; + } + + unsigned char output[BUF_SIZE] = {0}; + err = mbedtls_aes_crypt_ecb(&aes, MBEDTLS_AES_DECRYPT, buf, output); + if (err) { + printf("Could not decode buffer\n"); + return EXIT_FAILURE; + } if (fclose(fp)) { printf("Error closing file %s\n", filename);