+performance tests; some modifications to the Cast5-test-suit
This commit is contained in:
parent
b567660a24
commit
2c2d732098
4
cast5.mk
4
cast5.mk
|
@ -5,8 +5,8 @@ ALGO_NAME := CAST5
|
||||||
BLOCK_CIPHERS += $(ALGO_NAME)
|
BLOCK_CIPHERS += $(ALGO_NAME)
|
||||||
|
|
||||||
$(ALGO_NAME)_OBJ := cast5.o
|
$(ALGO_NAME)_OBJ := cast5.o
|
||||||
$(ALGO_NAME)_TEST_BIN := main-cast5-test.o debug.o uart.o serial-tools.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
|
cast5.o nessie_bc_test.o nessie_common.o performance_test.o
|
||||||
$(ALGO_NAME)_NESSIE_TEST := "nessie"
|
$(ALGO_NAME)_NESSIE_TEST := "nessie"
|
||||||
$(ALGO_NAME)_PEROFRMANCE_TEST := "performance"
|
$(ALGO_NAME)_PEROFRMANCE_TEST := "performance"
|
||||||
|
|
||||||
|
|
|
@ -28,6 +28,7 @@ void arcfour_genctx_dummy(uint8_t* key, uint16_t keysize, void* ctx){
|
||||||
void testrun_nessie_arcfour(void){
|
void testrun_nessie_arcfour(void){
|
||||||
nessie_stream_ctx.outsize_b = 8; /* actually unused */
|
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.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.name = cipher_name;
|
||||||
nessie_stream_ctx.ctx_size_B = sizeof(arcfour_ctx_t);
|
nessie_stream_ctx.ctx_size_B = sizeof(arcfour_ctx_t);
|
||||||
nessie_stream_ctx.cipher_genctx = (nessie_stream_genctx_fpt)arcfour_genctx_dummy;
|
nessie_stream_ctx.cipher_genctx = (nessie_stream_genctx_fpt)arcfour_genctx_dummy;
|
||||||
|
|
|
@ -10,9 +10,12 @@
|
||||||
|
|
||||||
#include "cast5.h"
|
#include "cast5.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>
|
||||||
|
#include <stdlib.h>
|
||||||
|
|
||||||
char* cipher_name = "cast-128 (cast5)";
|
char* cipher_name = "cast-128 (cast5)";
|
||||||
|
|
||||||
|
@ -149,12 +152,54 @@ void testrun_cast5(void){
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
|
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 *
|
* main *
|
||||||
*****************************************************************************/
|
*****************************************************************************/
|
||||||
|
|
||||||
|
typedef void(*void_fpt)(void);
|
||||||
|
|
||||||
int main (void){
|
int main (void){
|
||||||
char str[20];
|
char str[20];
|
||||||
|
|
||||||
|
@ -162,17 +207,21 @@ int main (void){
|
||||||
DEBUG_INIT();
|
DEBUG_INIT();
|
||||||
uart_putstr("\r\n");
|
uart_putstr("\r\n");
|
||||||
|
|
||||||
uart_putstr("\r\n\r\nCrypto-VS\r\nloaded and running\r\n");
|
uart_putstr_P(PSTR("\r\n\r\nCrypto-VS ("));
|
||||||
restart:
|
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){
|
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_cast5();
|
uart_putstr_P(PSTR("\r\nunknown command\r\n"));
|
||||||
test_nessie_cast5();
|
}
|
||||||
goto restart;
|
|
||||||
continue;
|
continue;
|
||||||
error:
|
error:
|
||||||
uart_putstr("ERROR\r\n");
|
uart_putstr("ERROR\r\n");
|
||||||
} /* while (1) */
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
@ -11,9 +11,11 @@
|
||||||
#include "serpent.h"
|
#include "serpent.h"
|
||||||
#include "nessie_bc_test.h"
|
#include "nessie_bc_test.h"
|
||||||
#include "cli.h"
|
#include "cli.h"
|
||||||
|
#include "performance_test.h"
|
||||||
|
|
||||||
#include <stdint.h>
|
#include <stdint.h>
|
||||||
#include <string.h>
|
#include <string.h>
|
||||||
|
#include <stdlib.h>
|
||||||
|
|
||||||
char* cipher_name = "Serpent";
|
char* cipher_name = "Serpent";
|
||||||
|
|
||||||
|
@ -43,7 +45,47 @@ void testrun_nessie_serpent(void){
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
|
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 *
|
* main *
|
||||||
*****************************************************************************/
|
*****************************************************************************/
|
||||||
|
@ -59,8 +101,8 @@ 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"));
|
||||||
|
|
||||||
PGM_P u = PSTR("nessie\0test\0");
|
PGM_P u = PSTR("nessie\0test\0performance\0");
|
||||||
void_fpt v[] = {testrun_nessie_serpent, testrun_nessie_serpent};
|
void_fpt v[] = {testrun_nessie_serpent, testrun_nessie_serpent, testrun_performance_serpent};
|
||||||
|
|
||||||
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;}
|
||||||
|
|
|
@ -141,10 +141,15 @@ void nessie_print_header(char* name,
|
||||||
uart_putstr_P(PSTR(" bits"));
|
uart_putstr_P(PSTR(" bits"));
|
||||||
}
|
}
|
||||||
if(ivsize_b){
|
if(ivsize_b){
|
||||||
uart_putstr_P(PSTR("\r\nIV size: "));
|
if(ivsize_b==(uint16_t)-1){
|
||||||
utoa(ivsize_b, str, 10);
|
uart_putstr_P(PSTR("\r\nNo initial value (IV) mode"));
|
||||||
uart_putstr(str);
|
}
|
||||||
uart_putstr_P(PSTR(" bits"));
|
{
|
||||||
|
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"));
|
uart_putstr_P(PSTR("\r\n"));
|
||||||
}
|
}
|
||||||
|
|
|
@ -129,7 +129,7 @@ void nessie_stream_run(void){
|
||||||
uint8_t key[(nessie_stream_ctx.keysize_b+7)/8];
|
uint8_t key[(nessie_stream_ctx.keysize_b+7)/8];
|
||||||
|
|
||||||
nessie_print_header(nessie_stream_ctx.name, nessie_stream_ctx.keysize_b,
|
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 */
|
/* test set 1 */
|
||||||
set=1;
|
set=1;
|
||||||
nessie_print_setheader(set);
|
nessie_print_setheader(set);
|
||||||
|
|
|
@ -8,6 +8,7 @@ typedef uint8_t (*nessie_stream_genenc_fpt)(void* ctx);
|
||||||
|
|
||||||
typedef struct nessie_stream_ctx_st{
|
typedef struct nessie_stream_ctx_st{
|
||||||
uint16_t keysize_b;
|
uint16_t keysize_b;
|
||||||
|
uint16_t ivsize_b;
|
||||||
uint16_t outsize_b;
|
uint16_t outsize_b;
|
||||||
uint16_t ctx_size_B;
|
uint16_t ctx_size_B;
|
||||||
char* name;
|
char* name;
|
||||||
|
|
|
@ -0,0 +1,60 @@
|
||||||
|
/*
|
||||||
|
*
|
||||||
|
*
|
||||||
|
*
|
||||||
|
*/
|
||||||
|
|
||||||
|
#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;
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
|
@ -0,0 +1,11 @@
|
||||||
|
#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_*/
|
|
@ -8,7 +8,7 @@ BLOCK_CIPHERS += $(ALGO_NAME)
|
||||||
$(ALGO_NAME)_OBJ := serpent.o serpent-sboxes-bitslice.o
|
$(ALGO_NAME)_OBJ := serpent.o serpent-sboxes-bitslice.o
|
||||||
$(ALGO_NAME)_TEST_BIN := main-serpent-test.o debug.o uart.o serial-tools.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 \
|
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)_NESSIE_TEST := "nessie"
|
||||||
$(ALGO_NAME)_PEROFRMANCE_TEST := "performance"
|
$(ALGO_NAME)_PEROFRMANCE_TEST := "performance"
|
||||||
|
|
||||||
|
|
Loading…
Reference in New Issue