BLOCK_CIPHERS += $(ALGO_NAME)
$(ALGO_NAME)_OBJ := cast5.o
-$(ALGO_NAME)_TEST_BIN := main-cast5-test.o debug.o uart.o serial-tools.o \
- cast5.o nessie_bc_test.o nessie_common.o
+$(ALGO_NAME)_TEST_BIN := main-cast5-test.o debug.o uart.o serial-tools.o cli.o\
+ cast5.o nessie_bc_test.o nessie_common.o performance_test.o
$(ALGO_NAME)_NESSIE_TEST := "nessie"
$(ALGO_NAME)_PEROFRMANCE_TEST := "performance"
void testrun_nessie_arcfour(void){
nessie_stream_ctx.outsize_b = 8; /* actually unused */
nessie_stream_ctx.keysize_b = 128; /* this is theone we have refrence vectors for */
+ nessie_stream_ctx.ivsize_b = (uint16_t)-1;
nessie_stream_ctx.name = cipher_name;
nessie_stream_ctx.ctx_size_B = sizeof(arcfour_ctx_t);
nessie_stream_ctx.cipher_genctx = (nessie_stream_genctx_fpt)arcfour_genctx_dummy;
#include "cast5.h"
#include "nessie_bc_test.h"
+#include "performance_test.h"
+#include "cli.h"
#include <stdint.h>
#include <string.h>
+#include <stdlib.h>
char* cipher_name = "cast-128 (cast5)";
}
-
+void test_performance_cast5(void){
+ uint16_t i,c;
+ uint64_t t;
+ char str[6];
+ uint8_t key[16], data[16];
+ cast5_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);
+
+ memset(key, 0, 16);
+ memset(data, 0, 16);
+
+ startTimer(1);
+ cast5_init(&ctx, key, 128);
+ t = stopTimer();
+ uart_putstr_P(PSTR("\r\n\tctx-gen time: "));
+ uart_hexdump(&t, 8);
+
+
+ startTimer(1);
+ cast5_enc(&ctx, data);
+ t = stopTimer();
+ uart_putstr_P(PSTR("\r\n\tencrypt time: "));
+ uart_hexdump(&t, 8);
+
+
+ startTimer(1);
+ cast5_dec(&ctx, data);
+ t = stopTimer();
+ uart_putstr_P(PSTR("\r\n\tdecrypt time: "));
+ uart_hexdump(&t, 8);
+ uart_putstr_P(PSTR("\r\n"));
+}
/*****************************************************************************
* main *
*****************************************************************************/
+typedef void(*void_fpt)(void);
+
int main (void){
char str[20];
DEBUG_INIT();
uart_putstr("\r\n");
- uart_putstr("\r\n\r\nCrypto-VS\r\nloaded and running\r\n");
-restart:
+ uart_putstr_P(PSTR("\r\n\r\nCrypto-VS ("));
+ uart_putstr(cipher_name);
+ uart_putstr_P(PSTR(")\r\nloaded and running\r\n"));
+
+ PGM_P u = PSTR("nessie\0test\0performance\0");
+ void_fpt v[] = {test_nessie_cast5, test_nessie_cast5, test_performance_cast5};
+
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_cast5();
- test_nessie_cast5();
- 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");
- } /* while (1) */
+ }
}
#include "serpent.h"
#include "nessie_bc_test.h"
#include "cli.h"
+#include "performance_test.h"
#include <stdint.h>
#include <string.h>
+#include <stdlib.h>
char* cipher_name = "Serpent";
}
-
+void testrun_performance_serpent(void){
+ uint16_t i,c;
+ uint64_t t;
+ char str[6];
+ uint8_t key[32], data[16];
+ serpent_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);
+
+ memset(key, 0, 32);
+ memset(data, 0, 16);
+
+ startTimer(1);
+ serpent_genctx(key, 0, &ctx);
+ t = stopTimer();
+ uart_putstr_P(PSTR("\r\n\tctx-gen time: "));
+ uart_hexdump(&t, 8);
+
+
+ startTimer(1);
+ serpent_enc(data, &ctx);
+ t = stopTimer();
+ uart_putstr_P(PSTR("\r\n\tencrypt time: "));
+ uart_hexdump(&t, 8);
+
+
+ startTimer(1);
+ serpent_dec(data, &ctx);
+ t = stopTimer();
+ uart_putstr_P(PSTR("\r\n\tdecrypt time: "));
+ uart_hexdump(&t, 8);
+ uart_putstr_P(PSTR("\r\n"));
+}
/*****************************************************************************
* main *
*****************************************************************************/
uart_putstr(cipher_name);
uart_putstr_P(PSTR(")\r\nloaded and running\r\n"));
- PGM_P u = PSTR("nessie\0test\0");
- void_fpt v[] = {testrun_nessie_serpent, testrun_nessie_serpent};
+ PGM_P u = PSTR("nessie\0test\0performance\0");
+ void_fpt v[] = {testrun_nessie_serpent, testrun_nessie_serpent, testrun_performance_serpent};
while(1){
if (!getnextwordn(str,20)){DEBUG_S("DBG: W1\r\n"); goto error;}
uart_putstr_P(PSTR(" bits"));
}
if(ivsize_b){
- uart_putstr_P(PSTR("\r\nIV size: "));
- utoa(ivsize_b, str, 10);
- uart_putstr(str);
- uart_putstr_P(PSTR(" bits"));
+ if(ivsize_b==(uint16_t)-1){
+ uart_putstr_P(PSTR("\r\nNo initial value (IV) mode"));
+ }
+ {
+ uart_putstr_P(PSTR("\r\nIV size: "));
+ utoa(ivsize_b, str, 10);
+ uart_putstr(str);
+ uart_putstr_P(PSTR(" bits"));
+ }
}
uart_putstr_P(PSTR("\r\n"));
}
uint8_t key[(nessie_stream_ctx.keysize_b+7)/8];
nessie_print_header(nessie_stream_ctx.name, nessie_stream_ctx.keysize_b,
- 0, 0, 0, 0);
+ 0, 0, 0, nessie_stream_ctx.ivsize_b);
/* test set 1 */
set=1;
nessie_print_setheader(set);
typedef struct nessie_stream_ctx_st{
uint16_t keysize_b;
+ uint16_t ivsize_b;
uint16_t outsize_b;
uint16_t ctx_size_B;
char* name;
--- /dev/null
+/*
+ *
+ *
+ *
+ */
+
+#include <stdint.h>
+#include <stdlib.h>
+#include <avr/io.h>
+#include <avr/interrupt.h>
+#include "performance_test.h"
+
+uint32_t ovfcounter;
+
+uint16_t const_overhead=0;
+uint16_t int_overhead=0;
+
+ISR(TIMER1_OVF_vect){
+ ovfcounter++;
+}
+
+void calibrateTimer(void){
+ startTimer(1);
+ stopTimer();
+ const_overhead = TCNT1;
+ startTimer(1);
+ TCNT1=0xFFFE;
+ ; ; ; ;
+// asm volatile("NOP\n"::); asm volatile("NOP\n"::);
+ stopTimer();
+ int_overhead = TCNT1;
+}
+
+void startTimer(uint8_t granularity){
+ TCCR1B = 0; /* stop timer */
+ TCNT1 = 0;
+ ovfcounter = 0;
+ TCCR1A = 0x00;
+ TIMSK &= 0xC3;
+ TIMSK |= _BV(2); /* enable TOIE1 */
+ TCCR1B = granularity & 0x7; /* start timer */
+}
+
+uint64_t stopTimer(void){
+ TCCR1B = 0; /* stop timer */
+ uint64_t ret;
+ ret = (ovfcounter<<16) | TCNT1;
+ ret -= const_overhead;
+ ret -= ovfcounter * int_overhead;
+ return ret;
+}
+
+void getOverhead(uint16_t* constoh, uint16_t* intoh){
+ *constoh = const_overhead;
+ *intoh = int_overhead;
+}
+
+
+
+
--- /dev/null
+#ifndef PERFORMANCE_TEST_H_
+#define PERFORMANCE_TEST_H_
+
+#include <stdint.h>
+
+void calibrateTimer(void);
+void startTimer(uint8_t granularity);
+uint64_t stopTimer(void);
+void getOverhead(uint16_t* constoh, uint16_t* intoh);
+
+#endif /*PERFORMANCE_TEST_H_*/
$(ALGO_NAME)_OBJ := serpent.o serpent-sboxes-bitslice.o
$(ALGO_NAME)_TEST_BIN := main-serpent-test.o debug.o uart.o serial-tools.o \
serpent.o serpent-sboxes-bitslice.o nessie_bc_test.o \
- nessie_common.o cli.o
+ nessie_common.o cli.o performance_test.o
$(ALGO_NAME)_NESSIE_TEST := "nessie"
$(ALGO_NAME)_PEROFRMANCE_TEST := "performance"