From: bg Date: Tue, 18 Sep 2012 15:10:35 +0000 (+0200) Subject: few changes to aes, nothing of importance X-Git-Url: https://git.cryptolib.org/?p=arm-crypto-lib.git;a=commitdiff_plain;h=bbdf729f289a7920c271991712558f566392af4a few changes to aes, nothing of importance --- diff --git a/aes/aes_keyschedule.c b/aes/aes_keyschedule.c index 30fac7d..80a5598 100644 --- a/aes/aes_keyschedule.c +++ b/aes/aes_keyschedule.c @@ -26,11 +26,13 @@ */ #include +#include +#include "memxor.h" #include "aes.h" #include "aes_keyschedule.h" #include "aes_sbox.h" -#include +/* static void aes_rotword(void* a){ uint8_t t; @@ -40,10 +42,12 @@ void aes_rotword(void* a){ ((uint8_t*)a)[2] = ((uint8_t*)a)[3]; ((uint8_t*)a)[3] = t; } +*/ -uint8_t rc_tab[] = { 0x01, 0x02, 0x04, 0x08, - 0x10, 0x20, 0x40, 0x80, - 0x1b, 0x36 }; +const uint8_t rc_tab[] = { + 0x01, 0x02, 0x04, 0x08, + 0x10, 0x20, 0x40, 0x80, + 0x1b, 0x36 }; void aes_init(const void* key, uint16_t keysize_b, aes_genctx_t* ctx){ uint8_t hi,i,nk, next_nk; @@ -52,12 +56,13 @@ void aes_init(const void* key, uint16_t keysize_b, aes_genctx_t* ctx){ uint32_t v32; uint8_t v8[4]; } tmp; - nk=keysize_b>>5; /* 4, 6, 8 */ - hi=4*(nk+6+1); + nk = keysize_b >> 5; /* 4, 6, 8 */ + hi = 4 * (nk + 6 + 1); memcpy(ctx, key, keysize_b/8); next_nk = nk; for(i=nk; ikey[0].ks))[i-1]; + /* tmp.v32 = ((uint32_t*)(ctx->key[0].ks))[i-1]; */ + memcpy(tmp.v8, ctx->key[0].ks + (i - 1) * 4, 4); if(i != next_nk){ if(nk == 8 && i % 8 == 4){ tmp.v8[0] = aes_sbox[tmp.v8[0]]; @@ -67,7 +72,8 @@ void aes_init(const void* key, uint16_t keysize_b, aes_genctx_t* ctx){ } } else { next_nk += nk; - aes_rotword(&(tmp.v32)); +/* aes_rotword(&(tmp.v32)); */ + tmp.v32 = (tmp.v32 >> 8) | (tmp.v32 << 24); tmp.v8[0] = aes_sbox[tmp.v8[0]]; tmp.v8[1] = aes_sbox[tmp.v8[1]]; tmp.v8[2] = aes_sbox[tmp.v8[2]]; @@ -75,8 +81,12 @@ void aes_init(const void* key, uint16_t keysize_b, aes_genctx_t* ctx){ tmp.v8[0] ^= rc_tab[rc]; rc++; } + memcpy(ctx->key[0].ks + 4 * i, ctx->key[0].ks + (i - nk) * 4, 4); + memxor(ctx->key[0].ks + 4 * i, tmp.v8, 4); +/* ((uint32_t*)(ctx->key[0].ks))[i] = ((uint32_t*)(ctx->key[0].ks))[i-nk] ^ tmp.v32; +*/ } } diff --git a/aes/aes_types.h b/aes/aes_types.h index 2768521..6d68022 100644 --- a/aes/aes_types.h +++ b/aes/aes_types.h @@ -46,7 +46,7 @@ typedef struct __attribute__((packed)){ } aes256_ctx_t; typedef struct __attribute__((packed)){ - aes_roundkey_t key[1]; /* just to avoid the warning */ + aes_roundkey_t key[15]; /* just to avoid the warning */ } aes_genctx_t; typedef struct __attribute__((packed)){