some small updates
This commit is contained in:
parent
61444fd31d
commit
ddcdfe688e
6
cast5.c
6
cast5.c
|
@ -213,8 +213,10 @@ uint32_t cast5_f2(uint32_t d, uint32_t m, uint8_t r){
|
||||||
return (((ia - ib) + ic) ^ id);
|
return (((ia - ib) + ic) ^ id);
|
||||||
#else
|
#else
|
||||||
|
|
||||||
return (((pgm_read_dword(&s1[((uint8_t*)&t)[IA]] ) - pgm_read_dword(&s2[((uint8_t*)&t)[IB]] ))
|
return (((pgm_read_dword(&s1[((uint8_t*)&t)[IA]])
|
||||||
+ pgm_read_dword(&s3[((uint8_t*)&t)[IC]] )) ^ pgm_read_dword(&s4[((uint8_t*)&t)[ID]]));
|
- 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
|
#endif
|
||||||
}
|
}
|
||||||
|
|
2
cli.h
2
cli.h
|
@ -4,6 +4,8 @@
|
||||||
#include <stdint.h>
|
#include <stdint.h>
|
||||||
#include <avr/pgmspace.h>
|
#include <avr/pgmspace.h>
|
||||||
|
|
||||||
|
typedef void(*void_fpt)(void);
|
||||||
|
|
||||||
int16_t findstring_d0(const char* str, const char* v);
|
int16_t findstring_d0(const char* str, const char* v);
|
||||||
int16_t findstring_d0_P(const char* str, PGM_P v);
|
int16_t findstring_d0_P(const char* str, PGM_P v);
|
||||||
|
|
||||||
|
|
|
@ -77,21 +77,12 @@ void testrun_self_present(void){
|
||||||
}
|
}
|
||||||
|
|
||||||
void testrun_performance_present(void){
|
void testrun_performance_present(void){
|
||||||
uint16_t i,c;
|
|
||||||
uint64_t t;
|
uint64_t t;
|
||||||
char str[16];
|
|
||||||
uint8_t key[10], data[8];
|
uint8_t key[10], data[8];
|
||||||
present_ctx_t ctx;
|
present_ctx_t ctx;
|
||||||
|
|
||||||
calibrateTimer();
|
calibrateTimer();
|
||||||
getOverhead(&c, &i);
|
print_overhead();
|
||||||
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);
|
|
||||||
|
|
||||||
memset(key, 0, 10);
|
memset(key, 0, 10);
|
||||||
memset(data, 0, 8);
|
memset(data, 0, 8);
|
||||||
|
@ -99,23 +90,18 @@ void testrun_performance_present(void){
|
||||||
startTimer(1);
|
startTimer(1);
|
||||||
present_init(key, 80, &ctx);
|
present_init(key, 80, &ctx);
|
||||||
t = stopTimer();
|
t = stopTimer();
|
||||||
uart_putstr_P(PSTR("\r\n\tctx-gen time: "));
|
print_time_P(PSTR("\tctx-gen time: "),t);
|
||||||
ultoa((unsigned long)t, str, 10);
|
|
||||||
uart_putstr(str);
|
|
||||||
|
|
||||||
startTimer(1);
|
startTimer(1);
|
||||||
present_enc(data, &ctx);
|
present_enc(data, &ctx);
|
||||||
t = stopTimer();
|
t = stopTimer();
|
||||||
uart_putstr_P(PSTR("\r\n\tencrypt time: "));
|
print_time_P(PSTR("\tencrypt time: "), t);
|
||||||
ultoa((unsigned long)t, str, 10);
|
|
||||||
uart_putstr(str);
|
|
||||||
|
|
||||||
startTimer(1);
|
startTimer(1);
|
||||||
present_dec(data, &ctx);
|
present_dec(data, &ctx);
|
||||||
t = stopTimer();
|
t = stopTimer();
|
||||||
uart_putstr_P(PSTR("\r\n\tdecrypt time: "));
|
print_time_P(PSTR("\tdecrypt time: "), t);
|
||||||
ultoa((unsigned long)t, str, 10);
|
|
||||||
uart_putstr(str);
|
|
||||||
uart_putstr_P(PSTR("\r\n"));
|
uart_putstr_P(PSTR("\r\n"));
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -123,8 +109,6 @@ void testrun_performance_present(void){
|
||||||
* main *
|
* main *
|
||||||
*****************************************************************************/
|
*****************************************************************************/
|
||||||
|
|
||||||
typedef void(*void_fpt)(void);
|
|
||||||
|
|
||||||
int main (void){
|
int main (void){
|
||||||
char str[20];
|
char str[20];
|
||||||
DEBUG_INIT();
|
DEBUG_INIT();
|
||||||
|
|
|
@ -10,6 +10,8 @@
|
||||||
|
|
||||||
#include "xtea.h"
|
#include "xtea.h"
|
||||||
#include "nessie_bc_test.h"
|
#include "nessie_bc_test.h"
|
||||||
|
#include "performance_test.h"
|
||||||
|
#include "cli.h"
|
||||||
|
|
||||||
#include <stdint.h>
|
#include <stdint.h>
|
||||||
#include <string.h>
|
#include <string.h>
|
||||||
|
@ -40,7 +42,28 @@ void testrun_nessie_xtea(void){
|
||||||
nessie_bc_run();
|
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 *
|
* main *
|
||||||
|
@ -55,14 +78,16 @@ int main (void){
|
||||||
uart_putstr(cipher_name);
|
uart_putstr(cipher_name);
|
||||||
uart_putstr_P(PSTR(")\r\nloaded and running\r\n"));
|
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){
|
while(1){
|
||||||
if (!getnextwordn(str,20)) {DEBUG_S("DBG: W1\r\n"); goto error;}
|
if (!getnextwordn(str,20)){DEBUG_S("DBG: W1\r\n"); goto error;}
|
||||||
if (strcmp(str, "nessie")) {DEBUG_S("DBG: 1b\r\n"); goto error;}
|
if(execcommand_d0_P(str, u, v)<0){
|
||||||
testrun_nessie_xtea();
|
uart_putstr_P(PSTR("\r\nunknown command\r\n"));
|
||||||
goto restart;
|
}
|
||||||
continue;
|
continue;
|
||||||
error:
|
error:
|
||||||
uart_putstr("ERROR\r\n");
|
uart_putstr("ERROR\r\n");
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
|
@ -26,13 +26,9 @@
|
||||||
push r17
|
push r17
|
||||||
push r28
|
push r28
|
||||||
push r29
|
push r29
|
||||||
in r28, _SFR_IO_ADDR(SREG)
|
|
||||||
push r28
|
|
||||||
.endm
|
.endm
|
||||||
|
|
||||||
.macro pop_all
|
.macro pop_all
|
||||||
pop r28
|
|
||||||
out _SFR_IO_ADDR(SREG), r28
|
|
||||||
pop r29
|
pop r29
|
||||||
pop r28
|
pop r28
|
||||||
pop r17
|
pop r17
|
||||||
|
@ -451,8 +447,8 @@ round:
|
||||||
push r25
|
push r25
|
||||||
push r24
|
push r24
|
||||||
pi_gamma_pi:
|
pi_gamma_pi:
|
||||||
ldi r30, lo8(bigendian_rotl32)
|
ldi r30, pm_lo8(bigendian_rotl32)
|
||||||
ldi r31, hi8(bigendian_rotl32)
|
ldi r31, pm_hi8(bigendian_rotl32)
|
||||||
call pi
|
call pi
|
||||||
/* pi1 done; now gamma */
|
/* pi1 done; now gamma */
|
||||||
call gamma_1
|
call gamma_1
|
||||||
|
@ -465,23 +461,10 @@ pi_gamma_pi:
|
||||||
op32 eor, state2, state0
|
op32 eor, state2, state0
|
||||||
op32 eor, state2, state1
|
op32 eor, state2, state1
|
||||||
op32 eor, state2, state3
|
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
|
call gamma_1
|
||||||
ldi r30, lo8(bigendian_rotr32)
|
ldi r30, pm_lo8(bigendian_rotr32)
|
||||||
ldi r31, hi8(bigendian_rotr32)
|
ldi r31, pm_hi8(bigendian_rotr32)
|
||||||
call pi
|
call pi
|
||||||
ret
|
ret
|
||||||
|
|
||||||
|
@ -526,8 +509,6 @@ gamma_1:
|
||||||
ret
|
ret
|
||||||
|
|
||||||
pi:
|
pi:
|
||||||
lsr r31
|
|
||||||
ror r30
|
|
||||||
/* a[1] <<<= 1*/
|
/* a[1] <<<= 1*/
|
||||||
mov r22, state1_0
|
mov r22, state1_0
|
||||||
mov r23, state1_1
|
mov r23, state1_1
|
||||||
|
|
|
@ -7,10 +7,13 @@
|
||||||
**/
|
**/
|
||||||
|
|
||||||
#include "config.h"
|
#include "config.h"
|
||||||
|
#include <string.h>
|
||||||
#include <stdint.h>
|
#include <stdint.h>
|
||||||
#include <stdlib.h>
|
#include <stdlib.h>
|
||||||
#include <avr/io.h>
|
#include <avr/io.h>
|
||||||
#include <avr/interrupt.h>
|
#include <avr/interrupt.h>
|
||||||
|
#include <avr/pgmspace.h>
|
||||||
|
#include "uart.h"
|
||||||
#include "performance_test.h"
|
#include "performance_test.h"
|
||||||
|
|
||||||
|
|
||||||
|
@ -65,6 +68,27 @@ void getOverhead(uint16_t* constoh, uint16_t* intoh){
|
||||||
*intoh = int_overhead;
|
*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);
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
|
|
@ -2,10 +2,14 @@
|
||||||
#define PERFORMANCE_TEST_H_
|
#define PERFORMANCE_TEST_H_
|
||||||
|
|
||||||
#include <stdint.h>
|
#include <stdint.h>
|
||||||
|
#include <avr/pgmspace.h>
|
||||||
|
|
||||||
void calibrateTimer(void);
|
void calibrateTimer(void);
|
||||||
void startTimer(uint8_t granularity);
|
void startTimer(uint8_t granularity);
|
||||||
uint64_t stopTimer(void);
|
uint64_t stopTimer(void);
|
||||||
void getOverhead(uint16_t* constoh, uint16_t* intoh);
|
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_*/
|
#endif /*PERFORMANCE_TEST_H_*/
|
||||||
|
|
|
@ -644,8 +644,7 @@ sha1_nextBlock_mainloop_core: /* ther core function; T=ROTL5(a) ....*/
|
||||||
/* wo Z-4 gerade auf kt zeigt ... */
|
/* wo Z-4 gerade auf kt zeigt ... */
|
||||||
movw r28, r26 /* copy X in Y */
|
movw r28, r26 /* copy X in Y */
|
||||||
adiw r30, 3*4 /* now Z points to the rigth locatin in our jump-vector-table */
|
adiw r30, 3*4 /* now Z points to the rigth locatin in our jump-vector-table */
|
||||||
clc
|
lsr r31
|
||||||
ror r31
|
|
||||||
ror r30
|
ror r30
|
||||||
|
|
||||||
icall
|
icall
|
||||||
|
|
22
xtea.c
22
xtea.c
|
@ -8,26 +8,28 @@
|
||||||
#include <stdint.h>
|
#include <stdint.h>
|
||||||
|
|
||||||
|
|
||||||
void xtea_enc(uint32_t* dest, uint32_t* v, uint32_t* k) {
|
void xtea_enc(void* dest, const void* v, const void* k) {
|
||||||
uint32_t v0=v[0], v1=v[1], i;
|
uint8_t i;
|
||||||
|
uint32_t v0=((uint32_t*)v)[0], v1=((uint32_t*)v)[1];
|
||||||
uint32_t sum=0, delta=0x9E3779B9;
|
uint32_t sum=0, delta=0x9E3779B9;
|
||||||
for(i=0; i<32; i++) {
|
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;
|
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) {
|
void xtea_dec(void* dest, const void* v, const void* k) {
|
||||||
uint32_t v0=v[0], v1=v[1], i;
|
uint8_t i;
|
||||||
|
uint32_t v0=((uint32_t*)v)[0], v1=((uint32_t*)v)[1];
|
||||||
uint32_t sum=0xC6EF3720, delta=0x9E3779B9;
|
uint32_t sum=0xC6EF3720, delta=0x9E3779B9;
|
||||||
for(i=0; i<32; i++) {
|
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;
|
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;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
|
|
9
xtea.h
9
xtea.h
|
@ -13,7 +13,10 @@
|
||||||
* this fits for xtea.c and xtea-asm.S
|
* 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)
|
* v: the block to operate on (64 bit)
|
||||||
* k: the key for en/decryption (128 bit)
|
* k: the key for en/decryption (128 bit)
|
||||||
*/
|
*/
|
||||||
void xtea_enc(uint32_t* dest, uint32_t* v, uint32_t* k);
|
void xtea_enc(void* dest, const void* v, const void* k);
|
||||||
void xtea_dec(uint32_t* dest, uint32_t* v, uint32_t* k);
|
void xtea_dec(void* dest, const void* v, const void* k);
|
||||||
|
|
||||||
|
|
||||||
#endif /*XTEA_H_*/
|
#endif /*XTEA_H_*/
|
||||||
|
|
3
xtea.mk
3
xtea.mk
|
@ -6,7 +6,8 @@ BLOCK_CIPHERS += $(ALGO_NAME)
|
||||||
|
|
||||||
$(ALGO_NAME)_OBJ := xtea-asm.o
|
$(ALGO_NAME)_OBJ := xtea-asm.o
|
||||||
$(ALGO_NAME)_TEST_BIN := main-xtea-test.o debug.o uart.o serial-tools.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)_NESSIE_TEST := "nessie"
|
||||||
$(ALGO_NAME)_PEROFRMANCE_TEST := "performance"
|
$(ALGO_NAME)_PEROFRMANCE_TEST := "performance"
|
||||||
|
|
||||||
|
|
Loading…
Reference in New Issue