s->shortkey = (keylength<=80);
/* littel endian only! */
memset(&(x[0]), 0 ,16); /* set x to zero */
- memcpy(&(x[0]), key, keylength/8);
+ if(keylength > 128)
+ keylength=128;
+ memcpy(&(x[0]), key, (keylength+7)/8);
/* todo: merge a and b and compress the whole stuff */
cast5_init(&ctx, key, 128);
t = stopTimer();
uart_putstr_P(PSTR("\r\n\tctx-gen time: "));
- uart_hexdump(&t, 8);
+ ultoa((unsigned long)t, str, 10);
+ uart_putstr(str);
startTimer(1);
cast5_enc(&ctx, data);
t = stopTimer();
uart_putstr_P(PSTR("\r\n\tencrypt time: "));
- uart_hexdump(&t, 8);
+ ultoa((unsigned long)t, str, 10);
+ uart_putstr(str);
startTimer(1);
cast5_dec(&ctx, data);
t = stopTimer();
uart_putstr_P(PSTR("\r\n\tdecrypt time: "));
- uart_hexdump(&t, 8);
+ ultoa((unsigned long)t, str, 10);
+ uart_putstr(str);
+
uart_putstr_P(PSTR("\r\n"));
}
#include "present.h"
#include "nessie_bc_test.h"
#include "cli.h"
+#include "performance_test.h"
+#include <stdlib.h>
#include <stdint.h>
#include <string.h>
}
+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);
+
+ 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);
+
+ 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);
+
+ 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);
+ 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_present, testrun_self_present};
+ PGM_P u = PSTR("nessie\0test\0performance\0");
+ void_fpt v[] = {testrun_nessie_present, testrun_self_present, testrun_performance_present};
while(1){
if (!getnextwordn(str,20)){DEBUG_S("DBG: W1\r\n"); goto error;}
void testrun_performance_serpent(void){
uint16_t i,c;
uint64_t t;
- char str[6];
+ char str[16];
uint8_t key[32], data[16];
serpent_ctx_t ctx;
serpent_genctx(key, 0, &ctx);
t = stopTimer();
uart_putstr_P(PSTR("\r\n\tctx-gen time: "));
- uart_hexdump(&t, 8);
+ ultoa((unsigned long)t, str, 10);
+ uart_putstr(str);
startTimer(1);
serpent_enc(data, &ctx);
t = stopTimer();
uart_putstr_P(PSTR("\r\n\tencrypt time: "));
- uart_hexdump(&t, 8);
+ ultoa((unsigned long)t, str, 10);
+ uart_putstr(str);
startTimer(1);
serpent_dec(data, &ctx);
t = stopTimer();
uart_putstr_P(PSTR("\r\n\tdecrypt time: "));
- uart_hexdump(&t, 8);
+ ultoa((unsigned long)t, str, 10);
+ uart_putstr(str);
+
uart_putstr_P(PSTR("\r\n"));
}
/*****************************************************************************
$(ALGO_NAME)_OBJ := present.o
$(ALGO_NAME)_TEST_BIN := main-present-test.o debug.o uart.o serial-tools.o \
- present.o nessie_bc_test.o nessie_common.o cli.o
+ present.o nessie_bc_test.o nessie_common.o cli.o \
+ performance_test.o
$(ALGO_NAME)_NESSIE_TEST := "nessie"
$(ALGO_NAME)_PEROFRMANCE_TEST := "performance"