]> git.cryptolib.org Git - avr-crypto-lib.git/commitdiff
some small updates
authorbg <bg@b1d182e4-1ff8-0310-901f-bddb46175740>
Sun, 20 Apr 2008 02:36:13 +0000 (02:36 +0000)
committerbg <bg@b1d182e4-1ff8-0310-901f-bddb46175740>
Sun, 20 Apr 2008 02:36:13 +0000 (02:36 +0000)
cast5.c
cli.h
main-present-test.c
main-xtea-test.c
noekeon_asm.S
performance_test.c
performance_test.h
sha1-asm.S
xtea.c
xtea.h
xtea.mk

diff --git a/cast5.c b/cast5.c
index 204fe30dcc1d74c593fa9e731f7aa2b3d1c0ec03..bab5c065cb7c430c09b3a93b5d3f72156bc1816c 100644 (file)
--- a/cast5.c
+++ b/cast5.c
@@ -213,8 +213,10 @@ uint32_t cast5_f2(uint32_t d, uint32_t m, uint8_t r){
        return (((ia - ib) + ic) ^ id);
 #else
        
-       return (((pgm_read_dword(&s1[((uint8_t*)&t)[IA]] ) - pgm_read_dword(&s2[((uint8_t*)&t)[IB]] )) 
-               + pgm_read_dword(&s3[((uint8_t*)&t)[IC]] )) ^ pgm_read_dword(&s4[((uint8_t*)&t)[ID]]));
+       return (((pgm_read_dword(&s1[((uint8_t*)&t)[IA]]) 
+               - pgm_read_dword(&s2[((uint8_t*)&t)[IB]]) ) 
+                   + pgm_read_dword(&s3[((uint8_t*)&t)[IC]]) ) 
+                   ^ pgm_read_dword(&s4[((uint8_t*)&t)[ID]]) );
 
 #endif
 }
diff --git a/cli.h b/cli.h
index da146b876cf1cf287eea8ae3694cbe458c1db119..c2854ba3d5af064ab8a81dadddaeaa9982a807d8 100644 (file)
--- a/cli.h
+++ b/cli.h
@@ -4,6 +4,8 @@
 #include <stdint.h>
 #include <avr/pgmspace.h>
 
+typedef void(*void_fpt)(void);
+
 int16_t findstring_d0(const char* str, const char* v);
 int16_t findstring_d0_P(const char* str, PGM_P v);
 
index a58a6dd194ab66eef079bcd574790cb8d6d8127c..a40d00b2af6d953d604a675adfa68156e0fa0fa3 100644 (file)
@@ -77,21 +77,12 @@ void testrun_self_present(void){
 }
 
 void testrun_performance_present(void){
-       uint16_t i,c;
        uint64_t t;
-       char str[16];
        uint8_t key[10], data[8];
        present_ctx_t ctx;
        
        calibrateTimer();
-       getOverhead(&c, &i);
-       uart_putstr_P(PSTR("\r\n\r\n=== benchmark ==="));
-       utoa(c, str, 10);
-       uart_putstr_P(PSTR("\r\n\tconst overhead:     "));
-       uart_putstr(str);
-       utoa(i, str, 10);
-       uart_putstr_P(PSTR("\r\n\tinterrupt overhead: "));
-       uart_putstr(str);
+       print_overhead();
        
        memset(key,  0, 10);
        memset(data, 0,  8);
@@ -99,23 +90,18 @@ void testrun_performance_present(void){
        startTimer(1);
        present_init(key, 80, &ctx);
        t = stopTimer();
-       uart_putstr_P(PSTR("\r\n\tctx-gen time: "));
-       ultoa((unsigned long)t, str, 10);
-       uart_putstr(str);
+       print_time_P(PSTR("\tctx-gen time: "),t);
        
        startTimer(1);
        present_enc(data, &ctx);
        t = stopTimer();
-       uart_putstr_P(PSTR("\r\n\tencrypt time: "));
-       ultoa((unsigned long)t, str, 10);
-       uart_putstr(str);
+       print_time_P(PSTR("\tencrypt time: "), t);
        
        startTimer(1);
        present_dec(data, &ctx);
        t = stopTimer();
-       uart_putstr_P(PSTR("\r\n\tdecrypt time: "));
-       ultoa((unsigned long)t, str, 10);
-       uart_putstr(str);
+       print_time_P(PSTR("\tdecrypt time: "), t);
+       
        uart_putstr_P(PSTR("\r\n"));
 }
 
@@ -123,8 +109,6 @@ void testrun_performance_present(void){
  *  main                                                                                                                                        *
  *****************************************************************************/
 
-typedef void(*void_fpt)(void);
-
 int main (void){
        char  str[20];
        DEBUG_INIT();
index 5e4ef0731a42b2e3a21bf42341257d12771424b1..7f67f0f9782f06af7a1d0cbd6f4a5da19e44241c 100644 (file)
@@ -10,6 +10,8 @@
 
 #include "xtea.h"
 #include "nessie_bc_test.h"
+#include "performance_test.h"
+#include "cli.h"
 
 #include <stdint.h>
 #include <string.h>
@@ -40,7 +42,28 @@ void testrun_nessie_xtea(void){
        nessie_bc_run();        
 }
 
-
+void testrun_performance_xtea(void){
+       uint64_t t;
+       uint8_t key[16], data[8];
+       
+       calibrateTimer();
+       print_overhead();
+       
+       memset(key,  0, 16);
+       memset(data, 0,  8);
+       
+       startTimer(1);
+       xtea_enc(data, data, key);
+       t = stopTimer();
+       print_time_P(PSTR("\tencrypt time: "), t);
+       
+       startTimer(1);
+       xtea_dec(data, data, key);
+       t = stopTimer();
+       print_time_P(PSTR("\tdecrypt time: "), t);
+       
+       uart_putstr_P(PSTR("\r\n"));
+}
 
 /*****************************************************************************
  *  main                                                                                                                                        *
@@ -55,14 +78,16 @@ int main (void){
        uart_putstr(cipher_name);
        uart_putstr_P(PSTR(")\r\nloaded and running\r\n"));
 
-restart:
+       PGM_P    u   = PSTR("nessie\0test\0performance\0");
+       void_fpt v[] = {testrun_nessie_xtea, testrun_nessie_xtea, testrun_performance_xtea};
+
        while(1){ 
-               if (!getnextwordn(str,20))  {DEBUG_S("DBG: W1\r\n"); goto error;}
-               if (strcmp(str, "nessie")) {DEBUG_S("DBG: 1b\r\n"); goto error;}
-                       testrun_nessie_xtea();
-               goto restart;           
+               if (!getnextwordn(str,20)){DEBUG_S("DBG: W1\r\n"); goto error;}
+               if(execcommand_d0_P(str, u, v)<0){
+                       uart_putstr_P(PSTR("\r\nunknown command\r\n"));
+               }
                continue;
        error:
                uart_putstr("ERROR\r\n");
-       }       
+       }
 }
index d880296389fdc63cdf2dd2adef5d57b77eba3792..0422964cd49d935fe3f1add7ebfc7aeb136a68bc 100644 (file)
        push r17
        push r28
        push r29
-       in r28, _SFR_IO_ADDR(SREG)
-       push r28
 .endm
 
 .macro pop_all
-       pop r28
-       out _SFR_IO_ADDR(SREG), r28
        pop r29
        pop r28
        pop r17
@@ -451,8 +447,8 @@ round:
        push r25
        push r24
 pi_gamma_pi:
-       ldi r30, lo8(bigendian_rotl32)
-       ldi r31, hi8(bigendian_rotl32)
+       ldi r30, pm_lo8(bigendian_rotl32)
+       ldi r31, pm_hi8(bigendian_rotl32)
        call pi
        /* pi1 done; now gamma */
        call gamma_1
@@ -465,23 +461,10 @@ pi_gamma_pi:
        op32 eor, state2, state0
        op32 eor, state2, state1
        op32 eor, state2, state3
-/*     
-       eor state2_0, state0_0
-       eor state2_1, state0_1
-       eor state2_2, state0_2
-       eor state2_3, state0_3
-       eor state2_0, state1_0
-       eor state2_1, state1_1
-       eor state2_2, state1_2
-       eor state2_3, state1_3
-       eor state2_0, state3_0
-       eor state2_1, state3_1
-       eor state2_2, state3_2
-       eor state2_3, state3_3
-*/
+
        call gamma_1
-       ldi r30, lo8(bigendian_rotr32)
-       ldi r31, hi8(bigendian_rotr32)
+       ldi r30, pm_lo8(bigendian_rotr32)
+       ldi r31, pm_hi8(bigendian_rotr32)
        call pi
        ret
        
@@ -526,8 +509,6 @@ gamma_1:
        ret
        
 pi:    
-       lsr r31
-       ror r30
        /* a[1] <<<= 1*/
        mov r22, state1_0
        mov r23, state1_1
index 0728827cf75a9f085c5b8c708901074fba9181ba..44b5b7be26b4db9183ea5f0962d0a8e81c74184d 100644 (file)
@@ -7,10 +7,13 @@
  **/
  
 #include "config.h"
+#include <string.h>
 #include <stdint.h>
 #include <stdlib.h>
 #include <avr/io.h>
 #include <avr/interrupt.h>
+#include <avr/pgmspace.h>
+#include "uart.h"
 #include "performance_test.h"
 
 
@@ -65,6 +68,27 @@ void getOverhead(uint16_t* constoh, uint16_t* intoh){
        *intoh   = int_overhead; 
 }
 
+void print_time_P(PGM_P s, uint64_t t){
+       char sv[16];
+       uint8_t c;
+       uart_putstr_P(PSTR("\r\n"));
+       uart_putstr_P(s);
+       ultoa((unsigned long)t, sv, 10);
+       for(c=strlen(sv); c<11; ++c){
+               uart_putc(' ');
+       }
+       uart_putstr(sv);
+}
 
+void print_overhead(void){
+       char str[16];
+       uart_putstr_P(PSTR("\r\n\r\n=== benchmark ==="));
+       utoa(const_overhead, str, 10);
+       uart_putstr_P(PSTR("\r\n\tconst overhead:     "));
+       uart_putstr(str);
+       utoa(int_overhead, str, 10);
+       uart_putstr_P(PSTR("\r\n\tinterrupt overhead: "));
+       uart_putstr(str);
+}
 
 
index 2243586a4ae1ecc4d87b0213651e5f6410a38830..a32e7566b9d64470f97df3223e280508d7f7366a 100644 (file)
@@ -2,10 +2,14 @@
 #define PERFORMANCE_TEST_H_
 
 #include <stdint.h>
+#include <avr/pgmspace.h>
 
 void calibrateTimer(void);
 void startTimer(uint8_t granularity);
 uint64_t stopTimer(void);
 void getOverhead(uint16_t* constoh, uint16_t* intoh);
 
+void print_time_P(PGM_P s, uint64_t t);
+void print_overhead(void);
+
 #endif /*PERFORMANCE_TEST_H_*/
index 278d52a6a2bd35c715d1170fbd5542a96d7aeb67..884adbc2ae71e8b8972ced2e5b1b008304e6cf86 100644 (file)
@@ -644,8 +644,7 @@ sha1_nextBlock_mainloop_core:       /* ther core function; T=ROTL5(a) ....*/
        /* wo Z-4 gerade auf kt zeigt ... */\r
        movw r28, r26 /* copy X in Y */\r
        adiw r30, 3*4 /* now Z points to the rigth locatin in our jump-vector-table */\r
-       clc\r
-       ror r31\r
+       lsr r31\r
        ror r30\r
                \r
        icall\r
diff --git a/xtea.c b/xtea.c
index 70ad914a12519e91f674e8a16604cfda6c42110a..02b97a4b9a9a2b6d310906d0fd166d6163bfa2f1 100644 (file)
--- a/xtea.c
+++ b/xtea.c
@@ -8,26 +8,28 @@
 #include <stdint.h> 
  
 
-void xtea_enc(uint32_t* dest, uint32_t* v, uint32_t* k) {
-    uint32_t v0=v[0], v1=v[1], i;
+void xtea_enc(void* dest, const void* v, const void* k) {
+    uint8_t i;
+    uint32_t v0=((uint32_t*)v)[0], v1=((uint32_t*)v)[1];
     uint32_t sum=0, delta=0x9E3779B9;
     for(i=0; i<32; i++) {
-        v0 += ((v1 << 4 ^ v1 >> 5) + v1) ^ (sum + k[sum & 3]);
+        v0 += ((v1 << 4 ^ v1 >> 5) + v1) ^ (sum + ((uint32_t*)k)[sum & 3]);
         sum += delta;
-        v1 += ((v0 << 4 ^ v0 >> 5) + v0) ^ (sum + k[sum>>11 & 3]);
+        v1 += ((v0 << 4 ^ v0 >> 5) + v0) ^ (sum + ((uint32_t*)k)[sum>>11 & 3]);
     }
-    dest[0]=v0; dest[1]=v1;
+    ((uint32_t*)dest)[0]=v0; ((uint32_t*)dest)[1]=v1;
 }
 
-void xtea_dec(uint32_t* dest, uint32_t* v, uint32_t* k) {
-    uint32_t v0=v[0], v1=v[1], i;
+void xtea_dec(void* dest, const void* v, const void* k) {
+    uint8_t i;
+    uint32_t v0=((uint32_t*)v)[0], v1=((uint32_t*)v)[1];
     uint32_t sum=0xC6EF3720, delta=0x9E3779B9;
     for(i=0; i<32; i++) {
-        v1 -= ((v0 << 4 ^ v0 >> 5) + v0) ^ (sum + k[sum>>11 & 3]);
+        v1 -= ((v0 << 4 ^ v0 >> 5) + v0) ^ (sum + ((uint32_t*)k)[sum>>11 & 3]);
         sum -= delta;
-        v0 -= ((v1 << 4 ^ v1 >> 5) + v1) ^ (sum + k[sum & 3]);
+        v0 -= ((v1 << 4 ^ v1 >> 5) + v1) ^ (sum + ((uint32_t*)k)[sum & 3]);
     }
-    dest[0]=v0; dest[1]=v1;
+    ((uint32_t*)dest)[0]=v0; ((uint32_t*)dest)[1]=v1;
 }
 
 
diff --git a/xtea.h b/xtea.h
index a156abd1246cecdea6e1a02cc0e7200ce02627dc..d72ce135cafb904942eb30b16aaea77c9269bac6 100644 (file)
--- a/xtea.h
+++ b/xtea.h
  * this fits for xtea.c and xtea-asm.S
  * 
  */
-
+#define XTEA_BLOCKSIZE 64
+#define XTEA_BLOCKSIZEB ((XTEA_BLOCKSIZE+7)/8)
+#define XTEA_KEYSIZE 128
+#define XTEA_KEYSIZEB ((XTEA_KEYSIZE+7)/8)
 
 
 /*
@@ -21,8 +24,8 @@
  * v:   the block to operate on (64 bit)
  * k:   the key for en/decryption (128 bit)
  */
-void xtea_enc(uint32_t* dest, uint32_t* v, uint32_t* k);
-void xtea_dec(uint32_t* dest, uint32_t* v, uint32_t* k);
+void xtea_enc(void* dest, const void* v, const void* k);
+void xtea_dec(void* dest, const void* v, const void* k);
 
 
 #endif /*XTEA_H_*/
diff --git a/xtea.mk b/xtea.mk
index 0dd003efb65a8a4103f71a47fa5751d41ec3f544..38f485bdc1a4862cab1287cff6b72848412f9145 100644 (file)
--- a/xtea.mk
+++ b/xtea.mk
@@ -6,7 +6,8 @@ BLOCK_CIPHERS += $(ALGO_NAME)
 
 $(ALGO_NAME)_OBJ      := xtea-asm.o
 $(ALGO_NAME)_TEST_BIN := main-xtea-test.o debug.o uart.o serial-tools.o \
-                         xtea-asm.o nessie_bc_test.o nessie_common.o
+                         xtea-asm.o nessie_bc_test.o nessie_common.o \
+                        cli.o performance_test.o
 $(ALGO_NAME)_NESSIE_TEST      := "nessie"
 $(ALGO_NAME)_PEROFRMANCE_TEST := "performance"