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
}
#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);
}
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);
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"));
}
* main *
*****************************************************************************/
-typedef void(*void_fpt)(void);
-
int main (void){
char str[20];
DEBUG_INIT();
#include "xtea.h"
#include "nessie_bc_test.h"
+#include "performance_test.h"
+#include "cli.h"
#include <stdint.h>
#include <string.h>
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 *
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");
- }
+ }
}
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
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
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
ret
pi:
- lsr r31
- ror r30
/* a[1] <<<= 1*/
mov r22, state1_0
mov r23, state1_1
**/
#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"
*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);
+}
#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_*/
/* 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
#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;
}
* 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)
/*
* 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_*/
$(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"