Browse Source

few changes to aes, nothing of importance

master
bg 9 years ago
parent
commit
bbdf729f28
  1. 26
      aes/aes_keyschedule.c
  2. 2
      aes/aes_types.h

26
aes/aes_keyschedule.c

@ -26,11 +26,13 @@
*/
#include <stdint.h>
#include <string.h>
#include "memxor.h"
#include "aes.h"
#include "aes_keyschedule.h"
#include "aes_sbox.h"
#include <string.h>
/*
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; i<hi; ++i){
tmp.v32 = ((uint32_t*)(ctx->key[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;
*/
}
}

2
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)){

Loading…
Cancel
Save