Fix mbedtls dependency and decrypt using AES in ECB mode
This commit is contained in:
parent
91ca893d85
commit
02ca35a4ff
2 changed files with 16 additions and 2 deletions
|
@ -7,7 +7,7 @@ incdir = include_directories('src')
|
||||||
|
|
||||||
cmake = import('cmake')
|
cmake = import('cmake')
|
||||||
mbedtls_proj = cmake.subproject('mbedtls')
|
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('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)
|
executable('ex02', ['src/ex02/main.c', 'src/utils.c'], dependencies: m_dep, include_directories: incdir)
|
||||||
|
|
|
@ -1,9 +1,9 @@
|
||||||
|
#include "mbedtls/aes.h"
|
||||||
#include "utils.h"
|
#include "utils.h"
|
||||||
#include <ctype.h>
|
#include <ctype.h>
|
||||||
#include <math.h>
|
#include <math.h>
|
||||||
#include <stdio.h>
|
#include <stdio.h>
|
||||||
#include <string.h>
|
#include <string.h>
|
||||||
#include "mbedtls/aes.h"
|
|
||||||
|
|
||||||
#define BUF_SIZE 4096
|
#define BUF_SIZE 4096
|
||||||
|
|
||||||
|
@ -37,6 +37,20 @@ int main(int argc, char *argv[]) {
|
||||||
}
|
}
|
||||||
|
|
||||||
mbedtls_aes_context aes;
|
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)) {
|
if (fclose(fp)) {
|
||||||
printf("Error closing file %s\n", filename);
|
printf("Error closing file %s\n", filename);
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue