From: bg Date: Sun, 20 Apr 2008 02:36:13 +0000 (+0000) Subject: some small updates X-Git-Url: https://git.cryptolib.org/?a=commitdiff_plain;h=ddcdfe688ef1cd087d9ef08930fad3fa18c392d2;p=avr-crypto-lib.git some small updates --- diff --git a/cast5.c b/cast5.c index 204fe30..bab5c06 100644 --- 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 da146b8..c2854ba 100644 --- a/cli.h +++ b/cli.h @@ -4,6 +4,8 @@ #include #include +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); diff --git a/main-present-test.c b/main-present-test.c index a58a6dd..a40d00b 100644 --- a/main-present-test.c +++ b/main-present-test.c @@ -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(); diff --git a/main-xtea-test.c b/main-xtea-test.c index 5e4ef07..7f67f0f 100644 --- a/main-xtea-test.c +++ b/main-xtea-test.c @@ -10,6 +10,8 @@ #include "xtea.h" #include "nessie_bc_test.h" +#include "performance_test.h" +#include "cli.h" #include #include @@ -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"); - } + } } diff --git a/noekeon_asm.S b/noekeon_asm.S index d880296..0422964 100644 --- a/noekeon_asm.S +++ b/noekeon_asm.S @@ -26,13 +26,9 @@ 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 diff --git a/performance_test.c b/performance_test.c index 0728827..44b5b7b 100644 --- a/performance_test.c +++ b/performance_test.c @@ -7,10 +7,13 @@ **/ #include "config.h" +#include #include #include #include #include +#include +#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); +} diff --git a/performance_test.h b/performance_test.h index 2243586..a32e756 100644 --- a/performance_test.h +++ b/performance_test.h @@ -2,10 +2,14 @@ #define PERFORMANCE_TEST_H_ #include +#include 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_*/ diff --git a/sha1-asm.S b/sha1-asm.S index 278d52a..884adbc 100644 --- a/sha1-asm.S +++ b/sha1-asm.S @@ -644,8 +644,7 @@ sha1_nextBlock_mainloop_core: /* ther core function; T=ROTL5(a) ....*/ /* wo Z-4 gerade auf kt zeigt ... */ movw r28, r26 /* copy X in Y */ adiw r30, 3*4 /* now Z points to the rigth locatin in our jump-vector-table */ - clc - ror r31 + lsr r31 ror r30 icall diff --git a/xtea.c b/xtea.c index 70ad914..02b97a4 100644 --- a/xtea.c +++ b/xtea.c @@ -8,26 +8,28 @@ #include -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 a156abd..d72ce13 100644 --- a/xtea.h +++ b/xtea.h @@ -13,7 +13,10 @@ * 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 0dd003e..38f485b 100644 --- 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"