few changes to aes, nothing of importance
This commit is contained in:
parent
1cdc772d04
commit
bbdf729f28
|
@ -26,11 +26,13 @@
|
||||||
*/
|
*/
|
||||||
|
|
||||||
#include <stdint.h>
|
#include <stdint.h>
|
||||||
|
#include <string.h>
|
||||||
|
#include "memxor.h"
|
||||||
#include "aes.h"
|
#include "aes.h"
|
||||||
#include "aes_keyschedule.h"
|
#include "aes_keyschedule.h"
|
||||||
#include "aes_sbox.h"
|
#include "aes_sbox.h"
|
||||||
#include <string.h>
|
|
||||||
|
|
||||||
|
/*
|
||||||
static
|
static
|
||||||
void aes_rotword(void* a){
|
void aes_rotword(void* a){
|
||||||
uint8_t t;
|
uint8_t t;
|
||||||
|
@ -40,8 +42,10 @@ void aes_rotword(void* a){
|
||||||
((uint8_t*)a)[2] = ((uint8_t*)a)[3];
|
((uint8_t*)a)[2] = ((uint8_t*)a)[3];
|
||||||
((uint8_t*)a)[3] = t;
|
((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,
|
0x10, 0x20, 0x40, 0x80,
|
||||||
0x1b, 0x36 };
|
0x1b, 0x36 };
|
||||||
|
|
||||||
|
@ -52,12 +56,13 @@ void aes_init(const void* key, uint16_t keysize_b, aes_genctx_t* ctx){
|
||||||
uint32_t v32;
|
uint32_t v32;
|
||||||
uint8_t v8[4];
|
uint8_t v8[4];
|
||||||
} tmp;
|
} tmp;
|
||||||
nk=keysize_b>>5; /* 4, 6, 8 */
|
nk = keysize_b >> 5; /* 4, 6, 8 */
|
||||||
hi=4*(nk+6+1);
|
hi = 4 * (nk + 6 + 1);
|
||||||
memcpy(ctx, key, keysize_b/8);
|
memcpy(ctx, key, keysize_b/8);
|
||||||
next_nk = nk;
|
next_nk = nk;
|
||||||
for(i=nk; i<hi; ++i){
|
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(i != next_nk){
|
||||||
if(nk == 8 && i % 8 == 4){
|
if(nk == 8 && i % 8 == 4){
|
||||||
tmp.v8[0] = aes_sbox[tmp.v8[0]];
|
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 {
|
} else {
|
||||||
next_nk += nk;
|
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[0] = aes_sbox[tmp.v8[0]];
|
||||||
tmp.v8[1] = aes_sbox[tmp.v8[1]];
|
tmp.v8[1] = aes_sbox[tmp.v8[1]];
|
||||||
tmp.v8[2] = aes_sbox[tmp.v8[2]];
|
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];
|
tmp.v8[0] ^= rc_tab[rc];
|
||||||
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]
|
((uint32_t*)(ctx->key[0].ks))[i] = ((uint32_t*)(ctx->key[0].ks))[i-nk]
|
||||||
^ tmp.v32;
|
^ tmp.v32;
|
||||||
|
*/
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
@ -46,7 +46,7 @@ typedef struct __attribute__((packed)){
|
||||||
} aes256_ctx_t;
|
} aes256_ctx_t;
|
||||||
|
|
||||||
typedef struct __attribute__((packed)){
|
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;
|
} aes_genctx_t;
|
||||||
|
|
||||||
typedef struct __attribute__((packed)){
|
typedef struct __attribute__((packed)){
|
||||||
|
|
Loading…
Reference in New Issue