few changes to aes, nothing of importance
This commit is contained in:
parent
1cdc772d04
commit
bbdf729f28
|
@ -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,8 +42,10 @@ 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,
|
||||
const uint8_t rc_tab[] = {
|
||||
0x01, 0x02, 0x04, 0x08,
|
||||
0x10, 0x20, 0x40, 0x80,
|
||||
0x1b, 0x36 };
|
||||
|
||||
|
@ -57,7 +61,8 @@ void aes_init(const void* key, uint16_t keysize_b, aes_genctx_t* ctx){
|
|||
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;
|
||||
*/
|
||||
}
|
||||
}
|
||||
|
||||
|
|
|
@ -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…
Reference in New Issue