]> git.cryptolib.org Git - arm-crypto-lib.git/commitdiff
few changes to aes, nothing of importance
authorbg <daniel.otte@rub.de>
Tue, 18 Sep 2012 15:10:35 +0000 (17:10 +0200)
committerbg <daniel.otte@rub.de>
Tue, 18 Sep 2012 15:10:35 +0000 (17:10 +0200)
aes/aes_keyschedule.c
aes/aes_types.h

index 30fac7def85d6205ee0de91be058649663ecbfd2..80a5598f4c164f810776a327894e697ab42a4972 100644 (file)
  */
 
 #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;
+*/
        }
 }
 
index 2768521aac580cfcf35d35049966162ce47d23b7..6d68022b0c296ca451a9a2ee323234cd4c0bbe27 100644 (file)
@@ -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)){