]> git.cryptolib.org Git - avr-crypto-lib.git/commitdiff
aes_keyschdule speed up
authorbg <bg@b1d182e4-1ff8-0310-901f-bddb46175740>
Sun, 4 Jan 2009 21:51:46 +0000 (21:51 +0000)
committerbg <bg@b1d182e4-1ff8-0310-901f-bddb46175740>
Sun, 4 Jan 2009 21:51:46 +0000 (21:51 +0000)
aes_enc.c
aes_keyschedule.c
test_src/main-aes-test.c

index 39be410b599dec616215e567c2dd5e7fcee41e48..7932e528d48218511191ee51cbf024a9b8c19798 100644 (file)
--- a/aes_enc.c
+++ b/aes_enc.c
@@ -47,8 +47,6 @@ void aes_shiftrow(void* data, uint8_t shift){
 #define GF256MUL_2(a) (gf256mul(2, (a), 0x1b))
 #define GF256MUL_3(a) (gf256mul(3, (a), 0x1b))
 
-
-
 static
 void aes_enc_round(aes_cipher_state_t* state, const aes_roundkey_t* k){
        uint8_t tmp[16];
index 59b7bf43704bba261f8e492bec5f4cd4f2a81f40..429cef639fed0c295313e4aabbeae65da09cfbd4 100644 (file)
@@ -46,39 +46,30 @@ void aes_rotword(void* a){
 #include "uart.h"
 
 void aes_init(const void* key, uint16_t keysize_b, aes_genctx_t* ctx){
-       uint8_t hi,i,nk;
+       uint8_t hi,i,nk, next_nk;
        uint8_t rc=1;
        uint8_t tmp[4];
-       nk=keysize_b/32;
+       nk=keysize_b>>5; /* 4, 6, 8 */
        hi=4*(nk+6+1);
        memcpy(ctx, key, keysize_b/8);
-       i=keysize_b/32;
+       next_nk = nk;
        for(i=nk;i<hi;++i){
                *((uint32_t*)tmp) = ((uint32_t*)(ctx->key[0].ks))[i-1];
-       //      uart_putstr_P(PSTR("\r\nDBG: tmp = "));
-       //      uart_hexdump(tmp, 4);
-               if(i%nk){
-                       if(nk>6 && i%nk==4){
+               if(i!=next_nk){
+                       if(nk==8 && i%8==4){
                                tmp[0] = pgm_read_byte(aes_sbox+tmp[0]);
                                tmp[1] = pgm_read_byte(aes_sbox+tmp[1]);
                                tmp[2] = pgm_read_byte(aes_sbox+tmp[2]);
                                tmp[3] = pgm_read_byte(aes_sbox+tmp[3]);
-       //                      uart_putstr_P(PSTR("\r\nDBG: after sub = "));
-       //                      uart_hexdump(tmp, 4);
                        }
                } else {
+                       next_nk += nk;
                        aes_rotword(tmp);
-       //              uart_putstr_P(PSTR("\r\nDBG: after rot = "));
-       //              uart_hexdump(tmp, 4);
                        tmp[0] = pgm_read_byte(aes_sbox+tmp[0]);
                        tmp[1] = pgm_read_byte(aes_sbox+tmp[1]);
                        tmp[2] = pgm_read_byte(aes_sbox+tmp[2]);
                        tmp[3] = pgm_read_byte(aes_sbox+tmp[3]);
-       //              uart_putstr_P(PSTR("\r\nDBG: after sub = "));
-       //              uart_hexdump(tmp, 4);
                        tmp[0] ^= rc;
-       //              uart_putstr_P(PSTR("\r\nDBG: after xor RC = "));
-       //              uart_hexdump(tmp, 4);
                        rc = gf256mul(2,rc,0x1b);
                }
                ((uint32_t*)(ctx->key[0].ks))[i] = ((uint32_t*)(ctx->key[0].ks))[i-nk]
index ef4262662d8c5fc985f0b6a163c4d55828e7bdb6..a051ce8a8a3fb3385958cb4204146715ea78a0c1 100644 (file)
@@ -113,7 +113,7 @@ void testrun_testkey_aes(void){
        }
 }
 
-void testrun_performance_aes(void){
+void testrun_performance_aes128(void){
        uint64_t t;
        char str[16];
        uint8_t key[32], data[16];
@@ -150,6 +150,94 @@ void testrun_performance_aes(void){
        
        uart_putstr_P(PSTR("\r\n"));
 }
+
+
+void testrun_performance_aes192(void){
+       uint64_t t;
+       char str[16];
+       uint8_t key[32], data[16];
+       aes192_ctx_t ctx;
+       
+       calibrateTimer();
+       print_overhead();
+       
+       memset(key,  0, 32);
+       memset(data, 0, 16);
+       
+       startTimer(1);
+       aes192_init(key, &ctx);
+       t = stopTimer();
+       uart_putstr_P(PSTR("\r\n\tctx-gen time: "));
+       ultoa((unsigned long)t, str, 10);
+       uart_putstr(str);
+       
+       
+       startTimer(1);
+       aes192_enc(data, &ctx);
+       t = stopTimer();
+       uart_putstr_P(PSTR("\r\n\tencrypt time: "));
+       ultoa((unsigned long)t, str, 10);
+       uart_putstr(str);
+       
+       
+       startTimer(1);
+       aes192_dec(data, &ctx);
+       t = stopTimer();
+       uart_putstr_P(PSTR("\r\n\tdecrypt time: "));
+       ultoa((unsigned long)t, str, 10);
+       uart_putstr(str);
+       
+       uart_putstr_P(PSTR("\r\n"));
+}
+
+
+void testrun_performance_aes256(void){
+       uint64_t t;
+       char str[16];
+       uint8_t key[32], data[16];
+       aes256_ctx_t ctx;
+       
+       calibrateTimer();
+       print_overhead();
+       
+       memset(key,  0, 32);
+       memset(data, 0, 16);
+       
+       startTimer(1);
+       aes256_init(key, &ctx);
+       t = stopTimer();
+       uart_putstr_P(PSTR("\r\n\tctx-gen time: "));
+       ultoa((unsigned long)t, str, 10);
+       uart_putstr(str);
+       
+       
+       startTimer(1);
+       aes256_enc(data, &ctx);
+       t = stopTimer();
+       uart_putstr_P(PSTR("\r\n\tencrypt time: "));
+       ultoa((unsigned long)t, str, 10);
+       uart_putstr(str);
+       
+       
+       startTimer(1);
+       aes256_dec(data, &ctx);
+       t = stopTimer();
+       uart_putstr_P(PSTR("\r\n\tdecrypt time: "));
+       ultoa((unsigned long)t, str, 10);
+       uart_putstr(str);
+       
+       uart_putstr_P(PSTR("\r\n"));
+}
+
+void testrun_performance_aes(void){
+       uart_putstr_P(PSTR("\r\n -=AES Performance Test=-\r\n"));
+       uart_putstr_P(PSTR("\r\n       AES-128\r\n"));
+       testrun_performance_aes128();
+       uart_putstr_P(PSTR("\r\n       AES-192\r\n"));
+       testrun_performance_aes192();
+       uart_putstr_P(PSTR("\r\n       AES-256\r\n"));
+       testrun_performance_aes256();
+}
 /*****************************************************************************
  *  main                                                                                                                                        *
  *****************************************************************************/