kokke/tiny-AES-c

AES_CBC 256 not working

fcolecumberri opened this issue · 2 comments

maybe we are doing something wrong with this code but up to what we understand something must be wrong

#define AES256 1
#include "aes.h"
#include <stdio.h>
#include <string.h>

int main(){
	uint8_t buff[64];
	uint8_t key[32], iv[32];
	int i=0;
	for(i=0; i<32; i++){
		key[i] = iv[i] = '0' + (i%10);
	}
	struct AES_ctx ctx;
	AES_init_ctx_iv(&ctx, key, iv);
	memset(buff, '@', sizeof(buff));
	AES_CBC_encrypt_buffer(&ctx, buff, sizeof(buff));
	for(i=0; i<sizeof(buff); i++) printf("%d ", (int)buff[i]);
	printf("\n");
	AES_CBC_decrypt_buffer(&ctx, buff, sizeof(buff));
	for(i=0; i<sizeof(buff); i++) printf("%d ", (int)buff[i]);
	printf("\n");
}

and we get the next output:

206 2 230 112 136 190 160 217 224 253 132 229 248 205 149 16 251 90 52 188 184 96 168 160 18 23 150 75 185 186 0 124 49 128 227 224 215 253 122 56 206 200 45 250 253 14 62 238 220 156 7 77 201 190 224 247 23 17 47 139 129 99 93 148 
172 237 117 62 189 203 150 128 111 104 95 250 243 16 41 225 64 64 64 64 64 64 64 64 64 64 64 64 64 64 64 64 64 64 64 64 64 64 64 64 64 64 64 64 64 64 64 64 64 64 64 64 64 64 64 64 64 64 64 64 64 64 64 64 

Also the test.c compiled for AES256 Fails

I solved it by commenting #define AES128 1 and uncommenting #define AES256 1 in aes.h file:

//#define AES128 1
//#define AES192 1
#define AES256 1
kokke commented

Hi @fcolecumberri

You need to change the definition in aes.h instead of doing it before inclusion as @gRastaSsS suggests.