From: bg Date: Sat, 2 Aug 2008 10:37:02 +0000 (+0000) Subject: modification to the build system X-Git-Url: https://git.cryptolib.org/?a=commitdiff_plain;h=2159c273c9d3361571a6ff1ab63d9bc76582fbab;p=avr-crypto-lib.git modification to the build system --- diff --git a/Makefile b/Makefile index 8033ad2..00d1f5f 100644 --- a/Makefile +++ b/Makefile @@ -19,10 +19,7 @@ $(1) = $(2) endef $(foreach a, $(ALGORITHMS_OBJ), $(eval $(call OBJinBINDIR_TEMPLATE, $(a), $(patsubst %.o,$(BIN_DIR)%.o,$($(a)))))) ALGORITHMS_TEST_BIN = $(patsubst %,%_TEST_BIN, $(ALGORITHMS)) -$(foreach a, $(ALGORITHMS_TEST_BIN), $(eval $(call OBJinBINDIR_TEMPLATE, $(a), $(patsubst %.o,$(BIN_DIR)%.o,$($(a)))))) -#ALGORITHMS_TEST_BIN_MAIN = $(foreach a, $(ALGORITHMS_TEST_BIN), $(firstword $($(a)))) -#ALGORITHMS_TEST_BIN_MAIN_ELF = $(patsubst $(BIN_DIR)%.o, $(TESTBIN_DIR)%.elf, $(ALGORITHMS_TEST_BIN_MAIN)) -#ALGORITHMS_TEST_BIN_MAIN_HEX = $(patsubst $(BIN_DIR)%.o, $(TESTBIN_DIR)%.hex, $(ALGORITHMS_TEST_BIN_MAIN)) +$(foreach a, $(ALGORITHMS_TEST_BIN), $(eval $(call OBJinBINDIR_TEMPLATE, $(a), $(patsubst %.o,$(TESTBIN_DIR)%.o,$($(a)))))) ALGORITHMS_TEST_BIN_IMM = $(foreach a, $(ALGORITHMS_TEST_BIN), $($(a))) @@ -41,18 +38,24 @@ all: $(foreach algo, $(ALGORITHMS), $(algo)_OBJ) #------------------------------------------------------------------------------- -define BLA_TEMPLATE2 -$(2): $(3) +define MAIN_OBJ_TEMPLATE +$(2): $(3) $(4) @echo "[gcc]: $$@" # echo $$^ @$(CC) $(CFLAGS) $(LDFLAGS)$(patsubst %.elf,%.map,$(2)) -o \ $(2) \ - $(3) \ + $(3) $(4) \ $(LIBS) endef -#$(foreach algo, $(ALGORITHMS), $(eval $(call BLA_TEMPLATE2, $(algo), $(patsubst $(BIN_DIR)%.o,$(TESTBIN_DIR)%.elf,$(firstword $($(algo)_TEST_BIN))), $(patsubst %.o,%.o,$($(algo)_TEST_BIN)) ))) -$(foreach algo, $(ALGORITHMS), $(eval $(call BLA_TEMPLATE2, $(algo), $(TESTBIN_DIR)main-$(call lc,$(algo))-test.elf, $(patsubst %.o,%.o,$($(algo)_TEST_BIN)) ))) +$(foreach algo, $(ALGORITHMS), $(eval $(call MAIN_OBJ_TEMPLATE, \ + $(algo), \ + $(TESTBIN_DIR)main-$(call lc,$(algo))-test.elf, \ + $(patsubst %.o,%.o,$($(algo)_TEST_BIN)), \ + $(patsubst %.o,%.o,$($(algo)_OBJ)) ))) + + + #------------------------------------------------------------------------------- .PHONY: help @@ -70,6 +73,8 @@ info: @echo " $(MACS)" @echo " PRNG functions:" @echo " $(PRNGS)" + @echo " ALGORITHMS_TEST_BIN" + @echo " $(ALGORITHMS_TEST_BIN)" @echo " ALGORITHMS_TEST_TARGET_ELF:" @echo " $(ALGORITHMS_TEST_TARGET_ELF)" @@ -82,6 +87,15 @@ $(BIN_DIR)%.o: %.S @echo "[as] : $@" @$(CC) $(ASFLAGS) -c -o $@ $< +$(TESTBIN_DIR)%.o: $(TESTSRC_DIR)%.c + @echo "[gcc]: $@" + @$(CC) $(CFLAGS) -c -o $@ $< + +$(TESTBIN_DIR)%.o: $(TESTSRC_DIR)%.S + @echo "[as] : $@" + @$(CC) $(ASFLAGS) -c -o $@ $< + + %.o: %.c @echo "[gcc]: $@" @$(CC) $(CFLAGS) -c -o $@ $< diff --git a/avr-makefile.inc b/avr-makefile.inc index 3585afe..0e09617 100644 --- a/avr-makefile.inc +++ b/avr-makefile.inc @@ -7,6 +7,7 @@ FLASHCMD = avrdude -p $(MCU_TARGET) -P /dev/ttyUSB0 -c avr911 -U flash:w:# DEP_DIR = deps/ BIN_DIR = bin/ TESTBIN_DIR = test_bin/ +TESTSRC_DIR = test_src/ #uisp -dprog=bsd -dlpt=/dev/parport1 --upload if=$(PRG).hex ERASECMD = TESTPORT = /dev/ttyUSB1 @@ -15,7 +16,7 @@ TESTLOG_DIR = testlog/ TESTPREFIX = nessie- CC = avr-gcc -override CFLAGS = -MMD -MF$(DEP_DIR)$(patsubst %.c,%.d,$<) -pedantic -std=c99 -Wall -Wstrict-prototypes $(OPTIMIZE) -mmcu=$(MCU_TARGET) $(DEFS) +override CFLAGS = -MMD -MF$(DEP_DIR)$(patsubst %.c,%.d,$<) -I. -pedantic -std=c99 -Wall -Wstrict-prototypes $(OPTIMIZE) -mmcu=$(MCU_TARGET) $(DEFS) override LDFLAGS = -Wl,-Map, override ASFLAGS = -mmcu=$(MCU_TARGET) diff --git a/cli.c b/cli.c deleted file mode 100644 index 8c15f5f..0000000 --- a/cli.c +++ /dev/null @@ -1,73 +0,0 @@ -/* cli.c */ -/* - This file is part of the Crypto-avr-lib/microcrypt-lib. - Copyright (C) 2008 Daniel Otte (daniel.otte@rub.de) - - This program is free software: you can redistribute it and/or modify - it under the terms of the GNU General Public License as published by - the Free Software Foundation, either version 3 of the License, or - (at your option) any later version. - - This program is distributed in the hope that it will be useful, - but WITHOUT ANY WARRANTY; without even the implied warranty of - MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the - GNU General Public License for more details. - - You should have received a copy of the GNU General Public License - along with this program. If not, see . -*/ -/** - * - * author: Daniel Otte - * email: daniel.otte@rub.de - * license: GPLv3 or later - * - * components to help implementing simple command based interaction - * - **/ - -#include -#include -#include - -int16_t findstring_d0(const char* str, const char* v){ - uint8_t i=0; - while(*v){ - if(!strcmp(str, v)){ - return i; - } - while(*v++) /* go to the next string */ - ; - ++i; - } - return -1; -} - -int16_t findstring_d0_P(const char* str, PGM_P v){ - uint8_t i=0; - while(pgm_read_byte(v)){ - if(!strcmp_P(str, v)){ - return i; - } - while(pgm_read_byte(v++)) /* go to the next string */ - ; - ++i; - } - return -1; -} - -int16_t execcommand_d0_P(const char* str, PGM_P v, void(*fpt[])(void) ){ - uint8_t i=0; - while(pgm_read_byte(v)){ - if(!strcmp_P(str, v)){ - (fpt[i])(); - return i; - } - while(pgm_read_byte(v++)) /* go to the next string */ - ; - ++i; - } - return -1; -} - - diff --git a/cli.h b/cli.h deleted file mode 100644 index c36a6e6..0000000 --- a/cli.h +++ /dev/null @@ -1,31 +0,0 @@ -/* cli.h */ -/* - This file is part of the Crypto-avr-lib/microcrypt-lib. - Copyright (C) 2008 Daniel Otte (daniel.otte@rub.de) - - This program is free software: you can redistribute it and/or modify - it under the terms of the GNU General Public License as published by - the Free Software Foundation, either version 3 of the License, or - (at your option) any later version. - - This program is distributed in the hope that it will be useful, - but WITHOUT ANY WARRANTY; without even the implied warranty of - MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the - GNU General Public License for more details. - - You should have received a copy of the GNU General Public License - along with this program. If not, see . -*/ -#ifndef CLI_H_ -#define CLI_H_ - -#include -#include - -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); - -int16_t execcommand_d0_P(const char* str, PGM_P v, void(*fpt[])(void) ); -#endif /*CLI_H_*/ diff --git a/debug.c b/debug.c deleted file mode 100644 index 3b5fee4..0000000 --- a/debug.c +++ /dev/null @@ -1,64 +0,0 @@ -/* debug.c */ -/* - This file is part of the Crypto-avr-lib/microcrypt-lib. - Copyright (C) 2008 Daniel Otte (daniel.otte@rub.de) - - This program is free software: you can redistribute it and/or modify - it under the terms of the GNU General Public License as published by - the Free Software Foundation, either version 3 of the License, or - (at your option) any later version. - - This program is distributed in the hope that it will be useful, - but WITHOUT ANY WARRANTY; without even the implied warranty of - MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the - GNU General Public License for more details. - - You should have received a copy of the GNU General Public License - along with this program. If not, see . -*/ -/*************************** -* -* -* -****************************/ -#include "config.h" - -#if DEBUG == uart - #include "uart.h" -#else - #error "Your DEBUG methode is not suported!" -#endif - -#ifdef DEBUG - void debug_init(void){ - #if DBUG==uart - uart_init(); - #else - #error "Your DEBUG methode is not suported!" - #endif - } - - void debug_char(char c){ - static char initialised = 0; - if (!initialised){ - uart_init(); - initialised=1; - } - uart_putc(c); - } - - void debug_str(char* s){ - while (*s) - debug_char(*s++); - } - - - - void debug_byte(char b){ - char table[] = "0123456789ABCDEF"; - debug_char(table[(b>>4) & 0xf]); - debug_char(table[b&0xf]); - } - -#endif //DEBUG - diff --git a/deps/test_src b/deps/test_src new file mode 120000 index 0000000..945c9b4 --- /dev/null +++ b/deps/test_src @@ -0,0 +1 @@ +. \ No newline at end of file diff --git a/main-arcfour-test.c b/main-arcfour-test.c deleted file mode 100644 index 0e0be91..0000000 --- a/main-arcfour-test.c +++ /dev/null @@ -1,86 +0,0 @@ -/* main-arcfour-test.c */ -/* - This file is part of the Crypto-avr-lib/microcrypt-lib. - Copyright (C) 2008 Daniel Otte (daniel.otte@rub.de) - - This program is free software: you can redistribute it and/or modify - it under the terms of the GNU General Public License as published by - the Free Software Foundation, either version 3 of the License, or - (at your option) any later version. - - This program is distributed in the hope that it will be useful, - but WITHOUT ANY WARRANTY; without even the implied warranty of - MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the - GNU General Public License for more details. - - You should have received a copy of the GNU General Public License - along with this program. If not, see . -*/ -/* - * arcfour (RC4 compatible) test-suit - * -*/ - -#include "config.h" -#include "serial-tools.h" -#include "uart.h" -#include "debug.h" - -#include "arcfour.h" -#include "nessie_stream_test.h" - -#include -#include - -char* cipher_name = "Arcfour"; - -/***************************************************************************** - * additional validation-functions * - *****************************************************************************/ -void arcfour_genctx_dummy(uint8_t* key, uint16_t keysize, void* ctx){ - arcfour_init(ctx, key, (keysize+7)/8); -} - - - -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; - nessie_stream_ctx.cipher_enc = (nessie_stream_genenc_fpt)arcfour_gen; - - nessie_stream_run(); -} - - - -/***************************************************************************** - * main * - *****************************************************************************/ - -int main (void){ - char str[20]; - DEBUG_INIT(); - uart_putstr("\r\n"); - - uart_putstr_P(PSTR("\r\n\r\nCrypto-VS (")); - uart_putstr(cipher_name); - uart_putstr_P(PSTR(")\r\nloaded and running\r\n")); - -restart: - 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_arcfour(); - goto restart; - continue; - error: - uart_putstr("ERROR\r\n"); - } - - -} - diff --git a/main-camellia-test.c b/main-camellia-test.c deleted file mode 100644 index 4d64a50..0000000 --- a/main-camellia-test.c +++ /dev/null @@ -1,135 +0,0 @@ -/* main-camellia-test.c */ -/* - This file is part of the Crypto-avr-lib/microcrypt-lib. - Copyright (C) 2008 Daniel Otte (daniel.otte@rub.de) - - This program is free software: you can redistribute it and/or modify - it under the terms of the GNU General Public License as published by - the Free Software Foundation, either version 3 of the License, or - (at your option) any later version. - - This program is distributed in the hope that it will be useful, - but WITHOUT ANY WARRANTY; without even the implied warranty of - MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the - GNU General Public License for more details. - - You should have received a copy of the GNU General Public License - along with this program. If not, see . -*/ -/* - * camellia test-suit - * - */ - -#include "config.h" -#include "serial-tools.h" -#include "uart.h" -#include "debug.h" - -#include "camellia.h" -#include "nessie_bc_test.h" -#include "performance_test.h" -#include "cli.h" - -char* cipher_name = "Camellia"; - - -#include -#include -#include -#include - - -/***************************************************************************** - * additional validation-functions * - *****************************************************************************/ -void camellia128_init_dummy(void* key, uint16_t keysize_b, void* ctx){ - camellia128_init(key, ctx); -} - -void testrun_nessie_camellia(void){ - nessie_bc_ctx.blocksize_B = 16; - nessie_bc_ctx.keysize_b = 128; - nessie_bc_ctx.name = cipher_name; - nessie_bc_ctx.ctx_size_B = sizeof(camellia128_ctx_t); - nessie_bc_ctx.cipher_enc = (nessie_bc_enc_fpt)camellia128_enc; - nessie_bc_ctx.cipher_dec = (nessie_bc_dec_fpt)camellia128_dec; - nessie_bc_ctx.cipher_genctx = (nessie_bc_gen_fpt)camellia128_init_dummy; - - nessie_bc_run(); -} - - -void test_performance_camellia(void){ - uint64_t t; - char str[6]; - uint8_t key[16], data[16]; - camellia128_ctx_t ctx; - - calibrateTimer(); - print_overhead(); - - memset(key, 0, 16); - memset(data, 0, 16); - - startTimer(1); - camellia128_init(key, &ctx); - t = stopTimer(); - uart_putstr_P(PSTR("\r\n\tctx-gen time: ")); - ultoa((unsigned long)t, str, 10); - uart_putstr(str); - - - startTimer(1); - camellia128_enc(data, &ctx); - t = stopTimer(); - uart_putstr_P(PSTR("\r\n\tencrypt time: ")); - ultoa((unsigned long)t, str, 10); - uart_putstr(str); - - - startTimer(1); - camellia128_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")); -} - - - -/***************************************************************************** - * self tests * - *****************************************************************************/ - -/***************************************************************************** - * main * - *****************************************************************************/ - -int main (void){ - char str[20]; - - - DEBUG_INIT(); - uart_putstr("\r\n"); - - 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[] = {testrun_nessie_camellia, testrun_nessie_camellia, test_performance_camellia}; - - while(1){ - 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"); - } -} - diff --git a/main-cast5-test.c b/main-cast5-test.c deleted file mode 100644 index 2cfb3d1..0000000 --- a/main-cast5-test.c +++ /dev/null @@ -1,220 +0,0 @@ -/* main-cast5-test.c */ -/* - This file is part of the Crypto-avr-lib/microcrypt-lib. - Copyright (C) 2008 Daniel Otte (daniel.otte@rub.de) - - This program is free software: you can redistribute it and/or modify - it under the terms of the GNU General Public License as published by - the Free Software Foundation, either version 3 of the License, or - (at your option) any later version. - - This program is distributed in the hope that it will be useful, - but WITHOUT ANY WARRANTY; without even the implied warranty of - MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the - GNU General Public License for more details. - - You should have received a copy of the GNU General Public License - along with this program. If not, see . -*/ -/* - * cast5 test-suit - * -*/ - -#include "config.h" -#include "serial-tools.h" -#include "uart.h" -#include "debug.h" - -#include "cast5.h" -#include "nessie_bc_test.h" -#include "performance_test.h" -#include "cli.h" - -#include -#include -#include - -char* cipher_name = "cast-128 (cast5)"; - -/***************************************************************************** - * additional validation-functions * - *****************************************************************************/ - -void testrun_nessie_cast5(void){ - nessie_bc_ctx.blocksize_B = 8; - nessie_bc_ctx.keysize_b = 128; - nessie_bc_ctx.name = cipher_name; - nessie_bc_ctx.ctx_size_B = sizeof(cast5_ctx_t); - nessie_bc_ctx.cipher_enc = (nessie_bc_enc_fpt)cast5_enc; - nessie_bc_ctx.cipher_dec = (nessie_bc_dec_fpt)cast5_dec; - nessie_bc_ctx.cipher_genctx = (nessie_bc_gen_fpt)cast5_init; - - nessie_bc_run(); -} - -/***************************************************************************** - * self tests * - *****************************************************************************/ - -void cast5_ctx_dump(cast5_ctx_t *s){ - uint8_t i; - uart_putstr("\r\n==== cast5_ctx_dump ====\r\n shortkey: "); - uart_putstr(s->shortkey?"yes":"no"); - for(i=0;i<16;++i){ - uint8_t r; - uart_putstr("\r\n Km"); uart_hexdump(&i, 1); uart_putc(':'); - uart_hexdump(&(s->mask[i]), 4); - uart_putstr("\r\n Kr"); uart_hexdump(&i, 1); uart_putc(':'); - r = (s->rotl[i/2]); - if (i&0x01) r >>= 4; - r &= 0xf; - r += (s->roth[i>>3]&(1<<(i&0x7)))?0x10:0x00; - uart_hexdump(&r, 1); - } -} - - -void test_encrypt(uint8_t *block, uint8_t *key, uint8_t keylength, bool print){ - cast5_ctx_t s; - if (print){ - uart_putstr("\r\nCAST5:\r\n key:\t"); - uart_hexdump(key, keylength/8); - uart_putstr("\r\n plaintext:\t"); - uart_hexdump(block, 8); - } - cast5_init(key, keylength, &s); - cast5_enc(block, &s); - if (print){ - uart_putstr("\r\n ciphertext:\t"); - uart_hexdump(block, 8); - } -} - -void test_decrypt(uint8_t *block, uint8_t *key, uint8_t keylength, bool print){ - cast5_ctx_t s; - if (print){ - uart_putstr("\r\nCAST5:\r\n key:\t"); - uart_hexdump(key, keylength/8); - uart_putstr("\r\n ciphertext:\t"); - uart_hexdump(block, 8); - } - cast5_init(key, keylength, &s); - cast5_dec(block, &s); - if (print){ - uart_putstr("\r\n plaintext:\t"); - uart_hexdump(block, 8); - } -} - -void testrun_cast5(void){ - uint8_t block[8]; - uint8_t key[16]; - uint8_t *tda = (uint8_t*)"\x01\x23\x45\x67\x89\xAB\xCD\xEF", - *tka = (uint8_t*)"\x01\x23\x45\x67\x12\x34\x56\x78\x23\x45\x67\x89\x34\x56\x78\x9A"; - memcpy(block, tda, 8); - memcpy(key, tka, 16); - test_encrypt(block, key, 128, true); - test_decrypt(block, key, 128, true); - memcpy(block, tda, 8); - memcpy(key, tka, 16); - test_encrypt(block, key, 80, true); - test_decrypt(block, key, 80, true); - memcpy(block, tda, 8); - memcpy(key, tka, 16); - test_encrypt(block, key, 40, true); - test_decrypt(block, key, 40, true); - -/**** long test *****/ - uart_putstr("\r\nmaintance-test"); - uint8_t a[16]= {0x01, 0x23, 0x45, 0x67, 0x12, - 0x34, 0x56, 0x78, 0x23, 0x45, - 0x67, 0x89, 0x34, 0x56, 0x78, - 0x9A}, - b[16]= {0x01, 0x23, 0x45, 0x67, 0x12, - 0x34, 0x56, 0x78, 0x23, 0x45, - 0x67, 0x89, 0x34, 0x56, 0x78, - 0x9A}; - uint32_t i; - for(i=0;i<1000000; ++i){ - test_encrypt(&(a[0]), &(b[0]), 128, false); - test_encrypt(&(a[8]), &(b[0]), 128, false); - test_encrypt(&(b[0]), &(a[0]), 128, false); - test_encrypt(&(b[8]), &(a[0]), 128, false); - if ((i&0x000000ff) == 0){ - uart_putstr("\r\n"); - uart_hexdump(&i, 4); - } - } - uart_putstr("\r\na = "); uart_hexdump(a, 16); - uart_putstr("\r\nb = "); uart_hexdump(b, 16); - -} - -void testrun_performance_cast5(void){ - uint64_t t; - char str[6]; - uint8_t key[16], data[16]; - cast5_ctx_t ctx; - - calibrateTimer(); - print_overhead(); - - memset(key, 0, 16); - memset(data, 0, 16); - - startTimer(1); - cast5_init(key, 128, &ctx); - t = stopTimer(); - uart_putstr_P(PSTR("\r\n\tctx-gen time: ")); - ultoa((unsigned long)t, str, 10); - uart_putstr(str); - - - startTimer(1); - cast5_enc(data, &ctx); - t = stopTimer(); - uart_putstr_P(PSTR("\r\n\tencrypt time: ")); - ultoa((unsigned long)t, str, 10); - uart_putstr(str); - - - startTimer(1); - cast5_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 * - *****************************************************************************/ - -int main (void){ - char str[20]; - - - DEBUG_INIT(); - uart_putstr("\r\n"); - - 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[] = {testrun_nessie_cast5, testrun_cast5, testrun_performance_cast5}; - - while(1){ - 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"); - } -} - diff --git a/main-des-test.c b/main-des-test.c deleted file mode 100644 index 714781c..0000000 --- a/main-des-test.c +++ /dev/null @@ -1,123 +0,0 @@ -/* main-des-test.c */ -/* - This file is part of the Crypto-avr-lib/microcrypt-lib. - Copyright (C) 2008 Daniel Otte (daniel.otte@rub.de) - - This program is free software: you can redistribute it and/or modify - it under the terms of the GNU General Public License as published by - the Free Software Foundation, either version 3 of the License, or - (at your option) any later version. - - This program is distributed in the hope that it will be useful, - but WITHOUT ANY WARRANTY; without even the implied warranty of - MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the - GNU General Public License for more details. - - You should have received a copy of the GNU General Public License - along with this program. If not, see . -*/ -/* - * des test-suit - * -*/ - -#include "config.h" -#include "serial-tools.h" -#include "uart.h" -#include "debug.h" - -#include "des.h" -#include "nessie_bc_test.h" -#include "cli.h" -#include "performance_test.h" - -#include -#include -#include - -char* cipher_name = "DES"; - -/***************************************************************************** - * additional validation-functions * - *****************************************************************************/ -void des_init_dummy(const void* key, uint16_t keysize_b, void* ctx){ - memcpy(ctx, key, 8); -} - -void des_enc_dummy(void* buffer, void* ctx){ - des_enc(buffer, buffer, ctx); -} - -void des_dec_dummy(void* buffer, void* ctx){ - des_dec(buffer, buffer, ctx); -} - -void testrun_nessie_des(void){ - nessie_bc_init(); - nessie_bc_ctx.blocksize_B = 8; - nessie_bc_ctx.keysize_b = 64; - nessie_bc_ctx.name = cipher_name; - nessie_bc_ctx.ctx_size_B = 8; - nessie_bc_ctx.cipher_enc = (nessie_bc_enc_fpt)des_enc_dummy; - nessie_bc_ctx.cipher_dec = (nessie_bc_dec_fpt)des_dec_dummy; - nessie_bc_ctx.cipher_genctx = (nessie_bc_gen_fpt)des_init_dummy; - - nessie_bc_run(); -} - - -void testrun_performance_des(void){ - uint64_t t; - char str[16]; - uint8_t key[8], data[8]; - - - calibrateTimer(); - print_overhead(); - - memset(key, 0, 8); - memset(data, 0, 8); - - startTimer(1); - des_enc(data, data, key); - t = stopTimer(); - uart_putstr_P(PSTR("\r\n\tencrypt time: ")); - ultoa((unsigned long)t, str, 10); - uart_putstr(str); - - startTimer(1); - des_dec(data, data, key); - 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 - *****************************************************************************/ - -int main (void){ - char str[20]; - DEBUG_INIT(); - uart_putstr("\r\n"); - - 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[] = {testrun_nessie_des, testrun_nessie_des, testrun_performance_des}; - - while(1){ - 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"); - } - -} - diff --git a/main-entropium-test.c b/main-entropium-test.c deleted file mode 100644 index 3384396..0000000 --- a/main-entropium-test.c +++ /dev/null @@ -1,116 +0,0 @@ -/* main-entropium-test.c */ -/* - This file is part of the Crypto-avr-lib/microcrypt-lib. - Copyright (C) 2008 Daniel Otte (daniel.otte@rub.de) - - This program is free software: you can redistribute it and/or modify - it under the terms of the GNU General Public License as published by - the Free Software Foundation, either version 3 of the License, or - (at your option) any later version. - - This program is distributed in the hope that it will be useful, - but WITHOUT ANY WARRANTY; without even the implied warranty of - MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the - GNU General Public License for more details. - - You should have received a copy of the GNU General Public License - along with this program. If not, see . -*/ -/* - * entropium test-suit - * -*/ - -#include "config.h" -#include "serial-tools.h" -#include "uart.h" -#include "debug.h" - -#include "entropium.h" -#include "nessie_bc_test.h" -#include "cli.h" -#include "performance_test.h" - -#include -#include -#include - -char* cipher_name = "Entropium"; - -/***************************************************************************** - * additional validation-functions * - *****************************************************************************/ - -void testrun_entropium(void){ - char c, str[16]; - uint8_t data[32]; - uint32_t i=0; - while(!uart_getc_nb(&c)){ - entropium_getRandomBlock(data); - uart_putstr_P(PSTR("\r\n ")); - ultoa(i, str, 10); - for(c=strlen(str); c<11; ++c){ - uart_putc(' '); - } - uart_putstr(str); - ++i; - uart_putstr_P(PSTR(" : ")); - uart_hexdump(data, 32); - } - uart_putstr_P(PSTR("\r\n\r\n")); -} - - -void testrun_performance_entropium(void){ - uint64_t t; - char str[16]; - uint8_t data[32]; - - calibrateTimer(); - print_overhead(); - - startTimer(1); - entropium_addEntropy(128, data); - t = stopTimer(); - uart_putstr_P(PSTR("\r\n\tadd entropy time: ")); - ultoa((unsigned long)t, str, 10); - uart_putstr(str); - - - startTimer(1); - entropium_getRandomBlock(data); - t = stopTimer(); - uart_putstr_P(PSTR("\r\n\tget random time: ")); - ultoa((unsigned long)t, str, 10); - uart_putstr(str); - - uart_putstr_P(PSTR("\r\n")); -} -/***************************************************************************** - * main * - *****************************************************************************/ - -int main (void){ - char str[20]; - DEBUG_INIT(); - uart_putstr("\r\n"); - - 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[] = {testrun_entropium, testrun_entropium, testrun_performance_entropium}; - - while(1){ - 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"); - } - -} - diff --git a/main-grain-test.c b/main-grain-test.c deleted file mode 100644 index 44f08f8..0000000 --- a/main-grain-test.c +++ /dev/null @@ -1,180 +0,0 @@ -/* main-grain-test.c */ -/* - This file is part of the Crypto-avr-lib/microcrypt-lib. - Copyright (C) 2008 Daniel Otte (daniel.otte@rub.de) - - This program is free software: you can redistribute it and/or modify - it under the terms of the GNU General Public License as published by - the Free Software Foundation, either version 3 of the License, or - (at your option) any later version. - - This program is distributed in the hope that it will be useful, - but WITHOUT ANY WARRANTY; without even the implied warranty of - MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the - GNU General Public License for more details. - - You should have received a copy of the GNU General Public License - along with this program. If not, see . -*/ -/* - * grain test-suit - * -*/ - -#include "config.h" -#include "serial-tools.h" -#include "uart.h" -#include "debug.h" -#include "cli.h" - -#include "grain.h" -#include "nessie_stream_test.h" -#include "performance_test.h" - -#include -#include -#include - -char* cipher_name = "Grain"; - -/***************************************************************************** - * additional validation-functions * - *****************************************************************************/ -void grain_genctx_dummy(uint8_t* key, uint16_t keysize_b, void* ctx){ - uint8_t iv[8]={0}; - grain_init(key, &iv, ctx); -} - -uint8_t grain_getbyte_dummy(grain_ctx_t* ctx){ - uint8_t i,ret=0; - for(i=0; i<8; ++i){ - ret<<=1; - ret |= grain_enc(ctx); - } - return ret; -} - -uint8_t grain_getbyte_dummy_rev(grain_ctx_t* ctx){ - uint8_t i,ret=0; - for(i=0; i<8; ++i){ - ret >>= 1; - ret |= grain_enc(ctx)?0x80:0x00; - } - return ret; -} - -void testrun_nessie_grain(void){ - nessie_stream_ctx.outsize_b = 8; /* actually unused */ - nessie_stream_ctx.keysize_b = 80; /* this is the one we have refrence vectors for */ - nessie_stream_ctx.ivsize_b = 64; - nessie_stream_ctx.name = cipher_name; - nessie_stream_ctx.ctx_size_B = sizeof(grain_ctx_t); - nessie_stream_ctx.cipher_genctx = (nessie_stream_genctx_fpt)grain_genctx_dummy; - nessie_stream_ctx.cipher_enc = (nessie_stream_genenc_fpt)grain_getbyte_dummy_rev; - - nessie_stream_run(); -} - - -void testrun_std_grain(void){ - grain_ctx_t ctx; - uint8_t i, key[10], iv[8], out[10]; - - /* 1 */ - memset(key, 0, 10); - memset(iv, 0, 8); - uart_putstr_P(PSTR("\r\n=== std test ===")); - uart_putstr_P(PSTR("\r\n key: ")); - uart_hexdump(key, 10); - uart_putstr_P(PSTR("\r\n iv: ")); - uart_hexdump(key, 8); - grain_init(key, iv, &ctx); - for(i=0; i<10; ++i){ - out[i] = grain_getbyte_dummy(&ctx); - } - uart_putstr_P(PSTR("\r\n out: ")); - uart_hexdump(out, 10); - - /* 2 */ - for(i=0; i<8; ++i){ - key[i] = i*0x22+1; - } - key[8]=0x12; - key[9]=0x34; - - for(i=0; i<8; ++i){ - iv[i] = i*0x22+1; - } - uart_putstr_P(PSTR("\r\n\r\n key: ")); - uart_hexdump(key, 10); - uart_putstr_P(PSTR("\r\n iv: ")); - uart_hexdump(key, 8); - grain_init(key, iv, &ctx); - for(i=0; i<10; ++i){ - out[i] = grain_getbyte_dummy(&ctx); - } - uart_putstr_P(PSTR("\r\n out: ")); - uart_hexdump(out, 10); - - - uart_putstr_P(PSTR("\r\n\r\n")); -} - -void testrun_performance_grain(void){ - uint64_t t; - char str[16]; - uint8_t key[10], iv[8]; - grain_ctx_t ctx; - - calibrateTimer(); - print_overhead(); - - memset(key, 0, 10); - memset(iv, 0, 8); - - startTimer(1); - grain_init(key, iv, &ctx); - t = stopTimer(); - uart_putstr_P(PSTR("\r\n\tctx-gen time: ")); - ultoa((unsigned long)t, str, 10); - uart_putstr(str); - - startTimer(1); - grain_enc(&ctx); - t = stopTimer(); - uart_putstr_P(PSTR("\r\n\tencrypt time: ")); - ultoa((unsigned long)t, str, 10); - uart_putstr(str); - - uart_putstr_P(PSTR("\r\n")); -} - -/***************************************************************************** - * main * - *****************************************************************************/ - -int main (void){ - char str[20]; - DEBUG_INIT(); - uart_putstr("\r\n"); - - 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[] = {testrun_nessie_grain, testrun_std_grain, testrun_performance_grain}; - - while(1){ - 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"); - } -} - - - diff --git a/main-hmac-sha1-test.c b/main-hmac-sha1-test.c deleted file mode 100644 index 2a786df..0000000 --- a/main-hmac-sha1-test.c +++ /dev/null @@ -1,100 +0,0 @@ -/* main-hmac-sha1-test.c */ -/* - This file is part of the Crypto-avr-lib/microcrypt-lib. - Copyright (C) 2008 Daniel Otte (daniel.otte@rub.de) - - This program is free software: you can redistribute it and/or modify - it under the terms of the GNU General Public License as published by - the Free Software Foundation, either version 3 of the License, or - (at your option) any later version. - - This program is distributed in the hope that it will be useful, - but WITHOUT ANY WARRANTY; without even the implied warranty of - MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the - GNU General Public License for more details. - - You should have received a copy of the GNU General Public License - along with this program. If not, see . -*/ -/* - * HMAC-SHA1 test-suit - * -*/ - -#include "config.h" -#include "serial-tools.h" -#include "uart.h" -#include "debug.h" - -#include "sha1.h" -#include "hmac-sha1.h" - -#include "nessie_mac_test.h" - -#include -#include -#include "cli.h" - -char* algo_name = "HMAC-SHA1"; - -/***************************************************************************** - * additional validation-functions * - *****************************************************************************/ -void hmacsha1_next_dummy(void* buffer, void* ctx){ - sha1_nextBlock(ctx, buffer); -} - -void hmacsha1_init_dummy(void* key, uint16_t keysize_b, void* ctx){ - hmac_sha1_init(ctx, key, keysize_b); -} - -void hmacsha1_last_dummy(void* buffer, uint16_t size_b, void* key, uint16_t keysize_b, void* ctx){ - sha1_lastBlock(ctx, buffer, size_b); - hmac_sha1_final(ctx, key, keysize_b); -} - -void testrun_nessie_hmacsha1(void){ - nessie_mac_ctx.macsize_b = 160; - nessie_mac_ctx.keysize_b = 512; - nessie_mac_ctx.blocksize_B = 512/8; - nessie_mac_ctx.ctx_size_B = sizeof(hmac_sha1_ctx_t); - nessie_mac_ctx.name = algo_name; - nessie_mac_ctx.mac_init = (nessie_mac_init_fpt)hmacsha1_init_dummy; - nessie_mac_ctx.mac_next = (nessie_mac_next_fpt)hmacsha1_next_dummy; - nessie_mac_ctx.mac_last = (nessie_mac_last_fpt)hmacsha1_last_dummy; - nessie_mac_ctx.mac_conv = (nessie_mac_conv_fpt)sha1_ctx2hash; - - nessie_mac_run(); -} - - - -/***************************************************************************** - * main * - *****************************************************************************/ - -int main (void){ - char str[20]; - DEBUG_INIT(); - uart_putstr("\r\n"); - - uart_putstr_P(PSTR("\r\n\r\nCrypto-VS (")); - uart_putstr(algo_name); - uart_putstr_P(PSTR(")\r\nloaded and running\r\n")); - - PGM_P u = PSTR("nessie\0test\0"); - void_fpt v[] = {testrun_nessie_hmacsha1, testrun_nessie_hmacsha1}; - - while(1){ - 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"); - } - - -} - diff --git a/main-hmac-sha256-test.c b/main-hmac-sha256-test.c deleted file mode 100644 index 819ed57..0000000 --- a/main-hmac-sha256-test.c +++ /dev/null @@ -1,96 +0,0 @@ -/* main-hmac-sha256-test.c */ -/* - This file is part of the Crypto-avr-lib/microcrypt-lib. - Copyright (C) 2008 Daniel Otte (daniel.otte@rub.de) - - This program is free software: you can redistribute it and/or modify - it under the terms of the GNU General Public License as published by - the Free Software Foundation, either version 3 of the License, or - (at your option) any later version. - - This program is distributed in the hope that it will be useful, - but WITHOUT ANY WARRANTY; without even the implied warranty of - MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the - GNU General Public License for more details. - - You should have received a copy of the GNU General Public License - along with this program. If not, see . -*/ -/* - * HMAC-SHA256 test-suit - * -*/ - -#include "config.h" -#include "serial-tools.h" -#include "uart.h" -#include "debug.h" - -#include "sha256.h" -#include "hmac-sha256.h" - -#include "nessie_mac_test.h" - -#include -#include - -char* algo_name = "HMAC-SHA256"; - -/***************************************************************************** - * additional validation-functions * - *****************************************************************************/ -void hmacsha256_next_dummy(void* buffer, void* ctx){ - sha256_nextBlock(ctx, buffer); -} - -void hmacsha256_init_dummy(void* key, uint16_t keysize_b, void* ctx){ - hmac_sha256_init(ctx, key, keysize_b); -} - -void hmacsha256_last_dummy(void* buffer, uint16_t size_b, void* key, uint16_t keysize_b, void* ctx){ - sha256_lastBlock(ctx, buffer, size_b); - hmac_sha256_final(ctx, key, keysize_b); -} - -void testrun_nessie_hmacsha256(void){ - nessie_mac_ctx.macsize_b = 256; - nessie_mac_ctx.keysize_b = 512; - nessie_mac_ctx.blocksize_B = 512/8; - nessie_mac_ctx.ctx_size_B = sizeof(hmac_sha256_ctx_t); - nessie_mac_ctx.name = algo_name; - nessie_mac_ctx.mac_init = (nessie_mac_init_fpt)hmacsha256_init_dummy; - nessie_mac_ctx.mac_next = (nessie_mac_next_fpt)hmacsha256_next_dummy; - nessie_mac_ctx.mac_last = (nessie_mac_last_fpt)hmacsha256_last_dummy; - nessie_mac_ctx.mac_conv = (nessie_mac_conv_fpt)sha256_ctx2hash; - - nessie_mac_run(); -} - - - -/***************************************************************************** - * main * - *****************************************************************************/ - -int main (void){ - char str[20]; - DEBUG_INIT(); - uart_putstr("\r\n"); - - uart_putstr_P(PSTR("\r\n\r\nCrypto-VS (")); - uart_putstr(algo_name); - uart_putstr_P(PSTR(")\r\nloaded and running\r\n")); - -restart: - 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_hmacsha256(); - goto restart; - continue; - error: - uart_putstr("ERROR\r\n"); - } - -} - diff --git a/main-md5-test.c b/main-md5-test.c deleted file mode 100644 index 490ee48..0000000 --- a/main-md5-test.c +++ /dev/null @@ -1,168 +0,0 @@ -/* main-md5-test.c */ -/* - This file is part of the Crypto-avr-lib/microcrypt-lib. - Copyright (C) 2008 Daniel Otte (daniel.otte@rub.de) - - This program is free software: you can redistribute it and/or modify - it under the terms of the GNU General Public License as published by - the Free Software Foundation, either version 3 of the License, or - (at your option) any later version. - - This program is distributed in the hope that it will be useful, - but WITHOUT ANY WARRANTY; without even the implied warranty of - MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the - GNU General Public License for more details. - - You should have received a copy of the GNU General Public License - along with this program. If not, see . -*/ -/* - * md5 test suit - * -*/ - -#include "config.h" -#include "serial-tools.h" -#include "uart.h" -#include "debug.h" - -#include "md5.h" -#include "nessie_hash_test.h" -#include "performance_test.h" - -#include -#include -#include -#include "cli.h" - -char* algo_name = "MD5"; - -/***************************************************************************** - * additional validation-functions * - *****************************************************************************/ -void md5_next_dummy(void* buffer, void* ctx){ - md5_nextBlock(ctx, buffer); -} - -void md5_last_dummy(void* buffer, uint16_t size_b, void* ctx){ - md5_lastBlock(ctx, buffer, size_b); -} - -void md5_ctx2hash_dummy(void* buffer, void* ctx){ - memcpy(buffer, ctx, 16); -} - - -void testrun_nessie_md5(void){ - nessie_hash_ctx.hashsize_b = 128; - nessie_hash_ctx.blocksize_B = 512/8; - nessie_hash_ctx.ctx_size_B = sizeof(md5_ctx_t); - nessie_hash_ctx.name = algo_name; - nessie_hash_ctx.hash_init = (nessie_hash_init_fpt)md5_init; - nessie_hash_ctx.hash_next = (nessie_hash_next_fpt)md5_next_dummy; - nessie_hash_ctx.hash_last = (nessie_hash_last_fpt)md5_last_dummy; - nessie_hash_ctx.hash_conv = (nessie_hash_conv_fpt)md5_ctx2hash_dummy; - - nessie_hash_run(); -} - -/***************************************************************************** - * self tests * - *****************************************************************************/ - -/* - * MD5 test suite: - * MD5 ("") = d41d8cd98f00b204e9800998ecf8427e - * MD5 ("a") = 0cc175b9c0f1b6a831c399e269772661 - * MD5 ("abc") = 900150983cd24fb0d6963f7d28e17f72 - * MD5 ("message digest") = f96b697d7cb7938d525a2f31aaf161d0 - * MD5 ("abcdefghijklmnopqrstuvwxyz") = c3fcd3d76192e4007dfb496cca67e13b - * MD5 ("ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789") = - * d174ab98d277d9f5a5611c2c9f419d9f - * MD5 ("123456789012345678901234567890123456789012345678901234567890123456 - * 78901234567890") = 57edf4a22be3c955ac49da2e2107b67a - */ - -void testrun_md5(void){ - md5_ctx_t s; - char* testv[]={"", "a", "abc", "message digest", "abcdefghijklmnopqrstuvwxyz", - "ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789", - "12345678901234567890123456789012345678901234567890123456789012345678901234567890"}; - uint8_t i; - - uart_putstr("\r\n=== MD5 test suit ==="); - for(i=0; i<7; ++i){ - uart_putstr("\r\n MD5 (\""); - uart_putstr(testv[i]); - uart_putstr("\") = \r\n"); - md5_init(&s); - md5_lastBlock(&s, testv[i], strlen(testv[i])*8); - uart_hexdump(&s.a[0], 16); - } -} - - -void testrun_performance_md5(void){ - uint64_t t; - char str[16]; - uint8_t data[32]; - md5_ctx_t ctx; - - calibrateTimer(); - print_overhead(); - - memset(data, 0, 32); - - startTimer(1); - md5_init(&ctx); - t = stopTimer(); - uart_putstr_P(PSTR("\r\n\tctx-gen time: ")); - ultoa((unsigned long)t, str, 10); - uart_putstr(str); - - - startTimer(1); - md5_nextBlock(&ctx, data); - t = stopTimer(); - uart_putstr_P(PSTR("\r\n\tone-block time: ")); - ultoa((unsigned long)t, str, 10); - uart_putstr(str); - - - startTimer(1); - md5_lastBlock(&ctx, data, 0); - t = stopTimer(); - uart_putstr_P(PSTR("\r\n\tlast block time: ")); - ultoa((unsigned long)t, str, 10); - uart_putstr(str); - - uart_putstr_P(PSTR("\r\n")); -} - - -/***************************************************************************** - * main * - *****************************************************************************/ - -int main (void){ - char str[20]; - - - DEBUG_INIT(); - uart_putstr("\r\n"); - - uart_putstr("\r\n\r\nCrypto-VS (MD5)\r\nloaded and running\r\n"); - PGM_P u = PSTR("nessie\0test\0performance\0"); - void_fpt v[] = {testrun_nessie_md5, testrun_md5, testrun_performance_md5}; - - while(1){ - 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"); - } -} - diff --git a/main-noekeon-test.c b/main-noekeon-test.c deleted file mode 100644 index 851c7bc..0000000 --- a/main-noekeon-test.c +++ /dev/null @@ -1,241 +0,0 @@ -/* main-noekeon-test.c */ -/* - This file is part of the Crypto-avr-lib/microcrypt-lib. - Copyright (C) 2008 Daniel Otte (daniel.otte@rub.de) - - This program is free software: you can redistribute it and/or modify - it under the terms of the GNU General Public License as published by - the Free Software Foundation, either version 3 of the License, or - (at your option) any later version. - - This program is distributed in the hope that it will be useful, - but WITHOUT ANY WARRANTY; without even the implied warranty of - MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the - GNU General Public License for more details. - - You should have received a copy of the GNU General Public License - along with this program. If not, see . -*/ -/* - * serpent test-suit - * -*/ - -#include "config.h" -#include "serial-tools.h" -#include "uart.h" -#include "debug.h" - -#include "noekeon.h" -#include "nessie_bc_test.h" -#include "cli.h" -#include "performance_test.h" - -#include -#include -#include - -char* cipher_name = "Noekeon"; - -/***************************************************************************** - * additional validation-functions * - *****************************************************************************/ -void noekeon_genctx_dummy(uint8_t* key, uint16_t keysize, void* ctx){ - noekeon_init(key, ctx); -} - -void testrun_nessie_noekeon_indirect(void){ - char str[strlen(cipher_name)+10]; - strcpy(str, cipher_name); - strcat(str, "-indirect"); - - nessie_bc_ctx.blocksize_B = 16; - nessie_bc_ctx.keysize_b = 128; - nessie_bc_ctx.name = str; - nessie_bc_ctx.ctx_size_B = sizeof(noekeon_ctx_t); - nessie_bc_ctx.cipher_enc = (nessie_bc_enc_fpt)noekeon_enc; - nessie_bc_ctx.cipher_dec = (nessie_bc_dec_fpt)noekeon_dec; - nessie_bc_ctx.cipher_genctx = (nessie_bc_gen_fpt)noekeon_genctx_dummy; - - nessie_bc_run(); -} - -void noekeon_genctx_dummy_direct(uint8_t* key, uint16_t keysize, void* ctx){ - memcpy(ctx, key, 16); -} - -void testrun_nessie_noekeon_direct(void){ - char str[strlen(cipher_name)+10]; - strcpy(str, cipher_name); - strcat(str, "-Direct"); - - nessie_bc_ctx.blocksize_B = 16; - nessie_bc_ctx.keysize_b = 128; - nessie_bc_ctx.name = str; - nessie_bc_ctx.ctx_size_B = sizeof(noekeon_ctx_t); - nessie_bc_ctx.cipher_enc = (nessie_bc_enc_fpt)noekeon_enc; - nessie_bc_ctx.cipher_dec = (nessie_bc_dec_fpt)noekeon_dec; - nessie_bc_ctx.cipher_genctx = (nessie_bc_gen_fpt)noekeon_genctx_dummy_direct; - - nessie_bc_run(); -} - -void testrun_nessie_noekeon(void){ - testrun_nessie_noekeon_direct(); - testrun_nessie_noekeon_indirect(); -} - - -void testrun_stdtest_rundirect(void* data, void* key){ - uart_putstr_P(PSTR("\r\n ")); - uart_putstr_P(PSTR("k = ")); - uart_hexdump(key,16); - - uart_putstr_P(PSTR("\r\n ")); - uart_putstr_P(PSTR("a = ")); - uart_hexdump(data,16); - - noekeon_enc(data, key); - uart_putstr_P(PSTR("\r\nafter NESSIEencrypt, b = ")); - uart_hexdump(data,16); - - noekeon_dec(data, key); - uart_putstr_P(PSTR("\r\nafter NESSIEdecrypt, a?= ")); - uart_hexdump(data,16); - uart_putstr_P(PSTR("\r\n")); -} - -void testrun_stdtest_runindirect(void* data, void* key){ - noekeon_ctx_t ctx; - uart_putstr_P(PSTR("\r\n ")); - uart_putstr_P(PSTR("k = ")); - uart_hexdump(key,16); - - uart_putstr_P(PSTR("\r\n ")); - uart_putstr_P(PSTR("a = ")); - uart_hexdump(data,16); - noekeon_init(key, &ctx); - noekeon_enc(data, &ctx); - uart_putstr_P(PSTR("\r\nafter NESSIEencrypt, b = ")); - uart_hexdump(data,16); - - noekeon_dec(data, &ctx); - uart_putstr_P(PSTR("\r\nafter NESSIEdecrypt, a?= ")); - uart_hexdump(data,16); - uart_putstr_P(PSTR("\r\n")); -} - -void testrun_stdtest_noekeon(void){ - uint8_t key[16], data[16]; - uint8_t key3[16]; - noekeon_ctx_t ctx; - - uart_putstr_P(PSTR("\r\nTest vectors for block cipher Noekeon in Indirect-Key Mode:\r\n")); - - memset(key, 0, 16); - memset(data, 0, 16); - testrun_stdtest_runindirect(data, key); - - memset(key, 0xFF, 16); - memset(data, 0xFF, 16); - testrun_stdtest_runindirect(data, key); - - memset(key, 0, 16); - memset(data, 0, 16); - noekeon_init(key, &ctx); - noekeon_enc(data, &ctx); - memcpy(key3, data, 16); - memset(key, 0xFF, 16); - memset(data, 0xFF, 16); - noekeon_init(key, &ctx); - noekeon_enc(data, &ctx); - testrun_stdtest_runindirect(data, key3); - - uart_putstr_P(PSTR("\r\nTest vectors for block cipher Noekeon in Direct-Key Mode:\r\n")); - - memset(key, 0, 16); - memset(data, 0, 16); - testrun_stdtest_rundirect(data, key); - - memset(key, 0xFF, 16); - memset(data, 0xFF, 16); - testrun_stdtest_rundirect(data, key); - - memset(key, 0, 16); - memset(data, 0, 16); - noekeon_enc(data, key); - memcpy(key3, data, 16); - memset(key, 0xFF, 16); - memset(data, 0xFF, 16); - noekeon_enc(data, key); - testrun_stdtest_rundirect(data, key3); - -} - -void testrun_performance_noekeon(void){ - uint64_t t; - char str[16]; - uint8_t key[16], data[16]; - noekeon_ctx_t ctx; - - calibrateTimer(); - print_overhead(); - - memset(key, 0, 16); - memset(data, 0, 16); - - startTimer(1); - noekeon_init(key, &ctx); - t = stopTimer(); - uart_putstr_P(PSTR("\r\n\tctx-gen time: ")); - ultoa((unsigned long)t, str, 10); - uart_putstr(str); - - startTimer(1); - noekeon_enc(data, &ctx); - t = stopTimer(); - uart_putstr_P(PSTR("\r\n\tencrypt time: ")); - ultoa((unsigned long)t, str, 10); - uart_putstr(str); - - startTimer(1); - noekeon_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 * - *****************************************************************************/ - -int main (void){ - char str[20]; - DEBUG_INIT(); - uart_putstr("\r\n"); - - 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\0direct\0indirect\0performance\0"); - void_fpt v[] = {testrun_nessie_noekeon, - testrun_stdtest_noekeon, - testrun_nessie_noekeon_direct, - testrun_nessie_noekeon_indirect, - testrun_performance_noekeon}; - - while(1){ - 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"); - } - -} - diff --git a/main-present-test.c b/main-present-test.c deleted file mode 100644 index 4c739bc..0000000 --- a/main-present-test.c +++ /dev/null @@ -1,152 +0,0 @@ -/* main-present-test.c */ -/* - This file is part of the Crypto-avr-lib/microcrypt-lib. - Copyright (C) 2008 Daniel Otte (daniel.otte@rub.de) - - This program is free software: you can redistribute it and/or modify - it under the terms of the GNU General Public License as published by - the Free Software Foundation, either version 3 of the License, or - (at your option) any later version. - - This program is distributed in the hope that it will be useful, - but WITHOUT ANY WARRANTY; without even the implied warranty of - MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the - GNU General Public License for more details. - - You should have received a copy of the GNU General Public License - along with this program. If not, see . -*/ -/* - * present test-suit - * -*/ - -#include "config.h" -#include "serial-tools.h" -#include "uart.h" -#include "debug.h" - -#include "present.h" -#include "nessie_bc_test.h" -#include "cli.h" -#include "performance_test.h" - -#include -#include -#include - -char* cipher_name = "Present"; - -/***************************************************************************** - * additional validation-functions * - *****************************************************************************/ -void present_genctx_dummy(uint8_t* key, uint16_t keysize_b, present_ctx_t* ctx){ - present_init(key, keysize_b, ctx); -} - -void testrun_nessie_present(void){ - nessie_bc_ctx.blocksize_B = 8; - nessie_bc_ctx.keysize_b = 80; - nessie_bc_ctx.name = cipher_name; - nessie_bc_ctx.ctx_size_B = sizeof(present_ctx_t); - nessie_bc_ctx.cipher_enc = (nessie_bc_enc_fpt)present_enc; - nessie_bc_ctx.cipher_dec = (nessie_bc_dec_fpt)present_dec; - nessie_bc_ctx.cipher_genctx = (nessie_bc_gen_fpt)present_genctx_dummy; - - nessie_bc_run(); -} - -void testrun_selfenc(uint8_t* key, uint8_t* buffer){ - present_ctx_t ctx; - uart_putstr_P(PSTR("\r\nkey : ")); - uart_hexdump(key, 10); - uart_putstr_P(PSTR("\r\nplain : ")); - uart_hexdump(buffer, 8); - present_init(key, 80, &ctx); - present_enc(buffer, &ctx); - uart_putstr_P(PSTR("\r\ncipher: ")); - uart_hexdump(buffer, 8); - present_dec(buffer, &ctx); - uart_putstr_P(PSTR("\r\nplain : ")); - uart_hexdump(buffer, 8); - uart_putstr_P(PSTR("\r\n")); -} - -void testrun_self_present(void){ - uint8_t buffer[8], key[10]; - uart_putstr_P(PSTR("\r\n\r\n=== Testvectors from the paper ===\r\n")); - - memset(buffer, 0, 8); - memset(key, 0, 10); - testrun_selfenc(key, buffer); - - memset(buffer, 0, 8); - memset(key, 0xFF, 10); - testrun_selfenc(key, buffer); - - memset(buffer, 0xFF, 8); - memset(key, 0, 10); - testrun_selfenc(key, buffer); - - memset(buffer, 0xFF, 8); - memset(key, 0xFF, 10); - testrun_selfenc(key, buffer); - -} - -void testrun_performance_present(void){ - uint64_t t; - uint8_t key[10], data[8]; - present_ctx_t ctx; - - calibrateTimer(); - print_overhead(); - - memset(key, 0, 10); - memset(data, 0, 8); - - startTimer(1); - present_init(key, 80, &ctx); - t = stopTimer(); - print_time_P(PSTR("\tctx-gen time: "),t); - - startTimer(1); - present_enc(data, &ctx); - t = stopTimer(); - print_time_P(PSTR("\tencrypt time: "), t); - - startTimer(1); - present_dec(data, &ctx); - t = stopTimer(); - print_time_P(PSTR("\tdecrypt time: "), t); - - uart_putstr_P(PSTR("\r\n")); -} - -/***************************************************************************** - * main * - *****************************************************************************/ - -int main (void){ - char str[20]; - DEBUG_INIT(); - uart_putstr("\r\n"); - - 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[] = {testrun_nessie_present, testrun_self_present, testrun_performance_present}; - - while(1){ - 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"); - } - -} diff --git a/main-rc5-test.c b/main-rc5-test.c deleted file mode 100644 index 2c16aea..0000000 --- a/main-rc5-test.c +++ /dev/null @@ -1,131 +0,0 @@ -/* main-rc5-test.c */ -/* - This file is part of the Crypto-avr-lib/microcrypt-lib. - Copyright (C) 2008 Daniel Otte (daniel.otte@rub.de) - - This program is free software: you can redistribute it and/or modify - it under the terms of the GNU General Public License as published by - the Free Software Foundation, either version 3 of the License, or - (at your option) any later version. - - This program is distributed in the hope that it will be useful, - but WITHOUT ANY WARRANTY; without even the implied warranty of - MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the - GNU General Public License for more details. - - You should have received a copy of the GNU General Public License - along with this program. If not, see . -*/ -/* - * rc5 test-suit - * -*/ - -#include "config.h" -#include "serial-tools.h" -#include "uart.h" -#include "debug.h" - -#include "rc5.h" -#include "nessie_bc_test.h" -#include "cli.h" -#include "performance_test.h" - -#include -#include -#include - -#define RC5_ROUNDS 12 -char* cipher_name = "RC5-32/12/16"; - -/***************************************************************************** - * additional validation-functions * - *****************************************************************************/ -void rc5_genctx_dummy(uint8_t* key, uint16_t keysize_b, void* ctx){ - rc5_init(key, keysize_b, RC5_ROUNDS, ctx); -} - -void testrun_nessie_rc5(void){ - nessie_bc_init(); - nessie_bc_ctx.blocksize_B = 8; - nessie_bc_ctx.keysize_b = 128; - nessie_bc_ctx.name = cipher_name; - nessie_bc_ctx.ctx_size_B = sizeof(rc5_ctx_t); - nessie_bc_ctx.cipher_enc = (nessie_bc_enc_fpt)rc5_enc; - nessie_bc_ctx.cipher_dec = (nessie_bc_dec_fpt)rc5_dec; - nessie_bc_ctx.cipher_free = (nessie_bc_free_fpt)rc5_free; - nessie_bc_ctx.cipher_genctx = (nessie_bc_gen_fpt)rc5_genctx_dummy; - - nessie_bc_run(); -} - - -void testrun_performance_rc5(void){ - uint64_t t; - char str[16]; - uint8_t key[16], data[16]; - rc5_ctx_t ctx; - - calibrateTimer(); - print_overhead(); - - memset(key, 0, 16); - memset(data, 0, 16); - - startTimer(1); - rc5_init(key, 128, RC5_ROUNDS, &ctx); - t = stopTimer(); - uart_putstr_P(PSTR("\r\n\tctx-gen time: ")); - ultoa((unsigned long)t, str, 10); - uart_putstr(str); - - startTimer(1); - rc5_enc(data, &ctx); - t = stopTimer(); - uart_putstr_P(PSTR("\r\n\tencrypt time: ")); - ultoa((unsigned long)t, str, 10); - uart_putstr(str); - - startTimer(1); - rc5_dec(data, &ctx); - t = stopTimer(); - uart_putstr_P(PSTR("\r\n\tdecrypt time: ")); - ultoa((unsigned long)t, str, 10); - uart_putstr(str); - - startTimer(1); - rc5_free(&ctx); - t = stopTimer(); - uart_putstr_P(PSTR("\r\n\tfree time: ")); - ultoa((unsigned long)t, str, 10); - uart_putstr(str); - uart_putstr_P(PSTR("\r\n")); -} -/***************************************************************************** - * main * - *****************************************************************************/ - -int main (void){ - char str[20]; - DEBUG_INIT(); - uart_putstr("\r\n"); - - 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[] = {testrun_nessie_rc5, testrun_nessie_rc5, testrun_performance_rc5}; - - while(1){ - 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"); - } - -} - diff --git a/main-rc6-test.c b/main-rc6-test.c deleted file mode 100644 index 5d7ecda..0000000 --- a/main-rc6-test.c +++ /dev/null @@ -1,138 +0,0 @@ -/* main-rc6-test.c */ -/* - This file is part of the Crypto-avr-lib/microcrypt-lib. - Copyright (C) 2008 Daniel Otte (daniel.otte@rub.de) - - This program is free software: you can redistribute it and/or modify - it under the terms of the GNU General Public License as published by - the Free Software Foundation, either version 3 of the License, or - (at your option) any later version. - - This program is distributed in the hope that it will be useful, - but WITHOUT ANY WARRANTY; without even the implied warranty of - MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the - GNU General Public License for more details. - - You should have received a copy of the GNU General Public License - along with this program. If not, see . -*/ -/* - * rc5 test-suit - * -*/ - -#include "config.h" -#include "serial-tools.h" -#include "uart.h" -#include "debug.h" - -#include "rc6.h" -#include "nessie_bc_test.h" -#include "cli.h" -#include "performance_test.h" - -#include -#include -#include - -#define RC6_ROUNDS 20 -char* cipher_name = "RC6-32/20/16"; - -/***************************************************************************** - * additional validation-functions * - *****************************************************************************/ -void rc6_genctx_dummy(uint8_t* key, uint16_t keysize_b, void* ctx){ - rc6_initl(key, keysize_b, RC6_ROUNDS, ctx); -} - -void testrun_nessie_rc6(void){ - nessie_bc_init(); - nessie_bc_ctx.blocksize_B = 16; - nessie_bc_ctx.keysize_b = 128; - nessie_bc_ctx.name = cipher_name; - nessie_bc_ctx.ctx_size_B = sizeof(rc6_ctx_t); - nessie_bc_ctx.cipher_enc = (nessie_bc_enc_fpt)rc6_enc; - nessie_bc_ctx.cipher_dec = (nessie_bc_dec_fpt)rc6_dec; - nessie_bc_ctx.cipher_free = (nessie_bc_free_fpt)rc6_free; - nessie_bc_ctx.cipher_genctx = (nessie_bc_gen_fpt)rc6_init; - - nessie_bc_run(); - - nessie_bc_ctx.keysize_b = 192; - nessie_bc_run(); - - nessie_bc_ctx.keysize_b = 256; - nessie_bc_run(); - -} - - -void testrun_performance_rc6(void){ - uint64_t t; - char str[16]; - uint8_t key[16], data[16]; - rc6_ctx_t ctx; - - calibrateTimer(); - print_overhead(); - - memset(key, 0, 16); - memset(data, 0, 16); - - startTimer(1); - rc6_init(key, 128, &ctx); - t = stopTimer(); - uart_putstr_P(PSTR("\r\n\tctx-gen time: ")); - ultoa((unsigned long)t, str, 10); - uart_putstr(str); - - startTimer(1); - rc6_enc(data, &ctx); - t = stopTimer(); - uart_putstr_P(PSTR("\r\n\tencrypt time: ")); - ultoa((unsigned long)t, str, 10); - uart_putstr(str); - - startTimer(1); - rc6_dec(data, &ctx); - t = stopTimer(); - uart_putstr_P(PSTR("\r\n\tdecrypt time: ")); - ultoa((unsigned long)t, str, 10); - uart_putstr(str); - - startTimer(1); - rc6_free(&ctx); - t = stopTimer(); - uart_putstr_P(PSTR("\r\n\tfree time: ")); - ultoa((unsigned long)t, str, 10); - uart_putstr(str); - uart_putstr_P(PSTR("\r\n")); -} -/***************************************************************************** - * main * - *****************************************************************************/ - -int main (void){ - char str[20]; - DEBUG_INIT(); - uart_putstr("\r\n"); - - 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[] = {testrun_nessie_rc6, testrun_nessie_rc6, testrun_performance_rc6}; - - while(1){ - 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"); - } - -} - diff --git a/main-seed-test.c b/main-seed-test.c deleted file mode 100644 index 678d132..0000000 --- a/main-seed-test.c +++ /dev/null @@ -1,189 +0,0 @@ -/* main-seed-test.c */ -/* - This file is part of the Crypto-avr-lib/microcrypt-lib. - Copyright (C) 2008 Daniel Otte (daniel.otte@rub.de) - - This program is free software: you can redistribute it and/or modify - it under the terms of the GNU General Public License as published by - the Free Software Foundation, either version 3 of the License, or - (at your option) any later version. - - This program is distributed in the hope that it will be useful, - but WITHOUT ANY WARRANTY; without even the implied warranty of - MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the - GNU General Public License for more details. - - You should have received a copy of the GNU General Public License - along with this program. If not, see . -*/ -/** - * \file main-seed-test.c - * \author Daniel Otte - * \email daniel.otte@rub.de - * \date 2007-06-01 - * \brief test suit for SEED - * \par License - * GPLv3 or later - * - */ -#include "config.h" -#include "serial-tools.h" -#include "uart.h" -#include "debug.h" - -#include "seed.h" -#include "nessie_bc_test.h" -#include "cli.h" -#include "performance_test.h" - -#include -#include -#include - -char* cipher_name = "Seed"; - -/***************************************************************************** - * additional validation-functions * - *****************************************************************************/ -void seed_genctx_dummy(uint8_t* key, uint16_t keysize, void* ctx){ - seed_init(key, ctx); -} - -void testrun_nessie_seed(void){ - nessie_bc_ctx.blocksize_B = 16; - nessie_bc_ctx.keysize_b = 128; - nessie_bc_ctx.name = cipher_name; - nessie_bc_ctx.ctx_size_B = sizeof(seed_ctx_t); - nessie_bc_ctx.cipher_enc = (nessie_bc_enc_fpt)seed_enc; - nessie_bc_ctx.cipher_dec = (nessie_bc_dec_fpt)seed_dec; - nessie_bc_ctx.cipher_genctx = (nessie_bc_gen_fpt)seed_genctx_dummy; - - nessie_bc_run(); - -} - - -void testrun_performance_seed(void){ - uint64_t t; - char str[16]; - uint8_t key[16], data[16]; - seed_ctx_t ctx; - - calibrateTimer(); - print_overhead(); - - memset(key, 0, 16); - memset(data, 0, 16); - - startTimer(1); - seed_init(key, &ctx); - t = stopTimer(); - uart_putstr_P(PSTR("\r\n\tctx-gen time: ")); - ultoa((unsigned long)t, str, 10); - uart_putstr(str); - - - startTimer(1); - seed_enc(data, &ctx); - t = stopTimer(); - uart_putstr_P(PSTR("\r\n\tencrypt time: ")); - ultoa((unsigned long)t, str, 10); - uart_putstr(str); - - - startTimer(1); - seed_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")); -} - -/***************************************************************************** - * self tests * - *****************************************************************************/ - -void testencrypt(uint8_t* block, uint8_t* key){ - seed_ctx_t ctx; - uart_putstr("\r\n==testy-encrypt==\r\n key: "); - uart_hexdump(key,16); - seed_init(key, &ctx); - uart_putstr("\r\n plain: "); - uart_hexdump(block,16); - seed_enc(block, &ctx); - uart_putstr("\r\n crypt: "); - uart_hexdump(block,16); -} - -void testdecrypt(uint8_t* block, uint8_t* key){ - seed_ctx_t ctx; - uart_putstr("\r\n==testy-decrypt==\r\n key: "); - uart_hexdump(key,16); - seed_init(key, &ctx); - uart_putstr("\r\n crypt: "); - uart_hexdump(block,16); - seed_dec(block, &ctx); - uart_putstr("\r\n plain: "); - uart_hexdump(block,16); -} - -void testrun_seed(void){ - uint8_t keys[4][16]= - { { 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, - 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00 }, - { 0x00, 0x01, 0x02, 0x03, 0x04, 0x05, 0x06, 0x07, - 0x08, 0x09, 0x0a, 0x0b, 0x0c, 0x0d, 0x0e, 0x0f }, - { 0x47, 0x06, 0x48, 0x08, 0x51, 0xE6, 0x1B, 0xE8, - 0x5D, 0x74, 0xBF, 0xB3, 0xFD, 0x95, 0x61, 0x85 }, - { 0x28, 0xDB, 0xC3, 0xBC, 0x49, 0xFF, 0xD8, 0x7D, - 0xCF, 0xA5, 0x09, 0xB1, 0x1D, 0x42, 0x2B, 0xE7,} - }; - uint8_t datas[4][16]= - { { 0x00, 0x01, 0x02, 0x03, 0x04, 0x05, 0x06, 0x07, - 0x08, 0x09, 0x0a, 0x0b, 0x0c, 0x0d, 0x0e, 0x0f }, - { 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, - 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00 }, - { 0x83, 0xA2, 0xF8, 0xA2, 0x88, 0x64, 0x1F, 0xB9, - 0xA4, 0xE9, 0xA5, 0xCC, 0x2F, 0x13, 0x1C, 0x7D }, - { 0xB4, 0x1E, 0x6B, 0xE2, 0xEB, 0xA8, 0x4A, 0x14, - 0x8E, 0x2E, 0xED, 0x84, 0x59, 0x3C, 0x5E, 0xC7 } - }; - uint8_t i=0; - for(i=0; i<4; ++i){ - testencrypt(datas[i],keys[i]); - testdecrypt(datas[i],keys[i]); - } -} - - - -/***************************************************************************** - * main * - *****************************************************************************/ - -int main (void){ - char str[20]; - - DEBUG_INIT(); - - 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[] = {testrun_nessie_seed, testrun_seed, testrun_performance_seed}; - - while(1){ - 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"); - } - -} - diff --git a/main-serpent-test.c b/main-serpent-test.c deleted file mode 100644 index 5c450b6..0000000 --- a/main-serpent-test.c +++ /dev/null @@ -1,130 +0,0 @@ -/* main-serpent-test.c */ -/* - This file is part of the Crypto-avr-lib/microcrypt-lib. - Copyright (C) 2008 Daniel Otte (daniel.otte@rub.de) - - This program is free software: you can redistribute it and/or modify - it under the terms of the GNU General Public License as published by - the Free Software Foundation, either version 3 of the License, or - (at your option) any later version. - - This program is distributed in the hope that it will be useful, - but WITHOUT ANY WARRANTY; without even the implied warranty of - MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the - GNU General Public License for more details. - - You should have received a copy of the GNU General Public License - along with this program. If not, see . -*/ -/* - * serpent test-suit - * -*/ - -#include "config.h" -#include "serial-tools.h" -#include "uart.h" -#include "debug.h" - -#include "serpent.h" -#include "nessie_bc_test.h" -#include "cli.h" -#include "performance_test.h" - -#include -#include -#include - -char* cipher_name = "Serpent"; - -/***************************************************************************** - * additional validation-functions * - *****************************************************************************/ -void serpent_genctx_dummy(uint8_t* key, uint16_t keysize, void* ctx){ - serpent_init(key, keysize&0xff, ctx); -} - -void testrun_nessie_serpent(void){ - nessie_bc_ctx.blocksize_B = 16; - nessie_bc_ctx.keysize_b = 128; - nessie_bc_ctx.name = cipher_name; - nessie_bc_ctx.ctx_size_B = sizeof(serpent_ctx_t); - nessie_bc_ctx.cipher_enc = (nessie_bc_enc_fpt)serpent_enc; - nessie_bc_ctx.cipher_dec = (nessie_bc_dec_fpt)serpent_dec; - nessie_bc_ctx.cipher_genctx = (nessie_bc_gen_fpt)serpent_genctx_dummy; - - nessie_bc_run(); - - nessie_bc_ctx.keysize_b = 192; - nessie_bc_run(); - - nessie_bc_ctx.keysize_b = 256; - nessie_bc_run(); -} - - -void testrun_performance_serpent(void){ - uint64_t t; - char str[16]; - uint8_t key[32], data[16]; - serpent_ctx_t ctx; - - calibrateTimer(); - print_overhead(); - - memset(key, 0, 32); - memset(data, 0, 16); - - startTimer(1); - serpent_init(key, 0, &ctx); - t = stopTimer(); - uart_putstr_P(PSTR("\r\n\tctx-gen time: ")); - 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: ")); - 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: ")); - ultoa((unsigned long)t, str, 10); - uart_putstr(str); - - uart_putstr_P(PSTR("\r\n")); -} -/***************************************************************************** - * main * - *****************************************************************************/ - -int main (void){ - char str[20]; - DEBUG_INIT(); - uart_putstr("\r\n"); - - 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[] = {testrun_nessie_serpent, testrun_nessie_serpent, testrun_performance_serpent}; - - while(1){ - 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"); - } - -} - diff --git a/main-sha1-test.c b/main-sha1-test.c deleted file mode 100644 index 6f07227..0000000 --- a/main-sha1-test.c +++ /dev/null @@ -1,171 +0,0 @@ -/* main-sha1-test.c */ -/* - This file is part of the Crypto-avr-lib/microcrypt-lib. - Copyright (C) 2008 Daniel Otte (daniel.otte@rub.de) - - This program is free software: you can redistribute it and/or modify - it under the terms of the GNU General Public License as published by - the Free Software Foundation, either version 3 of the License, or - (at your option) any later version. - - This program is distributed in the hope that it will be useful, - but WITHOUT ANY WARRANTY; without even the implied warranty of - MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the - GNU General Public License for more details. - - You should have received a copy of the GNU General Public License - along with this program. If not, see . -*/ -/* - * SHA-1 test-suit - * -*/ - -#include "config.h" -#include "serial-tools.h" -#include "uart.h" -#include "debug.h" - -#include "sha1.h" -#include "nessie_hash_test.h" -#include "performance_test.h" - -#include -#include -#include -#include "cli.h" - -char* algo_name = "SHA-1"; - -/***************************************************************************** - * additional validation-functions * - *****************************************************************************/ -void sha1_next_dummy(void* buffer, void* ctx){ - sha1_nextBlock(ctx, buffer); -} - -void sha1_last_dummy(void* buffer, uint16_t size_b, void* ctx){ - sha1_lastBlock(ctx, buffer, size_b); -} - -void testrun_nessie_sha1(void){ - nessie_hash_ctx.hashsize_b = 160; - nessie_hash_ctx.blocksize_B = 512/8; - nessie_hash_ctx.ctx_size_B = sizeof(sha1_ctx_t); - nessie_hash_ctx.name = algo_name; - nessie_hash_ctx.hash_init = (nessie_hash_init_fpt)sha1_init; - nessie_hash_ctx.hash_next = (nessie_hash_next_fpt)sha1_next_dummy; - nessie_hash_ctx.hash_last = (nessie_hash_last_fpt)sha1_last_dummy; - nessie_hash_ctx.hash_conv = (nessie_hash_conv_fpt)sha1_ctx2hash; - - nessie_hash_run(); -} - -/***************************************************************************** - * self tests * - *****************************************************************************/ - -void sha1_ctx_dump(sha1_ctx_t *s){ - uint8_t i; - uart_putstr("\r\n==== sha1_ctx_dump ===="); - for(i=0;i<5;++i){ - uart_putstr("\r\na["); uart_hexdump(&i, 1); uart_putstr("]: "); - uart_hexdump(&(s->h[i]), 4); - } - uart_putstr("\r\nlength"); uart_hexdump(&i, 8); -} - -void testrun_sha1(void){ - sha1_hash_t hash; - sha1(&hash,"abc",3*8); - uart_putstr("\r\nsha1(\"abc\") = \r\n\t"); - uart_hexdump(hash,SHA1_HASH_BITS/8); - - sha1(&hash,"abcdbcdecdefdefgefghfghighijhijkijkljklmklmnlmnomnopnopq",448); - uart_putstr("\r\nsha1(\"abcdbcdecdefdefgefghfghighijhijkijkljklmklmnlmnomnopnopq\") = \r\n\t"); - uart_hexdump(hash,SHA1_HASH_BITS/8); - - uart_putstr("\r\nsha1(1,000,000 * 'a') = \r\n\t"); - { - uint8_t block[SHA1_BLOCK_BITS/8]; - uint16_t i; - sha1_ctx_t s; - memset(block,'a',SHA1_BLOCK_BITS/8); - sha1_init(&s); - for(i=0;i<15625; ++i){ /* (1000000/(SHA1_BLOCK_BITS/8)) */ - sha1_nextBlock(&s, block); - } - sha1_lastBlock(&s,block,0); - sha1_ctx2hash(&hash, &s); - } - uart_hexdump(hash,SHA1_HASH_BITS/8); - - - uart_putstr("\r\nx"); -} - -void testrun_performance_sha1(void){ - uint64_t t; - char str[16]; - uint8_t data[32]; - sha1_ctx_t ctx; - - calibrateTimer(); - print_overhead(); - - memset(data, 0, 32); - - startTimer(1); - sha1_init(&ctx); - t = stopTimer(); - uart_putstr_P(PSTR("\r\n\tctx-gen time: ")); - ultoa((unsigned long)t, str, 10); - uart_putstr(str); - - - startTimer(1); - sha1_nextBlock(&ctx, data); - t = stopTimer(); - uart_putstr_P(PSTR("\r\n\tone-block time: ")); - ultoa((unsigned long)t, str, 10); - uart_putstr(str); - - - startTimer(1); - sha1_lastBlock(&ctx, data, 0); - t = stopTimer(); - uart_putstr_P(PSTR("\r\n\tlast block time: ")); - ultoa((unsigned long)t, str, 10); - uart_putstr(str); - - uart_putstr_P(PSTR("\r\n")); -} - - -/***************************************************************************** - * main * - *****************************************************************************/ - -int main (void){ - char str[20]; - - DEBUG_INIT(); - uart_putstr("\r\n"); - - uart_putstr("\r\n\r\nCrypto-VS (SHA-1)\r\nloaded and running\r\n"); - - PGM_P u = PSTR("nessie\0test\0performance\0"); - void_fpt v[] = {testrun_nessie_sha1, testrun_sha1, testrun_performance_sha1}; - - while(1){ - 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"); - } -} - - diff --git a/main-sha256-test.c b/main-sha256-test.c deleted file mode 100644 index 9c3031d..0000000 --- a/main-sha256-test.c +++ /dev/null @@ -1,127 +0,0 @@ -/* main-sha256-test.c */ -/* - This file is part of the Crypto-avr-lib/microcrypt-lib. - Copyright (C) 2008 Daniel Otte (daniel.otte@rub.de) - - This program is free software: you can redistribute it and/or modify - it under the terms of the GNU General Public License as published by - the Free Software Foundation, either version 3 of the License, or - (at your option) any later version. - - This program is distributed in the hope that it will be useful, - but WITHOUT ANY WARRANTY; without even the implied warranty of - MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the - GNU General Public License for more details. - - You should have received a copy of the GNU General Public License - along with this program. If not, see . -*/ -/* - * SHA-256 test-suit - * -*/ - -#include "config.h" -#include "serial-tools.h" -#include "uart.h" -#include "debug.h" - -#include "sha256.h" -#include "nessie_hash_test.h" -#include "performance_test.h" - -#include -#include -#include -#include "cli.h" - -char* algo_name = "SHA-256"; - -/***************************************************************************** - * additional validation-functions * - *****************************************************************************/ -void sha256_next_dummy(void* buffer, void* ctx){ - sha256_nextBlock(ctx, buffer); -} - -void sha256_last_dummy(void* buffer, uint16_t size_b, void* ctx){ - sha256_lastBlock(ctx, buffer, size_b); -} - -void testrun_nessie_sha256(void){ - nessie_hash_ctx.hashsize_b = 256; - nessie_hash_ctx.blocksize_B = 512/8; - nessie_hash_ctx.ctx_size_B = sizeof(sha256_ctx_t); - nessie_hash_ctx.name = algo_name; - nessie_hash_ctx.hash_init = (nessie_hash_init_fpt)sha256_init; - nessie_hash_ctx.hash_next = (nessie_hash_next_fpt)sha256_next_dummy; - nessie_hash_ctx.hash_last = (nessie_hash_last_fpt)sha256_last_dummy; - nessie_hash_ctx.hash_conv = (nessie_hash_conv_fpt)sha256_ctx2hash; - - nessie_hash_run(); -} - -void testrun_performance_sha256(void){ - uint64_t t; - char str[16]; - uint8_t data[32]; - sha256_ctx_t ctx; - - calibrateTimer(); - print_overhead(); - - memset(data, 0, 32); - - startTimer(1); - sha256_init(&ctx); - t = stopTimer(); - uart_putstr_P(PSTR("\r\n\tctx-gen time: ")); - ultoa((unsigned long)t, str, 10); - uart_putstr(str); - - - startTimer(1); - sha256_nextBlock(&ctx, data); - t = stopTimer(); - uart_putstr_P(PSTR("\r\n\tone-block time: ")); - ultoa((unsigned long)t, str, 10); - uart_putstr(str); - - - startTimer(1); - sha256_lastBlock(&ctx, data, 0); - t = stopTimer(); - uart_putstr_P(PSTR("\r\n\tlast block time: ")); - ultoa((unsigned long)t, str, 10); - uart_putstr(str); - - uart_putstr_P(PSTR("\r\n")); -} - -/***************************************************************************** - * main * - *****************************************************************************/ - -int main (void){ - char str[20]; - DEBUG_INIT(); - uart_putstr("\r\n"); - - uart_putstr_P(PSTR("\r\n\r\nCrypto-VS (")); - uart_putstr(algo_name); - uart_putstr_P(PSTR(")\r\nloaded and running\r\n")); - - PGM_P u = PSTR("nessie\0test\0performance\0"); - void_fpt v[] = {testrun_nessie_sha256, testrun_nessie_sha256, testrun_performance_sha256}; - - while(1){ - 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"); - } -} - diff --git a/main-shabea-test.c b/main-shabea-test.c deleted file mode 100644 index f221fd5..0000000 --- a/main-shabea-test.c +++ /dev/null @@ -1,193 +0,0 @@ -/* main-shabea-test.c */ -/* - This file is part of the Crypto-avr-lib/microcrypt-lib. - Copyright (C) 2008 Daniel Otte (daniel.otte@rub.de) - - This program is free software: you can redistribute it and/or modify - it under the terms of the GNU General Public License as published by - the Free Software Foundation, either version 3 of the License, or - (at your option) any later version. - - This program is distributed in the hope that it will be useful, - but WITHOUT ANY WARRANTY; without even the implied warranty of - MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the - GNU General Public License for more details. - - You should have received a copy of the GNU General Public License - along with this program. If not, see . -*/ -/** - * \file main-shabea-test.c - * \author Daniel Otte - * \date 2007-06-07 - * \brief test suit for SHABEA - * \par License - * GPLv3 or later - * - */ -#include "config.h" -#include "serial-tools.h" -#include "uart.h" -#include "debug.h" - -#include "shabea.h" -#include "nessie_bc_test.h" -#include "cli.h" -#include "performance_test.h" - -#include -#include -#include - -char* cipher_name = "Shabea"; - -/***************************************************************************** - * additional validation-functions * - *****************************************************************************/ -void shabea_genctx_dummy(uint8_t* key, uint16_t keysize_b, void* ctx){ - memcpy(ctx, key, (keysize_b+7)/8); -} - -void shabea_enc_dummy(void* buffer, void* ctx){ - shabea256(buffer, ctx, 256, 1, 16); -} - -void shabea_dec_dummy(void* buffer, void* ctx){ - shabea256(buffer, ctx, 256, 0, 16); -} - - -void testrun_nessie_shabea(void){ - nessie_bc_ctx.blocksize_B = 32; - nessie_bc_ctx.keysize_b = 256; - nessie_bc_ctx.name = cipher_name; - nessie_bc_ctx.ctx_size_B = 32; - nessie_bc_ctx.cipher_enc = (nessie_bc_enc_fpt)shabea_enc_dummy; - nessie_bc_ctx.cipher_dec = (nessie_bc_dec_fpt)shabea_dec_dummy; - nessie_bc_ctx.cipher_genctx = (nessie_bc_gen_fpt)shabea_genctx_dummy; - - nessie_bc_run(); -} - - -void testrun_performance_shabea(void){ - uint64_t t; - char str[16]; - uint8_t key[32], data[32]; - - calibrateTimer(); - print_overhead(); - - memset(key, 0, 32); - memset(data, 0, 32); - - startTimer(1); - shabea256(data, key, 256, 1, 16); - t = stopTimer(); - uart_putstr_P(PSTR("\r\n\tencrypt time: ")); - ultoa((unsigned long)t, str, 10); - uart_putstr(str); - - - startTimer(1); - shabea256(data, key, 256, 0, 16); - 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")); -} - -/***************************************************************************** - * self tests * - *****************************************************************************/ - -void testencrypt(uint8_t* block, uint8_t* key){ - uart_putstr("\r\n==testy-encrypt==\r\n key: "); - uart_hexdump(key,16); - uart_putstr("\r\n plain: "); - uart_hexdump(block,32); - shabea256(block,key,128,1,16); - uart_putstr("\r\n crypt: "); - uart_hexdump(block,32); -} - -void testdecrypt(uint8_t* block, uint8_t* key){ - - uart_putstr("\r\n==testy-decrypt==\r\n key: "); - uart_hexdump(key,16); - uart_putstr("\r\n crypt: "); - uart_hexdump(block,32); - shabea256(block,key,128,0,16); - uart_putstr("\r\n plain: "); - uart_hexdump(block,32); -} - -void testrun_shabea(void){ - uint8_t keys[4][16]= - { { 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, - 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00 }, - { 0x00, 0x01, 0x02, 0x03, 0x04, 0x05, 0x06, 0x07, - 0x08, 0x09, 0x0a, 0x0b, 0x0c, 0x0d, 0x0e, 0x0f }, - { 0x47, 0x06, 0x48, 0x08, 0x51, 0xE6, 0x1B, 0xE8, - 0x5D, 0x74, 0xBF, 0xB3, 0xFD, 0x95, 0x61, 0x85 }, - { 0x28, 0xDB, 0xC3, 0xBC, 0x49, 0xFF, 0xD8, 0x7D, - 0xCF, 0xA5, 0x09, 0xB1, 0x1D, 0x42, 0x2B, 0xE7,} - }; - uint8_t datas[4][32]= - { { 0x00, 0x01, 0x02, 0x03, 0x04, 0x05, 0x06, 0x07, - 0x08, 0x09, 0x0a, 0x0b, 0x0c, 0x0d, 0x0e, 0x0f, - 0x10, 0x11, 0x12, 0x13, 0x14, 0x15, 0x16, 0x17, - 0x18, 0x19, 0x1a, 0x1b, 0x1c, 0x1d, 0x1e, 0x1f }, - { 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, - 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, - 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, - 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00 }, - { 0x83, 0xA2, 0xF8, 0xA2, 0x88, 0x64, 0x1F, 0xB9, - 0xA4, 0xE9, 0xA5, 0xCC, 0x2F, 0x13, 0x1C, 0x7D, - 0x83, 0xA2, 0xF8, 0xA2, 0x88, 0x64, 0x1F, 0xB9, - 0xA4, 0xE9, 0xA5, 0xCC, 0x2F, 0x13, 0x1C, 0x7D }, - { 0xB4, 0x1E, 0x6B, 0xE2, 0xEB, 0xA8, 0x4A, 0x14, - 0x8E, 0x2E, 0xED, 0x84, 0x59, 0x3C, 0x5E, 0xC7, - 0xB4, 0x1E, 0x6B, 0xE2, 0xEB, 0xA8, 0x4A, 0x14, - 0x8E, 0x2E, 0xED, 0x84, 0x59, 0x3C, 0x5E, 0xC7 } - }; - uint8_t i=0; - for(i=0; i<4; ++i){ - testencrypt(datas[i],keys[i]); - testdecrypt(datas[i],keys[i]); - } -} - - - -/***************************************************************************** - * main * - *****************************************************************************/ - -int main (void){ - char str[20]; - - DEBUG_INIT(); - uart_putstr("\r\n"); - - 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[] = {testrun_nessie_shabea, testrun_shabea, testrun_performance_shabea}; - - while(1){ - 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"); - } - -} - diff --git a/main-shacal1_enc-test.c b/main-shacal1_enc-test.c deleted file mode 100644 index a4a0a1f..0000000 --- a/main-shacal1_enc-test.c +++ /dev/null @@ -1,110 +0,0 @@ -/* main-shacal1_enc-test.c */ -/* - This file is part of the Crypto-avr-lib/microcrypt-lib. - Copyright (C) 2008 Daniel Otte (daniel.otte@rub.de) - - This program is free software: you can redistribute it and/or modify - it under the terms of the GNU General Public License as published by - the Free Software Foundation, either version 3 of the License, or - (at your option) any later version. - - This program is distributed in the hope that it will be useful, - but WITHOUT ANY WARRANTY; without even the implied warranty of - MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the - GNU General Public License for more details. - - You should have received a copy of the GNU General Public License - along with this program. If not, see . -*/ -/* - * Shacal1 encryption only test-suit - * -*/ - -#include "config.h" -#include "serial-tools.h" -#include "uart.h" -#include "debug.h" - -#include "shacal1_enc.h" -#include "nessie_bc_test.h" -#include "cli.h" -#include "performance_test.h" - -#include -#include -#include - -char* cipher_name = "Shacal1 encryption only"; - -/***************************************************************************** - * additional validation-functions * - *****************************************************************************/ -void shacal1_genctx_dummy(uint8_t* key, uint16_t keysize_b, void* ctx){ - memcpy(ctx, key, (keysize_b+7)/8); -} - -void shacal1_enc_dummy(void* buffer, void* ctx){ - shacal1_enc(buffer, ctx, 512); -} - -void testrun_nessie_shacal1enc(void){ - nessie_bc_ctx.blocksize_B = SHACAL1_BLOCKSIZE_B; - nessie_bc_ctx.keysize_b = SHACAL1_KEYSIZE; - nessie_bc_ctx.name = cipher_name; - nessie_bc_ctx.ctx_size_B = SHACAL1_KEYSIZE_B; - nessie_bc_ctx.cipher_enc = (nessie_bc_enc_fpt)shacal1_enc_dummy; - nessie_bc_ctx.cipher_dec = (nessie_bc_dec_fpt)NULL; - nessie_bc_ctx.cipher_genctx = (nessie_bc_gen_fpt)shacal1_genctx_dummy; - - nessie_bc_run(); -} - -void testrun_performance_shacal1enc(void){ - uint64_t t; - uint8_t key[SHACAL1_KEYSIZE_B], data[SHACAL1_BLOCKSIZE_B]; - - calibrateTimer(); - print_overhead(); - - memset(key, 0, SHACAL1_KEYSIZE_B); - memset(data, 0, SHACAL1_BLOCKSIZE_B); - - - startTimer(1); - shacal1_enc(data, key, SHACAL1_KEYSIZE); - t = stopTimer(); - print_time_P(PSTR("\tencrypt time: "), t); - - uart_putstr_P(PSTR("\r\n")); -} - -/***************************************************************************** - * main * - *****************************************************************************/ - -int main (void){ - char str[20]; - DEBUG_INIT(); - uart_putstr("\r\n"); - - 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[] = {testrun_nessie_shacal1enc, - testrun_nessie_shacal1enc, - testrun_performance_shacal1enc}; - - while(1){ - 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"); - } - -} diff --git a/main-shacal2_enc-test.c b/main-shacal2_enc-test.c deleted file mode 100644 index 3ffd131..0000000 --- a/main-shacal2_enc-test.c +++ /dev/null @@ -1,110 +0,0 @@ -/* main-shacal2_enc-test.c */ -/* - This file is part of the Crypto-avr-lib/microcrypt-lib. - Copyright (C) 2008 Daniel Otte (daniel.otte@rub.de) - - This program is free software: you can redistribute it and/or modify - it under the terms of the GNU General Public License as published by - the Free Software Foundation, either version 3 of the License, or - (at your option) any later version. - - This program is distributed in the hope that it will be useful, - but WITHOUT ANY WARRANTY; without even the implied warranty of - MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the - GNU General Public License for more details. - - You should have received a copy of the GNU General Public License - along with this program. If not, see . -*/ -/* - * Shacal2 encryption only test-suit - * -*/ - -#include "config.h" -#include "serial-tools.h" -#include "uart.h" -#include "debug.h" - -#include "shacal2_enc.h" -#include "nessie_bc_test.h" -#include "cli.h" -#include "performance_test.h" - -#include -#include -#include - -char* cipher_name = "Shacal2 encryption only"; - -/***************************************************************************** - * additional validation-functions * - *****************************************************************************/ -void shacal2_genctx_dummy(uint8_t* key, uint16_t keysize_b, void* ctx){ - memcpy(ctx, key, (keysize_b+7)/8); -} - -void shacal2_enc_dummy(void* buffer, void* ctx){ - shacal2_enc(buffer, ctx, SHACAL2_KEYSIZE); -} - -void testrun_nessie_shacal2enc(void){ - nessie_bc_ctx.blocksize_B = SHACAL2_BLOCKSIZE_B; - nessie_bc_ctx.keysize_b = SHACAL2_KEYSIZE; - nessie_bc_ctx.name = cipher_name; - nessie_bc_ctx.ctx_size_B = SHACAL2_KEYSIZE_B; - nessie_bc_ctx.cipher_enc = (nessie_bc_enc_fpt)shacal2_enc_dummy; - nessie_bc_ctx.cipher_dec = (nessie_bc_dec_fpt)NULL; - nessie_bc_ctx.cipher_genctx = (nessie_bc_gen_fpt)shacal2_genctx_dummy; - - nessie_bc_run(); -} - -void testrun_performance_shacal2enc(void){ - uint64_t t; - uint8_t key[SHACAL2_KEYSIZE_B], data[SHACAL2_BLOCKSIZE_B]; - - calibrateTimer(); - print_overhead(); - - memset(key, 0, SHACAL2_KEYSIZE_B); - memset(data, 0, SHACAL2_BLOCKSIZE_B); - - - startTimer(1); - shacal2_enc(data, key, SHACAL2_KEYSIZE); - t = stopTimer(); - print_time_P(PSTR("\tencrypt time: "), t); - - uart_putstr_P(PSTR("\r\n")); -} - -/***************************************************************************** - * main * - *****************************************************************************/ - -int main (void){ - char str[20]; - DEBUG_INIT(); - uart_putstr("\r\n"); - - 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[] = {testrun_nessie_shacal2enc, - testrun_nessie_shacal2enc, - testrun_performance_shacal2enc}; - - while(1){ - 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"); - } - -} diff --git a/main-skipjack-test.c b/main-skipjack-test.c deleted file mode 100644 index a7f1165..0000000 --- a/main-skipjack-test.c +++ /dev/null @@ -1,150 +0,0 @@ -/* main-skipjack-test.c */ -/* - This file is part of the Crypto-avr-lib/microcrypt-lib. - Copyright (C) 2008 Daniel Otte (daniel.otte@rub.de) - - This program is free software: you can redistribute it and/or modify - it under the terms of the GNU General Public License as published by - the Free Software Foundation, either version 3 of the License, or - (at your option) any later version. - - This program is distributed in the hope that it will be useful, - but WITHOUT ANY WARRANTY; without even the implied warranty of - MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the - GNU General Public License for more details. - - You should have received a copy of the GNU General Public License - along with this program. If not, see . -*/ -/* - * skipjack test-suit - * -*/ - -#include "config.h" -#include "serial-tools.h" -#include "uart.h" -#include "debug.h" - -#include "skipjack.h" -#include "nessie_bc_test.h" -#include "cli.h" -#include "performance_test.h" - -#include -#include -#include - - -char* cipher_name = "Skipjack"; - -/***************************************************************************** - * additional validation-functions * - *****************************************************************************/ -void skipjack_genctx_dummy(uint8_t* key, uint16_t keysize, void* ctx){ - memcpy(ctx, key, 10); -} - -void testrun_nessie_skipjack(void){ - nessie_bc_ctx.blocksize_B = 8; - nessie_bc_ctx.keysize_b = 80; - nessie_bc_ctx.name = cipher_name; - nessie_bc_ctx.ctx_size_B = 10; - nessie_bc_ctx.cipher_enc = (nessie_bc_enc_fpt)skipjack_enc; - nessie_bc_ctx.cipher_dec = (nessie_bc_dec_fpt)skipjack_dec; - nessie_bc_ctx.cipher_genctx = (nessie_bc_gen_fpt)skipjack_genctx_dummy; - - nessie_bc_run(); -} - - -void testrun_performance_skipjack(void){ - uint64_t t; - char str[16]; - uint8_t key[10], data[8]; - - calibrateTimer(); - print_overhead(); - - memset(key, 0, 10); - memset(data, 0, 8); - - startTimer(1); - skipjack_enc(data, key); - t = stopTimer(); - uart_putstr_P(PSTR("\r\n\tencrypt time: ")); - ultoa((unsigned long)t, str, 10); - uart_putstr(str); - - - startTimer(1); - skipjack_dec(data, key); - 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")); -} - -/***************************************************************************** - * self tests * - *****************************************************************************/ - -void testencrypt(uint8_t* block, uint8_t* key){ - uart_putstr("\r\n==testy-encrypt==\r\n key: "); - uart_hexdump(key,10); - uart_putstr("\r\n plain: "); - uart_hexdump(block,8); - skipjack_enc(block,key); - uart_putstr("\r\n crypt: "); - uart_hexdump(block,8); -} - -void testdecrypt(uint8_t* block, uint8_t* key){ - uart_putstr("\r\n==testy-decrypt==\r\n key: "); - uart_hexdump(key,10); - uart_putstr("\r\n crypt: "); - uart_hexdump(block,8); - skipjack_dec(block,key); - uart_putstr("\r\n plain: "); - uart_hexdump(block,8); -} - -void testrun_skipjack(void){ - uint8_t key[]={ 0x00, 0x99, 0x88, 0x77, 0x66, - 0x55, 0x44, 0x33, 0x22, 0x11}; - uint8_t data[]={ 0x33, 0x22, 0x11, 0x00, 0xdd, 0xcc, 0xbb, 0xaa}; - testencrypt(data,key); - testdecrypt(data,key); -} - - - -/***************************************************************************** - * main * - *****************************************************************************/ - -int main (void){ - char str[20]; - - DEBUG_INIT(); - uart_putstr("\r\n"); - - uart_putstr("\r\n\r\nCrypto-VS (skipjack)\r\nloaded and running\r\n"); - - PGM_P u = PSTR("nessie\0test\0performance\0"); - void_fpt v[] = {testrun_nessie_skipjack, testrun_skipjack, testrun_performance_skipjack}; - - while(1){ - 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"); - } - -} - diff --git a/main-tdes-test.c b/main-tdes-test.c deleted file mode 100644 index d5ae1a0..0000000 --- a/main-tdes-test.c +++ /dev/null @@ -1,123 +0,0 @@ -/* main-tdes-test.c */ -/* - This file is part of the Crypto-avr-lib/microcrypt-lib. - Copyright (C) 2008 Daniel Otte (daniel.otte@rub.de) - - This program is free software: you can redistribute it and/or modify - it under the terms of the GNU General Public License as published by - the Free Software Foundation, either version 3 of the License, or - (at your option) any later version. - - This program is distributed in the hope that it will be useful, - but WITHOUT ANY WARRANTY; without even the implied warranty of - MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the - GNU General Public License for more details. - - You should have received a copy of the GNU General Public License - along with this program. If not, see . -*/ -/* - * tdes test-suit - * -*/ - -#include "config.h" -#include "serial-tools.h" -#include "uart.h" -#include "debug.h" - -#include "des.h" -#include "nessie_bc_test.h" -#include "cli.h" -#include "performance_test.h" - -#include -#include -#include - -char* cipher_name = "TDES"; - -/***************************************************************************** - * additional validation-functions * - *****************************************************************************/ -void tdes_init_dummy(const void* key, uint16_t keysize_b, void* ctx){ - memcpy(ctx, key, 8*3); -} - -void tdes_enc_dummy(void* buffer, void* ctx){ - tdes_enc(buffer, buffer, ctx); -} - -void tdes_dec_dummy(void* buffer, void* ctx){ - tdes_dec(buffer, buffer, ctx); -} - -void testrun_nessie_tdes(void){ - nessie_bc_init(); - nessie_bc_ctx.blocksize_B = 8; - nessie_bc_ctx.keysize_b = 192; - nessie_bc_ctx.name = cipher_name; - nessie_bc_ctx.ctx_size_B = sizeof(8*3); - nessie_bc_ctx.cipher_enc = (nessie_bc_enc_fpt)tdes_enc_dummy; - nessie_bc_ctx.cipher_dec = (nessie_bc_dec_fpt)tdes_dec_dummy; - nessie_bc_ctx.cipher_genctx = (nessie_bc_gen_fpt)tdes_init_dummy; - - nessie_bc_run(); -} - - -void testrun_performance_tdes(void){ - uint64_t t; - char str[16]; - uint8_t key[8*3], data[8]; - - - calibrateTimer(); - print_overhead(); - - memset(key, 0, 8*3); - memset(data, 0, 8); - - startTimer(1); - tdes_enc(data, data, key); - t = stopTimer(); - uart_putstr_P(PSTR("\r\n\tencrypt time: ")); - ultoa((unsigned long)t, str, 10); - uart_putstr(str); - - startTimer(1); - tdes_dec(data, data, key); - 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 * - *****************************************************************************/ - -int main (void){ - char str[20]; - DEBUG_INIT(); - uart_putstr("\r\n"); - - 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[] = {testrun_nessie_tdes, testrun_nessie_tdes, testrun_performance_tdes}; - - while(1){ - 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"); - } - -} - diff --git a/main-trivium-test.c b/main-trivium-test.c deleted file mode 100644 index 4d4e3d2..0000000 --- a/main-trivium-test.c +++ /dev/null @@ -1,123 +0,0 @@ -/* main-trivium-test.c */ -/* - This file is part of the Crypto-avr-lib/microcrypt-lib. - Copyright (C) 2008 Daniel Otte (daniel.otte@rub.de) - - This program is free software: you can redistribute it and/or modify - it under the terms of the GNU General Public License as published by - the Free Software Foundation, either version 3 of the License, or - (at your option) any later version. - - This program is distributed in the hope that it will be useful, - but WITHOUT ANY WARRANTY; without even the implied warranty of - MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the - GNU General Public License for more details. - - You should have received a copy of the GNU General Public License - along with this program. If not, see . -*/ -/* - * Mickey128 test-suit - * -*/ - -#include "config.h" -#include "serial-tools.h" -#include "uart.h" -#include "debug.h" -#include "cli.h" - -#include "trivium.h" -#include "nessie_stream_test.h" -#include "performance_test.h" - -#include -#include -#include - -char* cipher_name = "Trivium"; - -/***************************************************************************** - * additional validation-functions * - *****************************************************************************/ -void trivium_genctx_dummy(uint8_t* key, uint16_t keysize_b, void* ctx){ - uint32_t iv=0; - trivium_init(key, 80, &iv, 32, ctx); -} - -uint8_t trivium_getbyte_dummy(trivium_ctx_t* ctx){ - uint8_t i,ret=0; - for(i=0; i<8; ++i){ - ret<<=1; - ret |= trivium_enc(ctx); - } - return ret; -} - -void testrun_nessie_trivium(void){ - nessie_stream_ctx.outsize_b = 8; /* actually unused */ - nessie_stream_ctx.keysize_b = 80; /* this is the one we have refrence vectors for */ - nessie_stream_ctx.ivsize_b = 32; - nessie_stream_ctx.name = cipher_name; - nessie_stream_ctx.ctx_size_B = sizeof(trivium_ctx_t); - nessie_stream_ctx.cipher_genctx = (nessie_stream_genctx_fpt)trivium_genctx_dummy; - nessie_stream_ctx.cipher_enc = (nessie_stream_genenc_fpt)trivium_getbyte_dummy; - - nessie_stream_run(); -} - -void testrun_performance_trivium(void){ - uint64_t t; - char str[16]; - uint8_t key[10], iv[10]; - trivium_ctx_t ctx; - - calibrateTimer(); - print_overhead(); - - memset(key, 0, 10); - memset(iv, 0, 10); - - startTimer(1); - trivium_init(key, 80, iv, 80, &ctx); - t = stopTimer(); - uart_putstr_P(PSTR("\r\n\tctx-gen time: ")); - ultoa((unsigned long)t, str, 10); - uart_putstr(str); - - startTimer(1); - trivium_enc(&ctx); - t = stopTimer(); - uart_putstr_P(PSTR("\r\n\tencrypt time: ")); - ultoa((unsigned long)t, str, 10); - uart_putstr(str); - - uart_putstr_P(PSTR("\r\n")); -} - -/***************************************************************************** - * main * - *****************************************************************************/ - -int main (void){ - char str[20]; - DEBUG_INIT(); - uart_putstr("\r\n"); - - 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[] = {testrun_nessie_trivium, testrun_nessie_trivium, testrun_performance_trivium}; - - while(1){ - 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"); - } -} diff --git a/main-xtea-test.c b/main-xtea-test.c deleted file mode 100644 index 07fcffe..0000000 --- a/main-xtea-test.c +++ /dev/null @@ -1,111 +0,0 @@ -/* main-xtea-test.c */ -/* - This file is part of the Crypto-avr-lib/microcrypt-lib. - Copyright (C) 2008 Daniel Otte (daniel.otte@rub.de) - - This program is free software: you can redistribute it and/or modify - it under the terms of the GNU General Public License as published by - the Free Software Foundation, either version 3 of the License, or - (at your option) any later version. - - This program is distributed in the hope that it will be useful, - but WITHOUT ANY WARRANTY; without even the implied warranty of - MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the - GNU General Public License for more details. - - You should have received a copy of the GNU General Public License - along with this program. If not, see . -*/ -/* - * XTEA test-suit - * -*/ - -#include "config.h" -#include "serial-tools.h" -#include "uart.h" -#include "debug.h" - -#include "xtea.h" -#include "nessie_bc_test.h" -#include "performance_test.h" -#include "cli.h" - -#include -#include - -char* cipher_name = "XTEA"; - -void xtea_genctx_dummy(uint8_t* key, uint16_t keysize, void* ctx){ - memcpy(ctx, key, (keysize+7)/8); -} - -void xtea_enc_dummy(uint8_t* buffer, void* ctx){ - xtea_enc((uint32_t*)buffer, (uint32_t*)buffer, ctx); -} - -void xtea_dec_dummy(uint8_t* buffer, void* ctx){ - xtea_dec((uint32_t*)buffer, (uint32_t*)buffer, ctx); -} - -void testrun_nessie_xtea(void){ - nessie_bc_ctx.blocksize_B = 8; - nessie_bc_ctx.keysize_b = 128; - nessie_bc_ctx.name = cipher_name; - nessie_bc_ctx.ctx_size_B = 128/8; - nessie_bc_ctx.cipher_enc = (nessie_bc_enc_fpt)xtea_enc_dummy; - nessie_bc_ctx.cipher_dec = (nessie_bc_dec_fpt)xtea_dec_dummy; - nessie_bc_ctx.cipher_genctx = (nessie_bc_gen_fpt)xtea_genctx_dummy; - - 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 * - *****************************************************************************/ - -int main (void){ - char str[20]; - DEBUG_INIT(); - uart_putstr("\r\n"); - - 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[] = {testrun_nessie_xtea, testrun_nessie_xtea, testrun_performance_xtea}; - - while(1){ - 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"); - } -} diff --git a/mkfiles/a5_1.mk b/mkfiles/a5_1.mk index 6d89b62..e4264be 100644 --- a/mkfiles/a5_1.mk +++ b/mkfiles/a5_1.mk @@ -6,7 +6,7 @@ STREAM_CIPHERS += $(ALGO_NAME) $(ALGO_NAME)_OBJ := A5_1.o $(ALGO_NAME)_TEST_BIN := main-a5_1-test.o debug.o uart.o serial-tools.o \ - nessie_stream_test.o nessie_common.o A5_1.o + nessie_stream_test.o nessie_common.o $(ALGO_NAME)_NESSIE_TEST := "nessie" $(ALGO_NAME)_PEROFRMANCE_TEST := "performance" diff --git a/mkfiles/arcfour.mk b/mkfiles/arcfour.mk index a05f236..f5b4089 100644 --- a/mkfiles/arcfour.mk +++ b/mkfiles/arcfour.mk @@ -6,7 +6,7 @@ STREAM_CIPHERS += $(ALGO_NAME) $(ALGO_NAME)_OBJ := arcfour-asm.o $(ALGO_NAME)_TEST_BIN := main-arcfour-test.o debug.o uart.o serial-tools.o \ - nessie_stream_test.o nessie_common.o arcfour-asm.o + nessie_stream_test.o nessie_common.o $(ALGO_NAME)_NESSIE_TEST := "nessie" $(ALGO_NAME)_PEROFRMANCE_TEST := "performance" diff --git a/mkfiles/arcfour_c.mk b/mkfiles/arcfour_c.mk index 8e70754..21061a5 100644 --- a/mkfiles/arcfour_c.mk +++ b/mkfiles/arcfour_c.mk @@ -6,7 +6,7 @@ STREAM_CIPHERS += $(ALGO_NAME) $(ALGO_NAME)_OBJ := arcfour.o $(ALGO_NAME)_TEST_BIN := main-arcfour-test.o debug.o uart.o serial-tools.o \ - nessie_stream_test.o nessie_common.o arcfour.o + nessie_stream_test.o nessie_common.o $(ALGO_NAME)_NESSIE_TEST := "nessie" $(ALGO_NAME)_PEROFRMANCE_TEST := "performance" diff --git a/mkfiles/camellia.mk b/mkfiles/camellia.mk index a34d538..1e304a9 100644 --- a/mkfiles/camellia.mk +++ b/mkfiles/camellia.mk @@ -1,13 +1,12 @@ # Makefile for camellia ALGO_NAME := CAMELLIA -# comment out the following line for removement of serpent from the build process +# comment out the following line for removement of Camellia from the build process BLOCK_CIPHERS += $(ALGO_NAME) -# main-camellia-test.o debug.o uart.o serial-tools.o camellia.o camellia-asm.o $(ALGO_NAME)_OBJ := camellia.o camellia-asm.o $(ALGO_NAME)_TEST_BIN := main-camellia-test.o debug.o uart.o serial-tools.o \ - camellia.o camellia-asm.o nessie_bc_test.o \ + nessie_bc_test.o \ nessie_common.o cli.o performance_test.o $(ALGO_NAME)_NESSIE_TEST := "nessie" $(ALGO_NAME)_PEROFRMANCE_TEST := "performance" diff --git a/mkfiles/cast5.mk b/mkfiles/cast5.mk index b2b671b..33c32ba 100644 --- a/mkfiles/cast5.mk +++ b/mkfiles/cast5.mk @@ -6,7 +6,7 @@ BLOCK_CIPHERS += $(ALGO_NAME) $(ALGO_NAME)_OBJ := cast5.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 + nessie_bc_test.o nessie_common.o performance_test.o $(ALGO_NAME)_NESSIE_TEST := "nessie" $(ALGO_NAME)_PEROFRMANCE_TEST := "performance" diff --git a/mkfiles/des.mk b/mkfiles/des.mk index 2cc8d7c..15c16ec 100644 --- a/mkfiles/des.mk +++ b/mkfiles/des.mk @@ -5,7 +5,7 @@ ALGO_NAME := DES BLOCK_CIPHERS += $(ALGO_NAME) $(ALGO_NAME)_OBJ := des.o -$(ALGO_NAME)_TEST_BIN := main-des-test.o debug.o uart.o serial-tools.o des.o \ +$(ALGO_NAME)_TEST_BIN := main-des-test.o debug.o uart.o serial-tools.o \ nessie_bc_test.o nessie_common.o cli.o performance_test.o $(ALGO_NAME)_NESSIE_TEST := "nessie" $(ALGO_NAME)_PEROFRMANCE_TEST := "performance" diff --git a/mkfiles/entropium.mk b/mkfiles/entropium.mk index 589ff6f..e5806c3 100644 --- a/mkfiles/entropium.mk +++ b/mkfiles/entropium.mk @@ -6,7 +6,7 @@ PRNGS += $(ALGO_NAME) $(ALGO_NAME)_OBJ := entropium.o sha256-asm.o $(ALGO_NAME)_TEST_BIN := main-entropium-test.o debug.o uart.o serial-tools.o \ - sha256-asm.o entropium.o cli.o performance_test.o + cli.o performance_test.o $(ALGO_NAME)_NESSIE_TEST := "nessie" $(ALGO_NAME)_PEROFRMANCE_TEST := "performance" diff --git a/mkfiles/grain.mk b/mkfiles/grain.mk index ed330a6..4f026a9 100644 --- a/mkfiles/grain.mk +++ b/mkfiles/grain.mk @@ -6,8 +6,8 @@ STREAM_CIPHERS += $(ALGO_NAME) $(ALGO_NAME)_OBJ := grain.o $(ALGO_NAME)_TEST_BIN := main-grain-test.o debug.o uart.o serial-tools.o \ - nessie_stream_test.o nessie_common.o grain.o cli.o \ - performance_test.o + nessie_stream_test.o nessie_common.o cli.o \ + performance_test.o $(ALGO_NAME)_NESSIE_TEST := "nessie" $(ALGO_NAME)_PEROFRMANCE_TEST := "performance" diff --git a/mkfiles/hmac-sha1.mk b/mkfiles/hmac-sha1.mk index 8d5c90a..b63308f 100644 --- a/mkfiles/hmac-sha1.mk +++ b/mkfiles/hmac-sha1.mk @@ -6,7 +6,7 @@ MACS += $(ALGO_NAME) $(ALGO_NAME)_OBJ := hmac-sha1.o sha1-asm.o $(ALGO_NAME)_TEST_BIN := main-hmac-sha1-test.o debug.o uart.o serial-tools.o cli.o \ - hmac-sha1.o sha1-asm.o nessie_mac_test.o nessie_common.o + nessie_mac_test.o nessie_common.o $(ALGO_NAME)_NESSIE_TEST := "nessie" $(ALGO_NAME)_PEROFRMANCE_TEST := "performance" diff --git a/mkfiles/hmac-sha256.mk b/mkfiles/hmac-sha256.mk index 6d957b3..fe14892 100644 --- a/mkfiles/hmac-sha256.mk +++ b/mkfiles/hmac-sha256.mk @@ -6,7 +6,7 @@ MACS += $(ALGO_NAME) $(ALGO_NAME)_OBJ := hmac-sha256.o sha256-asm.o $(ALGO_NAME)_TEST_BIN := main-hmac-sha256-test.o debug.o uart.o serial-tools.o \ - hmac-sha256.o sha256-asm.o nessie_mac_test.o nessie_common.o + nessie_mac_test.o nessie_common.o $(ALGO_NAME)_NESSIE_TEST := "nessie" $(ALGO_NAME)_PEROFRMANCE_TEST := "performance" diff --git a/mkfiles/md5.mk b/mkfiles/md5.mk index b3d3de0..3fb9d65 100644 --- a/mkfiles/md5.mk +++ b/mkfiles/md5.mk @@ -5,7 +5,7 @@ ALGO_NAME := MD5 HASHES += $(ALGO_NAME) $(ALGO_NAME)_OBJ := md5.o -$(ALGO_NAME)_TEST_BIN := main-md5-test.o debug.o uart.o serial-tools.o md5.o \ +$(ALGO_NAME)_TEST_BIN := main-md5-test.o debug.o uart.o serial-tools.o \ nessie_hash_test.o nessie_common.o cli.o performance_test.o $(ALGO_NAME)_NESSIE_TEST := "nessie" $(ALGO_NAME)_PEROFRMANCE_TEST := "performance" diff --git a/mkfiles/noekeon.mk b/mkfiles/noekeon.mk index 3f1a313..359aef3 100644 --- a/mkfiles/noekeon.mk +++ b/mkfiles/noekeon.mk @@ -7,8 +7,7 @@ BLOCK_CIPHERS += $(ALGO_NAME) $(ALGO_NAME)_OBJ := noekeon_asm.o $(ALGO_NAME)_TEST_BIN := main-noekeon-test.o debug.o uart.o serial-tools.o \ - noekeon_asm.o nessie_bc_test.o \ - nessie_common.o cli.o performance_test.o + nessie_bc_test.o nessie_common.o cli.o performance_test.o $(ALGO_NAME)_NESSIE_TEST := test nessie $(ALGO_NAME)_PEROFRMANCE_TEST := performance diff --git a/mkfiles/noekeon_c.mk b/mkfiles/noekeon_c.mk index 48571d0..90d378d 100644 --- a/mkfiles/noekeon_c.mk +++ b/mkfiles/noekeon_c.mk @@ -7,8 +7,7 @@ BLOCK_CIPHERS += $(ALGO_NAME) $(ALGO_NAME)_OBJ := noekeon.o $(ALGO_NAME)_TEST_BIN := main-noekeon-test.o debug.o uart.o serial-tools.o \ - noekeon.o nessie_bc_test.o \ - nessie_common.o cli.o performance_test.o + nessie_bc_test.o nessie_common.o cli.o performance_test.o $(ALGO_NAME)_NESSIE_TEST := test nessie $(ALGO_NAME)_PEROFRMANCE_TEST := performance diff --git a/mkfiles/present.mk b/mkfiles/present.mk index 764acef..e30c506 100644 --- a/mkfiles/present.mk +++ b/mkfiles/present.mk @@ -7,8 +7,7 @@ BLOCK_CIPHERS += $(ALGO_NAME) $(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 \ - performance_test.o + nessie_bc_test.o nessie_common.o cli.o performance_test.o $(ALGO_NAME)_NESSIE_TEST := "nessie" $(ALGO_NAME)_PEROFRMANCE_TEST := "performance" diff --git a/mkfiles/rc5.mk b/mkfiles/rc5.mk index b45a610..ff20873 100644 --- a/mkfiles/rc5.mk +++ b/mkfiles/rc5.mk @@ -7,7 +7,7 @@ BLOCK_CIPHERS += $(ALGO_NAME) $(ALGO_NAME)_OBJ := rc5.o $(ALGO_NAME)_TEST_BIN := main-rc5-test.o debug.o uart.o serial-tools.o \ - rc5.o nessie_bc_test.o \ + nessie_bc_test.o \ nessie_common.o cli.o performance_test.o $(ALGO_NAME)_NESSIE_TEST := test nessie $(ALGO_NAME)_PEROFRMANCE_TEST := performance diff --git a/mkfiles/rc6.mk b/mkfiles/rc6.mk index 893b34f..47e2f00 100644 --- a/mkfiles/rc6.mk +++ b/mkfiles/rc6.mk @@ -7,8 +7,7 @@ BLOCK_CIPHERS += $(ALGO_NAME) $(ALGO_NAME)_OBJ := rc6.o $(ALGO_NAME)_TEST_BIN := main-rc6-test.o debug.o uart.o serial-tools.o \ - rc6.o nessie_bc_test.o \ - nessie_common.o cli.o performance_test.o + nessie_bc_test.o nessie_common.o cli.o performance_test.o $(ALGO_NAME)_NESSIE_TEST := test nessie $(ALGO_NAME)_PEROFRMANCE_TEST := performance diff --git a/mkfiles/seed.mk b/mkfiles/seed.mk index 515597c..35724f2 100644 --- a/mkfiles/seed.mk +++ b/mkfiles/seed.mk @@ -6,7 +6,7 @@ BLOCK_CIPHERS += $(ALGO_NAME) $(ALGO_NAME)_OBJ := seed.o seed-asm.o $(ALGO_NAME)_TEST_BIN := main-seed-test.o debug.o uart.o serial-tools.o \ - seed.o seed-asm.o nessie_bc_test.o nessie_common.o \ + nessie_bc_test.o nessie_common.o \ cli.o performance_test.o $(ALGO_NAME)_NESSIE_TEST := "nessie" $(ALGO_NAME)_PEROFRMANCE_TEST := "performance" diff --git a/mkfiles/serpent-bitslice.mk b/mkfiles/serpent-bitslice.mk index 5ddb0c4..e17ab28 100644 --- a/mkfiles/serpent-bitslice.mk +++ b/mkfiles/serpent-bitslice.mk @@ -5,10 +5,9 @@ ALGO_NAME := SERPENT_BITSLICE BLOCK_CIPHERS += $(ALGO_NAME) -$(ALGO_NAME)_OBJ := serpent.o serpent-sboxes-bitslice.o +$(ALGO_NAME)_OBJ := serpent.o serpent-sboxes-bitslice.o memxor.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 performance_test.o + nessie_bc_test.o nessie_common.o cli.o performance_test.o $(ALGO_NAME)_NESSIE_TEST := "nessie" $(ALGO_NAME)_PEROFRMANCE_TEST := "performance" diff --git a/mkfiles/serpent.mk b/mkfiles/serpent.mk index 03dad5b..5959aea 100644 --- a/mkfiles/serpent.mk +++ b/mkfiles/serpent.mk @@ -5,10 +5,9 @@ ALGO_NAME := SERPENT BLOCK_CIPHERS += $(ALGO_NAME) -$(ALGO_NAME)_OBJ := serpent.o serpent-sboxes.o +$(ALGO_NAME)_OBJ := serpent.o serpent-sboxes.o memxor.o $(ALGO_NAME)_TEST_BIN := main-serpent-test.o debug.o uart.o serial-tools.o \ - serpent.o serpent-sboxes.o nessie_bc_test.o \ - nessie_common.o cli.o performance_test.o + nessie_bc_test.o nessie_common.o cli.o performance_test.o $(ALGO_NAME)_NESSIE_TEST := "nessie" $(ALGO_NAME)_PEROFRMANCE_TEST := "performance" diff --git a/mkfiles/sha1.mk b/mkfiles/sha1.mk index dc2eade..eb2d919 100644 --- a/mkfiles/sha1.mk +++ b/mkfiles/sha1.mk @@ -6,8 +6,7 @@ HASHES += $(ALGO_NAME) $(ALGO_NAME)_OBJ := sha1-asm.o $(ALGO_NAME)_TEST_BIN := main-sha1-test.o debug.o uart.o serial-tools.o \ - sha1-asm.o nessie_hash_test.o nessie_common.o cli.o \ - performance_test.o + nessie_hash_test.o nessie_common.o cli.o performance_test.o $(ALGO_NAME)_NESSIE_TEST := "nessie" $(ALGO_NAME)_PEROFRMANCE_TEST := "performance" diff --git a/mkfiles/sha1_c.mk b/mkfiles/sha1_c.mk index bdfedf7..061f7a9 100644 --- a/mkfiles/sha1_c.mk +++ b/mkfiles/sha1_c.mk @@ -6,7 +6,7 @@ HASHES += $(ALGO_NAME) $(ALGO_NAME)_OBJ := sha1.o $(ALGO_NAME)_TEST_BIN := main-sha1-test.o debug.o uart.o serial-tools.o \ - sha1.o nessie_hash_test.o nessie_common.o cli.o \ + nessie_hash_test.o nessie_common.o cli.o \ performance_test.o $(ALGO_NAME)_NESSIE_TEST := "nessie" $(ALGO_NAME)_PEROFRMANCE_TEST := "performance" diff --git a/mkfiles/sha256.mk b/mkfiles/sha256.mk index 0a2fe1c..dcea21f 100644 --- a/mkfiles/sha256.mk +++ b/mkfiles/sha256.mk @@ -6,8 +6,7 @@ HASHES += $(ALGO_NAME) $(ALGO_NAME)_OBJ := sha256-asm.o $(ALGO_NAME)_TEST_BIN := main-sha256-test.o debug.o uart.o serial-tools.o \ - sha256-asm.o nessie_hash_test.o nessie_common.o cli.o \ - performance_test.o + nessie_hash_test.o nessie_common.o cli.o performance_test.o $(ALGO_NAME)_NESSIE_TEST := "nessie" $(ALGO_NAME)_PEROFRMANCE_TEST := "performance" diff --git a/mkfiles/sha256_c.mk b/mkfiles/sha256_c.mk index 8175ddc..cf850fc 100644 --- a/mkfiles/sha256_c.mk +++ b/mkfiles/sha256_c.mk @@ -6,8 +6,7 @@ HASHES += $(ALGO_NAME) $(ALGO_NAME)_OBJ := sha256.o $(ALGO_NAME)_TEST_BIN := main-sha256-test.o debug.o uart.o serial-tools.o \ - sha256.o nessie_hash_test.o nessie_common.o cli.o \ - performance_test.o + nessie_hash_test.o nessie_common.o cli.o performance_test.o $(ALGO_NAME)_NESSIE_TEST := "nessie" $(ALGO_NAME)_PEROFRMANCE_TEST := "performance" diff --git a/mkfiles/shabea.mk b/mkfiles/shabea.mk index ee749ff..4e9acaf 100644 --- a/mkfiles/shabea.mk +++ b/mkfiles/shabea.mk @@ -4,10 +4,9 @@ ALGO_NAME := SHABEA # comment out the following line for removement of SHABEA from the build process BLOCK_CIPHERS += $(ALGO_NAME) -$(ALGO_NAME)_OBJ := shabea.o sha256-asm.o +$(ALGO_NAME)_OBJ := shabea.o sha256-asm.o memxor.o $(ALGO_NAME)_TEST_BIN := main-shabea-test.o debug.o uart.o serial-tools.o \ - shabea.o sha256-asm.o nessie_bc_test.o \ - nessie_common.o cli.o performance_test.o memxor.o + nessie_bc_test.o nessie_common.o cli.o performance_test.o $(ALGO_NAME)_NESSIE_TEST := "nessie" $(ALGO_NAME)_PEROFRMANCE_TEST := "performance" diff --git a/mkfiles/shacal1enc.mk b/mkfiles/shacal1enc.mk index 1e19794..d329db7 100644 --- a/mkfiles/shacal1enc.mk +++ b/mkfiles/shacal1enc.mk @@ -7,8 +7,7 @@ BLOCK_CIPHERS += $(ALGO_NAME) $(ALGO_NAME)_OBJ := shacal1_enc.o sha1-asm.o $(ALGO_NAME)_TEST_BIN := main-shacal1_enc-test.o debug.o uart.o serial-tools.o \ - nessie_bc_test.o nessie_common.o cli.o \ - performance_test.o shacal1_enc.o sha1-asm.o + nessie_bc_test.o nessie_common.o cli.o performance_test.o $(ALGO_NAME)_NESSIE_TEST := "nessie" $(ALGO_NAME)_PEROFRMANCE_TEST := "performance" diff --git a/mkfiles/shacal2enc.mk b/mkfiles/shacal2enc.mk index 44ba529..739d9eb 100644 --- a/mkfiles/shacal2enc.mk +++ b/mkfiles/shacal2enc.mk @@ -7,8 +7,7 @@ BLOCK_CIPHERS += $(ALGO_NAME) $(ALGO_NAME)_OBJ := shacal2_enc.o sha256-asm.o $(ALGO_NAME)_TEST_BIN := main-shacal2_enc-test.o debug.o uart.o serial-tools.o \ - nessie_bc_test.o nessie_common.o cli.o \ - performance_test.o shacal2_enc.o sha256-asm.o + nessie_bc_test.o nessie_common.o cli.o performance_test.o $(ALGO_NAME)_NESSIE_TEST := "nessie" $(ALGO_NAME)_PEROFRMANCE_TEST := "performance" diff --git a/mkfiles/skipjack.mk b/mkfiles/skipjack.mk index 2a117a9..e48d8b9 100644 --- a/mkfiles/skipjack.mk +++ b/mkfiles/skipjack.mk @@ -6,7 +6,7 @@ BLOCK_CIPHERS += $(ALGO_NAME) $(ALGO_NAME)_OBJ := skipjack.o $(ALGO_NAME)_TEST_BIN := main-skipjack-test.o debug.o uart.o serial-tools.o \ - skipjack.o nessie_bc_test.o nessie_common.o cli.o \ + nessie_bc_test.o nessie_common.o cli.o \ performance_test.o $(ALGO_NAME)_NESSIE_TEST := "nessie" $(ALGO_NAME)_PEROFRMANCE_TEST := "performance" diff --git a/mkfiles/tdes.mk b/mkfiles/tdes.mk index 66b5168..f0b43e5 100644 --- a/mkfiles/tdes.mk +++ b/mkfiles/tdes.mk @@ -5,7 +5,7 @@ ALGO_NAME := TDES BLOCK_CIPHERS += $(ALGO_NAME) $(ALGO_NAME)_OBJ := des.o -$(ALGO_NAME)_TEST_BIN := main-tdes-test.o debug.o uart.o serial-tools.o des.o \ +$(ALGO_NAME)_TEST_BIN := main-tdes-test.o debug.o uart.o serial-tools.o \ nessie_bc_test.o nessie_common.o cli.o performance_test.o $(ALGO_NAME)_NESSIE_TEST := "nessie" $(ALGO_NAME)_PEROFRMANCE_TEST := "performance" diff --git a/mkfiles/trivium.mk b/mkfiles/trivium.mk index e2e3484..45ee4f3 100644 --- a/mkfiles/trivium.mk +++ b/mkfiles/trivium.mk @@ -6,8 +6,8 @@ STREAM_CIPHERS += $(ALGO_NAME) $(ALGO_NAME)_OBJ := trivium.o $(ALGO_NAME)_TEST_BIN := main-trivium-test.o debug.o uart.o serial-tools.o \ - nessie_stream_test.o nessie_common.o trivium.o cli.o \ - performance_test.o + nessie_stream_test.o nessie_common.o cli.o \ + performance_test.o $(ALGO_NAME)_NESSIE_TEST := "nessie" $(ALGO_NAME)_PEROFRMANCE_TEST := "performance" diff --git a/mkfiles/xtea.mk b/mkfiles/xtea.mk index 38f485b..b4edc30 100644 --- a/mkfiles/xtea.mk +++ b/mkfiles/xtea.mk @@ -6,8 +6,7 @@ BLOCK_CIPHERS += $(ALGO_NAME) $(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 \ - cli.o performance_test.o + nessie_bc_test.o nessie_common.o cli.o performance_test.o $(ALGO_NAME)_NESSIE_TEST := "nessie" $(ALGO_NAME)_PEROFRMANCE_TEST := "performance" diff --git a/mkfiles/xtea_c.mk b/mkfiles/xtea_c.mk index 157df87..7ebbded 100644 --- a/mkfiles/xtea_c.mk +++ b/mkfiles/xtea_c.mk @@ -6,8 +6,7 @@ BLOCK_CIPHERS += $(ALGO_NAME) $(ALGO_NAME)_OBJ := xtea.o $(ALGO_NAME)_TEST_BIN := main-xtea-test.o debug.o uart.o serial-tools.o \ - xtea.o nessie_bc_test.o nessie_common.o \ - cli.o performance_test.o + nessie_bc_test.o nessie_common.o cli.o performance_test.o $(ALGO_NAME)_NESSIE_TEST := "nessie" $(ALGO_NAME)_PEROFRMANCE_TEST := "performance" diff --git a/nessie_bc_test.c b/nessie_bc_test.c deleted file mode 100644 index f9a91e5..0000000 --- a/nessie_bc_test.c +++ /dev/null @@ -1,212 +0,0 @@ -/* nessie_bc_test.c */ -/* - This file is part of the Crypto-avr-lib/microcrypt-lib. - Copyright (C) 2008 Daniel Otte (daniel.otte@rub.de) - - This program is free software: you can redistribute it and/or modify - it under the terms of the GNU General Public License as published by - the Free Software Foundation, either version 3 of the License, or - (at your option) any later version. - - This program is distributed in the hope that it will be useful, - but WITHOUT ANY WARRANTY; without even the implied warranty of - MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the - GNU General Public License for more details. - - You should have received a copy of the GNU General Public License - along with this program. If not, see . -*/ -/** - * - * author: Daniel Otte - * email: daniel.otte@rub.de - * license: GPLv3 - * - * a suit for running the nessie-tests for blockciphers - * - * */ -#include -#include -#include "nessie_bc_test.h" -#include "nessie_common.h" -#include "uart.h" - -nessie_bc_ctx_t nessie_bc_ctx; - -void nessie_bc_init(void){ - memset(&nessie_bc_ctx, 0, sizeof(nessie_bc_ctx_t)); -} -static -void nessie_bc_free(void* ctx){ - if(nessie_bc_ctx.cipher_free) - nessie_bc_ctx.cipher_free(ctx); -} - -void nessie_bc_enc(uint8_t* key, uint8_t* pt){ - uint8_t ctx[nessie_bc_ctx.ctx_size_B]; - uint8_t buffer[nessie_bc_ctx.blocksize_B]; - uint16_t i; - - /* single test */ - nessie_print_item("key", key, (nessie_bc_ctx.keysize_b+7)/8); - nessie_bc_ctx.cipher_genctx(key, nessie_bc_ctx.keysize_b, ctx); - - memcpy(buffer, pt, nessie_bc_ctx.blocksize_B); - nessie_print_item("plain", buffer, nessie_bc_ctx.blocksize_B); - nessie_bc_ctx.cipher_enc(buffer, ctx); - nessie_print_item("cipher", buffer, nessie_bc_ctx.blocksize_B); - if(nessie_bc_ctx.cipher_dec){ - nessie_bc_ctx.cipher_dec(buffer, ctx); - nessie_print_item("decrypted", buffer, nessie_bc_ctx.blocksize_B); - } - /* 100 times test */ - memcpy(buffer, pt, nessie_bc_ctx.blocksize_B); - for(i=0; i<100; ++i){ - nessie_bc_ctx.cipher_enc(buffer, ctx); - } - nessie_print_item("Iterated 100 times", buffer, nessie_bc_ctx.blocksize_B); -#ifndef NESSIE_NO1KTEST - /* 1000 times test, we use the 100 precedig steps to fasten things a bit */ - for(; i<1000; ++i){ - nessie_bc_ctx.cipher_enc(buffer, ctx); - } - nessie_print_item("Iterated 1000 times", buffer, nessie_bc_ctx.blocksize_B); -#endif - nessie_bc_free(ctx); -} - -void nessie_bc_dec(uint8_t* key, uint8_t* ct){ - uint8_t ctx[nessie_bc_ctx.ctx_size_B]; - uint8_t buffer[nessie_bc_ctx.blocksize_B]; - - /* single test */ - nessie_print_item("key", key, (nessie_bc_ctx.keysize_b+7)/8); - nessie_bc_ctx.cipher_genctx(key, nessie_bc_ctx.keysize_b, ctx); - memcpy(buffer, ct, nessie_bc_ctx.blocksize_B); - nessie_print_item("cipher", buffer, nessie_bc_ctx.blocksize_B); - nessie_bc_ctx.cipher_dec(buffer, ctx); - nessie_print_item("plain", buffer, nessie_bc_ctx.blocksize_B); - nessie_bc_ctx.cipher_enc(buffer, ctx); - nessie_print_item("encrypted", buffer, nessie_bc_ctx.blocksize_B); - nessie_bc_free(ctx); -} - -void nessie_bc_run(void){ - uint16_t i; - uint8_t set; - uint8_t key[(nessie_bc_ctx.keysize_b+7)/8]; - uint8_t buffer[nessie_bc_ctx.blocksize_B]; - - nessie_print_header(nessie_bc_ctx.name, nessie_bc_ctx.keysize_b, - nessie_bc_ctx.blocksize_B*8, 0, 0, 0); - /* test set 1 */ - set=1; - nessie_print_setheader(set); - for(i=0; i>(i%8); - memset(buffer, 0, nessie_bc_ctx.blocksize_B); - nessie_bc_enc(key, buffer); - } - /* test set 2 */ - set=2; - nessie_print_setheader(set); - for(i=0; i>(i%8); - nessie_bc_enc(key, buffer); - } - /* test set 3 */ - set=3; - nessie_print_setheader(set); - for(i=0; i<256; ++i){ - nessie_print_set_vector(set, i); - memset(key, i, (nessie_bc_ctx.keysize_b+7)/8); - memset(buffer, i, nessie_bc_ctx.blocksize_B); - nessie_bc_enc(key, buffer); - } - /* test set 4 */ - set=4; - nessie_print_setheader(set); - /* 4 - 0*/ - nessie_print_set_vector(set, 0); - for(i=0; i<(nessie_bc_ctx.keysize_b+7)/8; ++i){ - key[i]=i; - } - for(i=0; i>(i%8); - memset(buffer, 0, nessie_bc_ctx.blocksize_B); - nessie_bc_dec(key, buffer); - } - /* test set 6 */ - set=6; - nessie_print_setheader(set); - for(i=0; i>(i%8); - nessie_bc_dec(key, buffer); - } - /* test set 7 */ - set=7; - nessie_print_setheader(set); - for(i=0; i<256; ++i){ - nessie_print_set_vector(set, i); - memset(key, i, (nessie_bc_ctx.keysize_b+7)/8); - memset(buffer, i, nessie_bc_ctx.blocksize_B); - nessie_bc_dec(key, buffer); - } - /* test set 8 */ - set=8; - nessie_print_setheader(set); - /* 8 - 0*/ - nessie_print_set_vector(set, 0); - for(i=0; i<(nessie_bc_ctx.keysize_b+7)/8; ++i){ - key[i]=i; - } - for(i=0; i. -*/ -#ifndef NESSIE_BC_TEST_H_ -#define NESSIE_BC_TEST_H_ - -#include - -typedef void (*nessie_bc_gen_fpt)(uint8_t* key, uint16_t keysize_b, void* ctx); -typedef void (*nessie_bc_free_fpt)(void* ctx); -typedef void (*nessie_bc_enc_fpt)(void* buffer, void* ctx); -typedef void (*nessie_bc_dec_fpt)(void* buffer, void* ctx); - -typedef struct nessie_bc_ctx_st{ - uint16_t keysize_b; - uint16_t blocksize_B; - uint16_t ctx_size_B; - char* name; - nessie_bc_gen_fpt cipher_genctx; - nessie_bc_free_fpt cipher_free; - nessie_bc_enc_fpt cipher_enc; - nessie_bc_dec_fpt cipher_dec; -} nessie_bc_ctx_t; - - -extern nessie_bc_ctx_t nessie_bc_ctx; - -void nessie_bc_run(void); -void nessie_bc_init(void); - - -#endif /*NESSIE_BC_TEST_H_*/ diff --git a/nessie_common.c b/nessie_common.c deleted file mode 100644 index 020d5ab..0000000 --- a/nessie_common.c +++ /dev/null @@ -1,178 +0,0 @@ -/* nessie_common.c */ -/* - This file is part of the Crypto-avr-lib/microcrypt-lib. - Copyright (C) 2008 Daniel Otte (daniel.otte@rub.de) - - This program is free software: you can redistribute it and/or modify - it under the terms of the GNU General Public License as published by - the Free Software Foundation, either version 3 of the License, or - (at your option) any later version. - - This program is distributed in the hope that it will be useful, - but WITHOUT ANY WARRANTY; without even the implied warranty of - MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the - GNU General Public License for more details. - - You should have received a copy of the GNU General Public License - along with this program. If not, see . -*/ -/** - * - * author: Daniel Otte - * email: daniel.otte@rub.de - * license: GPLv3 - * - * common function for nessie-tests - * - * */ - -#include -#include -#include -#include /* utoa() */ -#include "uart.h" - -void nessie_print_block(uint8_t* block, uint16_t blocksize_bit){ - char tab [] = {'0', '1', '2', '3', - '4', '5', '6', '7', - '8', '9', 'A', 'B', - 'C', 'D', 'E', 'F'}; - uint16_t i; - for(i=0; i<(blocksize_bit+7)/8; ++i){ - uart_putc(tab[(block[i])>>4]); - uart_putc(tab[(block[i])&0xf]); - } -} - -#define SPACES 31 -#define BYTESPERLINE 16 - -void nessie_print_item(char* name, uint8_t* buffer, uint16_t size_B){ - uint8_t name_len; - uint8_t i; - name_len=strlen(name); - if(name_len>SPACES-1){ - uart_putstr_P(PSTR("\r\n!!! formatting error !!!\r\n")); - return; - } - uart_putstr_P(PSTR("\r\n")); - for(i=0; iBYTESPERLINE)?BYTESPERLINE:toprint)*8); - buffer += BYTESPERLINE; - toprint -= BYTESPERLINE; - } - } -} - - -void nessie_print_set_vector(uint8_t set, uint16_t vector){ - uart_putstr_P(PSTR("\r\n\r\nSet ")); - uart_putc('0'+set%10); - uart_putstr_P(PSTR(", vector#")); - uart_putc((vector<100)?' ':'0'+vector/100); - uart_putc((vector<10 )?' ':'0'+(vector/10)%10); - uart_putc('0'+vector%10); - uart_putc(':'); -} - -/* example: -Test vectors -- set 3 -===================== - */ -void nessie_print_setheader(uint8_t set){ - uart_putstr_P(PSTR("\r\n\r\nTest vectors -- set ")); - uart_putc('0'+set%10); - uart_putstr_P(PSTR("\r\n=====================")); -} - -/* example: -******************************************************************************** -*Project NESSIE - New European Schemes for Signature, Integrity, and Encryption* -******************************************************************************** - -Primitive Name: Serpent -======================= -Key size: 256 bits -Block size: 128 bits -*/ - -void nessie_print_header(char* name, - uint16_t keysize_b, - uint16_t blocksize_b, - uint16_t hashsize_b, - uint16_t macsize_b, - uint16_t ivsize_b ){ - uint16_t i; - uart_putstr_P(PSTR("\r\n\r\n" - "********************************************************************************\r\n" - "* micro-crypt - crypto primitives for microcontrolles by Daniel Otte *\r\n" - "********************************************************************************\r\n" - "\r\n")); - uart_putstr_P(PSTR("Primitive Name: ")); - uart_putstr(name); - uart_putstr_P(PSTR("\r\n")); - /* underline */ - for(i=0; i<16+strlen(name); ++i){ - uart_putc('='); - } - char str[6]; /* must catch numbers up to 65535 + terminatin \0 */ - if(keysize_b){ - uart_putstr_P(PSTR("\r\nKey size: ")); - utoa(keysize_b, str, 10); - uart_putstr(str); - uart_putstr_P(PSTR(" bits")); - } - if(blocksize_b){ - uart_putstr_P(PSTR("\r\nBlock size: ")); - utoa(blocksize_b, str, 10); - uart_putstr(str); - uart_putstr_P(PSTR(" bits")); - } - if(hashsize_b){ - uart_putstr_P(PSTR("\r\nHash size: ")); - utoa(hashsize_b, str, 10); - uart_putstr(str); - uart_putstr_P(PSTR(" bits")); - } - if(macsize_b){ - uart_putstr_P(PSTR("\r\nMac size: ")); - utoa(macsize_b, str, 10); - uart_putstr(str); - uart_putstr_P(PSTR(" bits")); - } - if(ivsize_b){ - 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")); -} - -void nessie_print_footer(void){ - uart_putstr_P(PSTR("\r\n\r\n\r\n\r\nEnd of test vectors\r\n\r\n")); -} - diff --git a/nessie_common.h b/nessie_common.h deleted file mode 100644 index 4090e32..0000000 --- a/nessie_common.h +++ /dev/null @@ -1,47 +0,0 @@ -/* nessie_common.h */ -/* - This file is part of the Crypto-avr-lib/microcrypt-lib. - Copyright (C) 2008 Daniel Otte (daniel.otte@rub.de) - - This program is free software: you can redistribute it and/or modify - it under the terms of the GNU General Public License as published by - the Free Software Foundation, either version 3 of the License, or - (at your option) any later version. - - This program is distributed in the hope that it will be useful, - but WITHOUT ANY WARRANTY; without even the implied warranty of - MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the - GNU General Public License for more details. - - You should have received a copy of the GNU General Public License - along with this program. If not, see . -*/ -/** - * - * author: Daniel Otte - * email: daniel.otte@rub.de - * license: GPLv3 - * - * common function for nessie-tests - * - * */ - -#ifndef NESSIE_COMMON_H_ -#define NESSIE_COMMON_H_ - - -#include - -void nessie_print_block(uint8_t* block, uint16_t blocksize_bit); -void nessie_print_item(char* name, uint8_t* buffer, uint16_t size_B); -void nessie_print_set_vector(uint8_t set, uint16_t vector); -void nessie_print_setheader(uint8_t set); -void nessie_print_header(char* name, - uint16_t keysize_b, - uint16_t blocksize_b, - uint16_t hashsize_b, - uint16_t macsize_b, - uint16_t ivsize_b ); -void nessie_print_footer(void); - -#endif /*NESSIE_COMMON_H_*/ diff --git a/nessie_hash_test.c b/nessie_hash_test.c deleted file mode 100644 index a870b82..0000000 --- a/nessie_hash_test.c +++ /dev/null @@ -1,240 +0,0 @@ -/* nessie_hash_test.c */ -/* - This file is part of the Crypto-avr-lib/microcrypt-lib. - Copyright (C) 2008 Daniel Otte (daniel.otte@rub.de) - - This program is free software: you can redistribute it and/or modify - it under the terms of the GNU General Public License as published by - the Free Software Foundation, either version 3 of the License, or - (at your option) any later version. - - This program is distributed in the hope that it will be useful, - but WITHOUT ANY WARRANTY; without even the implied warranty of - MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the - GNU General Public License for more details. - - You should have received a copy of the GNU General Public License - along with this program. If not, see . -*/ -/** - * - * author: Daniel Otte - * email: daniel.otte@rub.de - * license: GPLv3 - * - * a suit for running the nessie-tests for hashes - * - * */ -#include -#include -#include "nessie_hash_test.h" -#include "nessie_common.h" -#include "uart.h" - -nessie_hash_ctx_t nessie_hash_ctx; - -static -void ascii_hash(char* data, char* desc){ - uint8_t ctx[nessie_hash_ctx.ctx_size_B]; - uint8_t hash[(nessie_hash_ctx.hashsize_b+7)/8]; - uint16_t sl; - - uart_putstr_P(PSTR("\r\n message=")); - uart_putstr(desc); - nessie_hash_ctx.hash_init(ctx); - sl = strlen(data); - while(sl>=nessie_hash_ctx.blocksize_B){ - nessie_hash_ctx.hash_next(data, ctx); - data += nessie_hash_ctx.blocksize_B; - sl -= nessie_hash_ctx.blocksize_B; - } - nessie_hash_ctx.hash_last(data, sl*8, ctx); - nessie_hash_ctx.hash_conv(hash, ctx); - nessie_print_item("hash", hash, (nessie_hash_ctx.hashsize_b+7)/8); -} - -// message=1 million times "a" - -static -void amillion_hash(void){ - uint8_t ctx[nessie_hash_ctx.ctx_size_B]; - uint8_t hash[(nessie_hash_ctx.hashsize_b+7)/8]; - uint8_t block[nessie_hash_ctx.blocksize_B]; - uint32_t n=1000000LL; - - uart_putstr_P(PSTR("\r\n message=")); - uart_putstr_P(PSTR("1 million times \"a\"")); - memset(block, 'a', nessie_hash_ctx.blocksize_B); - nessie_hash_ctx.hash_init(ctx); - while(n>=nessie_hash_ctx.blocksize_B){ - nessie_hash_ctx.hash_next(block, ctx); - n -= nessie_hash_ctx.blocksize_B; - } - nessie_hash_ctx.hash_last(block, n*8, ctx); - nessie_hash_ctx.hash_conv(hash, ctx); - nessie_print_item("hash", hash, (nessie_hash_ctx.hashsize_b+7)/8); -} - - -static -void zero_hash(uint16_t n){ - uint8_t ctx[nessie_hash_ctx.ctx_size_B]; - uint8_t hash[(nessie_hash_ctx.hashsize_b+7)/8]; - uint8_t block[nessie_hash_ctx.blocksize_B]; - - uart_putstr_P(PSTR("\r\n message=")); - if(n>=10000) - uart_putc('0'+n/10000); - if(n>=1000) - uart_putc('0'+(n/1000)%10); - if(n>=100) - uart_putc('0'+(n/100)%10); - if(n>=10) - uart_putc('0'+(n/10)%10); - uart_putc('0'+n%10); - uart_putstr_P(PSTR(" zero bits")); - - memset(block, 0, nessie_hash_ctx.blocksize_B); - nessie_hash_ctx.hash_init(ctx); - while(n>=nessie_hash_ctx.blocksize_B*8){ - nessie_hash_ctx.hash_next(block, ctx); - n -= nessie_hash_ctx.blocksize_B*8; - } - nessie_hash_ctx.hash_last(block, n, ctx); - nessie_hash_ctx.hash_conv(hash, ctx); - nessie_print_item("hash", hash, (nessie_hash_ctx.hashsize_b+7)/8); -} - -static -void one_in512_hash(uint16_t pos){ - uint8_t ctx[nessie_hash_ctx.ctx_size_B]; - uint8_t hash[(nessie_hash_ctx.hashsize_b+7)/8]; - uint8_t block[nessie_hash_ctx.blocksize_B]; - uint16_t n=512; - char* tab[8]={"80", "40", "20", "10", - "08", "04", "02", "01" }; - - pos&=511; - uart_putstr_P(PSTR("\r\n message=")); - uart_putstr_P(PSTR("512-bit string: ")); - if((pos/8) >=10){ - uart_putc('0'+(pos/8/10)%10); - } else { - uart_putc(' '); - } - uart_putc('0'+(pos/8)%10); - uart_putstr_P(PSTR("*00,")); - uart_putstr(tab[pos&7]); - uart_putc(','); - if(63-(pos/8) >=10){ - uart_putc('0'+((63-pos/8)/10)%10); - } else { - uart_putc(' '); - } - uart_putc('0'+(63-pos/8)%10); - uart_putstr_P(PSTR("*00")); - - /* now the real stuff */ - memset(block, 0, 512/8); - block[pos>>3] = 0x80>>(pos&0x7); - nessie_hash_ctx.hash_init(ctx); - while(n>=nessie_hash_ctx.blocksize_B*8){ - nessie_hash_ctx.hash_next(block, ctx); - n -= nessie_hash_ctx.blocksize_B*8; - } - nessie_hash_ctx.hash_last(block, n, ctx); - nessie_hash_ctx.hash_conv(hash, ctx); - nessie_print_item("hash", hash, (nessie_hash_ctx.hashsize_b+7)/8); -} - -static -void tv4_hash(void){ - uint8_t ctx[nessie_hash_ctx.ctx_size_B]; - uint8_t hash[(nessie_hash_ctx.hashsize_b+7)/8]; - uint8_t block[256/8]; - uint16_t n=256; - uint32_t i; - - uart_putstr_P(PSTR("\r\n message=")); - uart_putstr(PSTR("256 zero bits")); - memset(block, 0, 256/8); - - nessie_hash_ctx.hash_init(ctx); - while(n>=nessie_hash_ctx.blocksize_B*8){ - nessie_hash_ctx.hash_next(block, ctx); - n -= nessie_hash_ctx.blocksize_B*8; - } - nessie_hash_ctx.hash_last(block, n, ctx); - nessie_hash_ctx.hash_conv(hash, ctx); - nessie_print_item("hash", hash, (nessie_hash_ctx.hashsize_b+7)/8); - for(i=1; i<100000L; ++i){ /* this assumes BLOCKSIZE >= HASHSIZE */ - nessie_hash_ctx.hash_init(ctx); - nessie_hash_ctx.hash_last(hash, nessie_hash_ctx.hashsize_b, ctx); - nessie_hash_ctx.hash_conv(hash, ctx); - } - nessie_print_item("iterated 100000 times", hash, (nessie_hash_ctx.hashsize_b+7)/8); -} - -/* - "" (empty string) - message="a" - message="abc" - message="message digest" - message="abcdefghijklmnopqrstuvwxyz" - message="abcdbcdecdefdefgefghfghighijhijkijkljklmklmnlmnomnopnopq" - message="A...Za...z0...9" - message=8 times "1234567890" -*/ - - -void nessie_hash_run(void){ - uint16_t i; - uint8_t set; - - nessie_print_header(nessie_hash_ctx.name, 0, 0, nessie_hash_ctx.hashsize_b, 0, 0); - /* test set 1 */ - char* challange[8][2]= { - {"", "\"\" (empty string)"}, - {"a", "\"a\""}, - {"abc", "\"abc\""}, - {"message digest", "\"message digest\""}, - {"abcdefghijklmnopqrstuvwxyz","\"abcdefghijklmnopqrstuvwxyz\""}, - {"abcdbcdecdefdefgefghfghighijhijkijkljklmklmnlmnomnopnopq", - "\"abcdbcdecdefdefgefghfghighijhijkijkljklmklmnlmnomnopnopq\""}, - {"ABCDEFGHIJKLMNOPQRSTUVWXYZ" - "abcdefghijklmnopqrstuvwxyz" - "0123456789" , "\"A...Za...z0...9\""}, - {"1234567890" "1234567890" "1234567890" "1234567890" - "1234567890" "1234567890" "1234567890" "1234567890", - "8 times \"1234567890\""} - }; - set=1; - nessie_print_setheader(set); - for(i=0; i<8; ++i){ - nessie_print_set_vector(set, i); - ascii_hash(challange[i][0], challange[i][1]); - } - nessie_print_set_vector(set, i); - amillion_hash(); - /* test set 2 */ - set=2; - nessie_print_setheader(set); - for(i=0; i<1024; ++i){ - nessie_print_set_vector(set, i); - zero_hash(i); - } - /* test set 3 */ - set=3; - nessie_print_setheader(set); - for(i=0; i<512; ++i){ - nessie_print_set_vector(set, i); - one_in512_hash(i); - } - /* test set 4 */ - set=4; - nessie_print_setheader(set); - nessie_print_set_vector(set, 0); - tv4_hash(); - - nessie_print_footer(); -} diff --git a/nessie_hash_test.h b/nessie_hash_test.h deleted file mode 100644 index aa88bdb..0000000 --- a/nessie_hash_test.h +++ /dev/null @@ -1,46 +0,0 @@ -/* nessie_hash_test.h */ -/* - This file is part of the Crypto-avr-lib/microcrypt-lib. - Copyright (C) 2008 Daniel Otte (daniel.otte@rub.de) - - This program is free software: you can redistribute it and/or modify - it under the terms of the GNU General Public License as published by - the Free Software Foundation, either version 3 of the License, or - (at your option) any later version. - - This program is distributed in the hope that it will be useful, - but WITHOUT ANY WARRANTY; without even the implied warranty of - MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the - GNU General Public License for more details. - - You should have received a copy of the GNU General Public License - along with this program. If not, see . -*/ -#ifndef NESSIE_HASH_TEST_H_ -#define NESSIE_HASH_TEST_H_ - -#include - -typedef void (*nessie_hash_init_fpt)(void* ctx); -typedef void (*nessie_hash_next_fpt)(void* buffer, void* ctx); -typedef void (*nessie_hash_last_fpt)(void* buffer, uint16_t size_b, void* ctx); -typedef void (*nessie_hash_conv_fpt)(void* buffer, void* ctx); - - -typedef struct nessie_hash_ctx_st{ - uint16_t hashsize_b; - uint16_t blocksize_B; - uint16_t ctx_size_B; - char* name; - nessie_hash_init_fpt hash_init; - nessie_hash_next_fpt hash_next; - nessie_hash_last_fpt hash_last; - nessie_hash_conv_fpt hash_conv; -} nessie_hash_ctx_t; - - -extern nessie_hash_ctx_t nessie_hash_ctx; - -void nessie_hash_run(void); - -#endif /*NESSIE_HASH_TEST_H_*/ diff --git a/nessie_mac_test.c b/nessie_mac_test.c deleted file mode 100644 index 12863df..0000000 --- a/nessie_mac_test.c +++ /dev/null @@ -1,270 +0,0 @@ -/* nessie_mac_test.c */ -/* - This file is part of the Crypto-avr-lib/microcrypt-lib. - Copyright (C) 2008 Daniel Otte (daniel.otte@rub.de) - - This program is free software: you can redistribute it and/or modify - it under the terms of the GNU General Public License as published by - the Free Software Foundation, either version 3 of the License, or - (at your option) any later version. - - This program is distributed in the hope that it will be useful, - but WITHOUT ANY WARRANTY; without even the implied warranty of - MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the - GNU General Public License for more details. - - You should have received a copy of the GNU General Public License - along with this program. If not, see . -*/ -/** - * - * author: Daniel Otte - * email: daniel.otte@rub.de - * license: GPLv3 - * - * a suit for running the nessie-tests for MACs - * - * */ -#include -#include -#include "nessie_mac_test.h" -#include "nessie_common.h" -#include "uart.h" - -nessie_mac_ctx_t nessie_mac_ctx; - -#define KEYSIZE_B ((nessie_mac_ctx.keysize_b+7)/8) -#define MACSIZE_B ((nessie_mac_ctx.macsize_b+7)/8) - -#define PRINTKEY nessie_print_item("key", key, KEYSIZE_B) -#define PRINTMAC nessie_print_item("MAC", mac, MACSIZE_B) - -static -void ascii_mac(char* data, char* desc, uint8_t* key){ - uint8_t ctx[nessie_mac_ctx.ctx_size_B]; - uint8_t mac[MACSIZE_B]; - uint16_t sl; - - uart_putstr_P(PSTR("\r\n message=")); - uart_putstr(desc); - PRINTKEY; - nessie_mac_ctx.mac_init(key, nessie_mac_ctx.keysize_b, ctx); - sl = strlen(data); - while(sl>=nessie_mac_ctx.blocksize_B){ - nessie_mac_ctx.mac_next(data, ctx); - data += nessie_mac_ctx.blocksize_B; - sl -= nessie_mac_ctx.blocksize_B; - } - nessie_mac_ctx.mac_last(data, sl*8, key, nessie_mac_ctx.keysize_b, ctx); - nessie_mac_ctx.mac_conv(mac, ctx); - PRINTMAC; -} - -// message=1 million times "a" - -static -void amillion_mac(uint8_t* key){ - uint8_t ctx[nessie_mac_ctx.ctx_size_B]; - uint8_t mac[MACSIZE_B]; - uint8_t block[nessie_mac_ctx.blocksize_B]; - uint32_t n=1000000LL; - - uart_putstr_P(PSTR("\r\n message=")); - uart_putstr_P(PSTR("1 million times \"a\"")); - PRINTKEY; - - memset(block, 'a', nessie_mac_ctx.blocksize_B); - nessie_mac_ctx.mac_init(key, nessie_mac_ctx.keysize_b, ctx); - while(n>=nessie_mac_ctx.blocksize_B){ - nessie_mac_ctx.mac_next(block, ctx); - n -= nessie_mac_ctx.blocksize_B; - } - nessie_mac_ctx.mac_last(block, n*8, key, nessie_mac_ctx.keysize_b, ctx); - nessie_mac_ctx.mac_conv(mac, ctx); - PRINTMAC; -} - - -static -void zero_mac(uint16_t n, uint8_t* key){ - uint8_t ctx[nessie_mac_ctx.ctx_size_B]; - uint8_t mac[MACSIZE_B]; - uint8_t block[nessie_mac_ctx.blocksize_B]; - - uart_putstr_P(PSTR("\r\n message=")); - if(n>=10000) - uart_putc('0'+n/10000); - if(n>=1000) - uart_putc('0'+(n/1000)%10); - if(n>=100) - uart_putc('0'+(n/100)%10); - if(n>=10) - uart_putc('0'+(n/10)%10); - uart_putc('0'+n%10); - uart_putstr_P(PSTR(" zero bits")); - PRINTKEY; - - memset(block, 0, nessie_mac_ctx.blocksize_B); - nessie_mac_ctx.mac_init(key, nessie_mac_ctx.keysize_b,ctx);; - while(n>=nessie_mac_ctx.blocksize_B*8){ - nessie_mac_ctx.mac_next(block, ctx); - n -= nessie_mac_ctx.blocksize_B*8; - } - nessie_mac_ctx.mac_last(block, n, key, nessie_mac_ctx.keysize_b, ctx); - nessie_mac_ctx.mac_conv(mac, ctx); - PRINTMAC; -} - -static -void one_in512_mac(uint16_t pos, uint8_t* key){ - uint8_t ctx[nessie_mac_ctx.ctx_size_B]; - uint8_t mac[MACSIZE_B]; - uint8_t block[nessie_mac_ctx.blocksize_B]; - uint16_t n=512; - char* tab[8]={"80", "40", "20", "10", - "08", "04", "02", "01" }; - - pos&=511; - uart_putstr_P(PSTR("\r\n message=")); - uart_putstr_P(PSTR("512-bit string: ")); - if((pos/8) >=10){ - uart_putc('0'+(pos/8/10)%10); - } else { - uart_putc(' '); - } - uart_putc('0'+(pos/8)%10); - uart_putstr_P(PSTR("*00,")); - uart_putstr(tab[pos&7]); - uart_putc(','); - if(63-(pos/8) >=10){ - uart_putc('0'+((63-pos/8)/10)%10); - } else { - uart_putc(' '); - } - uart_putc('0'+(63-pos/8)%10); - uart_putstr_P(PSTR("*00")); - PRINTKEY; - - /* now the real stuff */ - memset(block, 0, 512/8); - block[pos>>3] = 0x80>>(pos&0x7); - nessie_mac_ctx.mac_init(key, nessie_mac_ctx.keysize_b, ctx);; - while(n>=nessie_mac_ctx.blocksize_B*8){ - nessie_mac_ctx.mac_next(block, ctx); - n -= nessie_mac_ctx.blocksize_B*8; - } - nessie_mac_ctx.mac_last(block, n, key, nessie_mac_ctx.keysize_b, ctx); - nessie_mac_ctx.mac_conv(mac, ctx); - PRINTMAC; -} - -static -void tv4_mac(uint8_t* key){ - uint8_t ctx[nessie_mac_ctx.ctx_size_B]; - uint8_t mac[MACSIZE_B]; - uint8_t block[256/8]; - uint16_t n=256; - uint32_t i; - - uart_putstr_P(PSTR("\r\n message=")); - uart_putstr(PSTR("256 zero bits")); - memset(block, 0, 256/8); - - nessie_mac_ctx.mac_init(key, nessie_mac_ctx.keysize_b, ctx);; - while(n>=nessie_mac_ctx.blocksize_B*8){ - nessie_mac_ctx.mac_next(block, ctx); - n -= nessie_mac_ctx.blocksize_B*8; - } - nessie_mac_ctx.mac_last(block, n, key, nessie_mac_ctx.keysize_b, ctx); - nessie_mac_ctx.mac_conv(mac, ctx); - PRINTMAC; - for(i=1; i<100000L; ++i){ /* this assumes BLOCKSIZE >= HASHSIZE */ - nessie_mac_ctx.mac_init(key, nessie_mac_ctx.keysize_b, ctx);; - nessie_mac_ctx.mac_last(mac, nessie_mac_ctx.macsize_b, key, nessie_mac_ctx.keysize_b, ctx); - nessie_mac_ctx.mac_conv(mac, ctx); - } - nessie_print_item("iterated 100000 times", mac, MACSIZE_B); -} - - -void nessie_mac_run(void){ - uint16_t i; - uint8_t set; - uint8_t keyproto[] = {0x00, 0x11, 0x22, 0x33, 0x44, 0x55, 0x66, 0x77, - 0x88, 0x99, 0xaa, 0xbb, 0xcc, 0xdd, 0xee, 0xff, - 0x01, 0x23, 0x45, 0x67, 0x89, 0xab, 0xcd, 0xef }; - uint8_t key[KEYSIZE_B]; - - nessie_print_header(nessie_mac_ctx.name, nessie_mac_ctx.keysize_b, 0, 0, - nessie_mac_ctx.macsize_b, 0); - /* test set 1 */ - char* challange[10][2]= { - {"", "\"\" (empty string)"}, - {"a", "\"a\""}, - {"abc", "\"abc\""}, - {"message digest", "\"message digest\""}, - {"abcdefghijklmnopqrstuvwxyz","\"abcdefghijklmnopqrstuvwxyz\""}, - {"abcdbcdecdefdefgefghfghighijhijkijkljklmklmnlmnomnopnopq", - "\"abcdbcdecdefdefgefghfghighijhijkijkljklmklmnlmnomnopnopq\""}, - {"ABCDEFGHIJKLMNOPQRSTUVWXYZ" - "abcdefghijklmnopqrstuvwxyz" - "0123456789" , "\"A...Za...z0...9\""}, - {"1234567890" "1234567890" "1234567890" "1234567890" - "1234567890" "1234567890" "1234567890" "1234567890", - "8 times \"1234567890\""}, - {"Now is the time for all ", "\"Now is the time for all \""}, - {"Now is the time for it", "\"Now is the time for it\""} - }; - set=1; - nessie_print_setheader(set); - for(i=0; i>3]=0x80>>(i&0x7); - ascii_mac("ABC", "\"ABC\"", key); - } - nessie_print_footer(); -} diff --git a/nessie_mac_test.h b/nessie_mac_test.h deleted file mode 100644 index ed83133..0000000 --- a/nessie_mac_test.h +++ /dev/null @@ -1,47 +0,0 @@ -/* nessie_mac_test.h */ -/* - This file is part of the Crypto-avr-lib/microcrypt-lib. - Copyright (C) 2008 Daniel Otte (daniel.otte@rub.de) - - This program is free software: you can redistribute it and/or modify - it under the terms of the GNU General Public License as published by - the Free Software Foundation, either version 3 of the License, or - (at your option) any later version. - - This program is distributed in the hope that it will be useful, - but WITHOUT ANY WARRANTY; without even the implied warranty of - MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the - GNU General Public License for more details. - - You should have received a copy of the GNU General Public License - along with this program. If not, see . -*/ -#ifndef NESSIE_MAC_TEST_H_ -#define NESSIE_MAC_TEST_H_ - -#include - -typedef void (*nessie_mac_init_fpt)(void* key, uint16_t keysize_b, void* ctx); -typedef void (*nessie_mac_next_fpt)(void* buffer, void* ctx); -typedef void (*nessie_mac_last_fpt)(void* buffer, uint16_t size_b, void* key, uint16_t keysize_b, void* ctx); -typedef void (*nessie_mac_conv_fpt)(void* buffer, void* ctx); - - -typedef struct nessie_mac_ctx_st{ - uint16_t macsize_b; - uint16_t keysize_b; - uint16_t blocksize_B; - uint16_t ctx_size_B; - char* name; - nessie_mac_init_fpt mac_init; - nessie_mac_next_fpt mac_next; - nessie_mac_last_fpt mac_last; - nessie_mac_conv_fpt mac_conv; -} nessie_mac_ctx_t; - - -extern nessie_mac_ctx_t nessie_mac_ctx; - -void nessie_mac_run(void); - -#endif /*NESSIE_MAC_TEST_H_*/ diff --git a/nessie_stream_test.c b/nessie_stream_test.c deleted file mode 100644 index 3866b21..0000000 --- a/nessie_stream_test.c +++ /dev/null @@ -1,192 +0,0 @@ -/* nessie_stream_test.c */ -/* - This file is part of the Crypto-avr-lib/microcrypt-lib. - Copyright (C) 2008 Daniel Otte (daniel.otte@rub.de) - - This program is free software: you can redistribute it and/or modify - it under the terms of the GNU General Public License as published by - the Free Software Foundation, either version 3 of the License, or - (at your option) any later version. - - This program is distributed in the hope that it will be useful, - but WITHOUT ANY WARRANTY; without even the implied warranty of - MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the - GNU General Public License for more details. - - You should have received a copy of the GNU General Public License - along with this program. If not, see . -*/ -/** - * - * author: Daniel Otte - * email: daniel.otte@rub.de - * license: GPLv3 - * - * a suit for running the nessie-tests for streamciphers - * - * */ -#include -#include -#include "nessie_stream_test.h" -#include "nessie_common.h" -#include "uart.h" - -nessie_stream_ctx_t nessie_stream_ctx; - - -#define BLOCKSIZE_B 64 - -static -void memxor(void* dest, void* src, uint8_t length){ - while(length--){ - *((uint8_t*)dest) ^= *((uint8_t*)src); - dest = (uint8_t*)dest +1; - src = (uint8_t*)src +1; - } -} - - -static -void nessie_gen_block(void* ctx, uint8_t* block){ - uint16_t i; - for(i=0; i>(i%8); - nessie_stream_enc(key); - } - /* test set 2 */ - set=2; - nessie_print_setheader(set); - for(i=0; i<256; ++i){ - nessie_print_set_vector(set, i); - memset(key, i, (nessie_stream_ctx.keysize_b+7)/8); - nessie_stream_enc(key); - } - /* test set 3 */ - set=3; - nessie_print_setheader(set); - for(i=0; i<256; ++i){ - uint8_t j; - nessie_print_set_vector(set, i); - for(j=0; j<(nessie_stream_ctx.keysize_b+7)/8; ++j){ - key[j]=(i+j)&0xff; - } - nessie_stream_enc(key); - } - /* test set 4 */ - set=4; - nessie_print_setheader(set); - for(i=0; i<4; ++i){ - uint8_t j; - nessie_print_set_vector(set, i); - for(j=0; j<(nessie_stream_ctx.keysize_b+7)/8; ++j){ - key[j]=(i*5+j*0x53)&0xff; - } - nessie_stream_enc_large(key); - } - - nessie_print_footer(); -} diff --git a/nessie_stream_test.h b/nessie_stream_test.h deleted file mode 100644 index 8422f45..0000000 --- a/nessie_stream_test.h +++ /dev/null @@ -1,42 +0,0 @@ -/* nessie_stream_test.h */ -/* - This file is part of the Crypto-avr-lib/microcrypt-lib. - Copyright (C) 2008 Daniel Otte (daniel.otte@rub.de) - - This program is free software: you can redistribute it and/or modify - it under the terms of the GNU General Public License as published by - the Free Software Foundation, either version 3 of the License, or - (at your option) any later version. - - This program is distributed in the hope that it will be useful, - but WITHOUT ANY WARRANTY; without even the implied warranty of - MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the - GNU General Public License for more details. - - You should have received a copy of the GNU General Public License - along with this program. If not, see . -*/ -#ifndef NESSIE_STREAM_TEST_H_ -#define NESSIE_STREAM_TEST_H_ - -#include - -typedef void (*nessie_stream_genctx_fpt)(uint8_t* key, uint16_t keylength_b, void* ctx); -typedef uint8_t (*nessie_stream_genenc_fpt)(void* ctx); - -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; - nessie_stream_genctx_fpt cipher_genctx; - nessie_stream_genenc_fpt cipher_enc; -} nessie_stream_ctx_t; - - -extern nessie_stream_ctx_t nessie_stream_ctx; - -void nessie_stream_run(void); - -#endif /*NESSIE_STREAM_TEST_H_*/ diff --git a/performance_test.c b/performance_test.c deleted file mode 100644 index 04a26bd..0000000 --- a/performance_test.c +++ /dev/null @@ -1,112 +0,0 @@ -/* performance_test.c */ -/* - This file is part of the Crypto-avr-lib/microcrypt-lib. - Copyright (C) 2008 Daniel Otte (daniel.otte@rub.de) - - This program is free software: you can redistribute it and/or modify - it under the terms of the GNU General Public License as published by - the Free Software Foundation, either version 3 of the License, or - (at your option) any later version. - - This program is distributed in the hope that it will be useful, - but WITHOUT ANY WARRANTY; without even the implied warranty of - MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the - GNU General Public License for more details. - - You should have received a copy of the GNU General Public License - along with this program. If not, see . -*/ -/* - * author: Daniel Otte - * email: daniel.otte@rub.de - * license: GPLv3 - * - * - **/ - -#include "config.h" -#include -#include -#include -#include -#include -#include -#include "uart.h" -#include "performance_test.h" - - -#ifdef ATMEGA644 - #define TIMSK TIMSK1 -#endif - - - -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(TOIE1); /* 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; -} - -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); -} - - diff --git a/performance_test.h b/performance_test.h deleted file mode 100644 index d8b1565..0000000 --- a/performance_test.h +++ /dev/null @@ -1,33 +0,0 @@ -/* performance_test.h */ -/* - This file is part of the Crypto-avr-lib/microcrypt-lib. - Copyright (C) 2008 Daniel Otte (daniel.otte@rub.de) - - This program is free software: you can redistribute it and/or modify - it under the terms of the GNU General Public License as published by - the Free Software Foundation, either version 3 of the License, or - (at your option) any later version. - - This program is distributed in the hope that it will be useful, - but WITHOUT ANY WARRANTY; without even the implied warranty of - MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the - GNU General Public License for more details. - - You should have received a copy of the GNU General Public License - along with this program. If not, see . -*/ -#ifndef PERFORMANCE_TEST_H_ -#define PERFORMANCE_TEST_H_ - -#include -#include - -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_*/ diff --git a/serial-tools.c b/serial-tools.c deleted file mode 100644 index 47b6439..0000000 --- a/serial-tools.c +++ /dev/null @@ -1,82 +0,0 @@ -/* serial-tools.c */ -/* - This file is part of the Crypto-avr-lib/microcrypt-lib. - Copyright (C) 2008 Daniel Otte (daniel.otte@rub.de) - - This program is free software: you can redistribute it and/or modify - it under the terms of the GNU General Public License as published by - the Free Software Foundation, either version 3 of the License, or - (at your option) any later version. - - This program is distributed in the hope that it will be useful, - but WITHOUT ANY WARRANTY; without even the implied warranty of - MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the - GNU General Public License for more details. - - You should have received a copy of the GNU General Public License - along with this program. If not, see . -*/ -/** - * - * Author: Daniel Otte - * Date: 16.05.2006 - * - * This tools should help to parse some input. - * - */ - -#include "config.h" -#include "uart.h" -#include -#include - -int getnextwordn(char *s, int n){ /* words are seperated by spaces */ - char c = ' '; - while ((c=uart_getc()) == ' ') - ; - *s++ = c; - while (n && (*s++=uart_getc())!=' ') - ; - *(s-1) = '\0'; - return n; -} - - -void readhex2buffer(void* buffer, int n){ - char c; - uint8_t i; - -// DEBUG_S("\r\nDBG: n="); DEBUG_B(n&0xff); DEBUG_S("\r\n"); - for(i=0; i=c){ - ((uint8_t*)buffer)[i] = c - '0'; - } else { - c &= ~('A' ^ 'a'); /* make all uppercase */ - if ('A'<= c && 'F'>=c){ - ((uint8_t*)buffer)[i] = c - 'A' + 10; - } else { - /* oh shit, wrong char */ - } - } - - ((uint8_t*)buffer)[i] <<= 4; - - c = uart_getc(); - if ('0'<= c && '9'>=c){ - ((uint8_t*)buffer)[i] |= c - '0'; - } else { - c &= ~('A' ^ 'a'); /* make all uppercase */ - if ('A'<= c && 'F'>=c){ - ((uint8_t*)buffer)[i] |= c - 'A' + 10; - } else { - /* oh shit, wrong char */ - } - } - } /* for i=0 .. n */ -} - -void uart_putptr(void* p){ - uart_hexdump((void*) &p,2); -} - diff --git a/serial-tools.h b/serial-tools.h deleted file mode 100644 index c76b4d5..0000000 --- a/serial-tools.h +++ /dev/null @@ -1,27 +0,0 @@ -/* serial-tools.h */ -/* - This file is part of the Crypto-avr-lib/microcrypt-lib. - Copyright (C) 2008 Daniel Otte (daniel.otte@rub.de) - - This program is free software: you can redistribute it and/or modify - it under the terms of the GNU General Public License as published by - the Free Software Foundation, either version 3 of the License, or - (at your option) any later version. - - This program is distributed in the hope that it will be useful, - but WITHOUT ANY WARRANTY; without even the implied warranty of - MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the - GNU General Public License for more details. - - You should have received a copy of the GNU General Public License - along with this program. If not, see . -*/ -#ifndef SERIALTOOLS_H_ -#define SERIALTOOLS_H_ - - -int getnextwordn(char *s, int n); /* words are seperated by spaces */ -void readhex2buffer(void* buffer, int n); -void uart_putptr(void* p); - -#endif /*SERIALTOOLS_H_*/ diff --git a/serpent.c b/serpent.c index 8c33bbe..8056eb4 100644 --- a/serpent.c +++ b/serpent.c @@ -26,21 +26,12 @@ #include #include /* memset() */ #include +#include "memxor.h" #include "serpent.h" #include "serpent-sboxes.h" /******************************************************************************/ -void memxor(void * dest, void * src, uint8_t size){ - while(size--){ - *((uint8_t*)dest) ^= *((uint8_t*)src); - dest = (uint8_t*)dest +1; - src = (uint8_t*)src +1; - } -} - -/******************************************************************************/ - uint32_t rotl32(uint32_t a, uint8_t n){ return ((a<>(32-n))); } @@ -92,10 +83,10 @@ static uint32_t gen_w(uint32_t * b, uint8_t i){ } /* key must be 256bit (32 byte) large! */ -void serpent_init(void * key, uint8_t keysize, serpent_ctx_t * ctx){ +void serpent_init(const void* key, uint16_t keysize, serpent_ctx_t* ctx){ uint32_t buffer[8]; uint8_t i,j; - if(keysize){ + if(keysize<256){ /* keysize is less than 256 bit, padding needed */ memset(buffer, 0, 32); memcpy(buffer, key, (keysize+7)/8); @@ -117,7 +108,7 @@ void serpent_init(void * key, uint8_t keysize, serpent_ctx_t * ctx){ } -void serpent_enc(void* buffer, serpent_ctx_t * ctx){ +void serpent_enc(void* buffer, const serpent_ctx_t* ctx){ uint8_t i; for(i=0; i<31; ++i){ memxor((uint8_t*)buffer, ctx->k[i], 16); @@ -130,7 +121,7 @@ void serpent_enc(void* buffer, serpent_ctx_t * ctx){ memxor((uint8_t*)buffer, ctx->k[i], 16); } -void serpent_dec(void* buffer, serpent_ctx_t * ctx){ +void serpent_dec(void* buffer, const serpent_ctx_t* ctx){ int8_t i=32; memxor((uint8_t*)buffer, ctx->k[i], 16); diff --git a/serpent.h b/serpent.h index 084b87a..3e90253 100644 --- a/serpent.h +++ b/serpent.h @@ -16,10 +16,10 @@ You should have received a copy of the GNU General Public License along with this program. If not, see . */ -/* serpent.h - * a bitsliced implementation of the serpent cipher for avr microcontrollers - * author: Daniel Otte - * license: GPLv3 +/** \file serpent.h + * \author Daniel Otte + * \license GPLv3 + * \brief a implementation of the serpent cipher for avr microcontrollers */ #ifndef SERPENT_H_ @@ -35,13 +35,13 @@ typedef struct serpent_ctx_st { #define SERPENT_KEY128 128 #define SERPENT_KEY192 192 -#define SERPENT_KEY256 0 +#define SERPENT_KEY256 256 /* key must be 256bit (32 byte) large! */ -void serpent_init(void * key, uint8_t keysize, serpent_ctx_t * ctx); -void serpent_enc(void * buffer, serpent_ctx_t * ctx); -void serpent_dec(void * buffer, serpent_ctx_t * ctx); +void serpent_init(const void* key, uint16_t keysize, serpent_ctx_t* ctx); +void serpent_enc(void* buffer, const serpent_ctx_t* ctx); +void serpent_dec(void* buffer, const serpent_ctx_t* ctx); #endif /*SERPENT_H_*/ diff --git a/test_src/cli.c b/test_src/cli.c new file mode 100644 index 0000000..8c15f5f --- /dev/null +++ b/test_src/cli.c @@ -0,0 +1,73 @@ +/* cli.c */ +/* + This file is part of the Crypto-avr-lib/microcrypt-lib. + Copyright (C) 2008 Daniel Otte (daniel.otte@rub.de) + + This program is free software: you can redistribute it and/or modify + it under the terms of the GNU General Public License as published by + the Free Software Foundation, either version 3 of the License, or + (at your option) any later version. + + This program is distributed in the hope that it will be useful, + but WITHOUT ANY WARRANTY; without even the implied warranty of + MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + GNU General Public License for more details. + + You should have received a copy of the GNU General Public License + along with this program. If not, see . +*/ +/** + * + * author: Daniel Otte + * email: daniel.otte@rub.de + * license: GPLv3 or later + * + * components to help implementing simple command based interaction + * + **/ + +#include +#include +#include + +int16_t findstring_d0(const char* str, const char* v){ + uint8_t i=0; + while(*v){ + if(!strcmp(str, v)){ + return i; + } + while(*v++) /* go to the next string */ + ; + ++i; + } + return -1; +} + +int16_t findstring_d0_P(const char* str, PGM_P v){ + uint8_t i=0; + while(pgm_read_byte(v)){ + if(!strcmp_P(str, v)){ + return i; + } + while(pgm_read_byte(v++)) /* go to the next string */ + ; + ++i; + } + return -1; +} + +int16_t execcommand_d0_P(const char* str, PGM_P v, void(*fpt[])(void) ){ + uint8_t i=0; + while(pgm_read_byte(v)){ + if(!strcmp_P(str, v)){ + (fpt[i])(); + return i; + } + while(pgm_read_byte(v++)) /* go to the next string */ + ; + ++i; + } + return -1; +} + + diff --git a/test_src/cli.h b/test_src/cli.h new file mode 100644 index 0000000..c36a6e6 --- /dev/null +++ b/test_src/cli.h @@ -0,0 +1,31 @@ +/* cli.h */ +/* + This file is part of the Crypto-avr-lib/microcrypt-lib. + Copyright (C) 2008 Daniel Otte (daniel.otte@rub.de) + + This program is free software: you can redistribute it and/or modify + it under the terms of the GNU General Public License as published by + the Free Software Foundation, either version 3 of the License, or + (at your option) any later version. + + This program is distributed in the hope that it will be useful, + but WITHOUT ANY WARRANTY; without even the implied warranty of + MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + GNU General Public License for more details. + + You should have received a copy of the GNU General Public License + along with this program. If not, see . +*/ +#ifndef CLI_H_ +#define CLI_H_ + +#include +#include + +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); + +int16_t execcommand_d0_P(const char* str, PGM_P v, void(*fpt[])(void) ); +#endif /*CLI_H_*/ diff --git a/test_src/debug.c b/test_src/debug.c new file mode 100644 index 0000000..3b5fee4 --- /dev/null +++ b/test_src/debug.c @@ -0,0 +1,64 @@ +/* debug.c */ +/* + This file is part of the Crypto-avr-lib/microcrypt-lib. + Copyright (C) 2008 Daniel Otte (daniel.otte@rub.de) + + This program is free software: you can redistribute it and/or modify + it under the terms of the GNU General Public License as published by + the Free Software Foundation, either version 3 of the License, or + (at your option) any later version. + + This program is distributed in the hope that it will be useful, + but WITHOUT ANY WARRANTY; without even the implied warranty of + MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + GNU General Public License for more details. + + You should have received a copy of the GNU General Public License + along with this program. If not, see . +*/ +/*************************** +* +* +* +****************************/ +#include "config.h" + +#if DEBUG == uart + #include "uart.h" +#else + #error "Your DEBUG methode is not suported!" +#endif + +#ifdef DEBUG + void debug_init(void){ + #if DBUG==uart + uart_init(); + #else + #error "Your DEBUG methode is not suported!" + #endif + } + + void debug_char(char c){ + static char initialised = 0; + if (!initialised){ + uart_init(); + initialised=1; + } + uart_putc(c); + } + + void debug_str(char* s){ + while (*s) + debug_char(*s++); + } + + + + void debug_byte(char b){ + char table[] = "0123456789ABCDEF"; + debug_char(table[(b>>4) & 0xf]); + debug_char(table[b&0xf]); + } + +#endif //DEBUG + diff --git a/test_src/main-arcfour-test.c b/test_src/main-arcfour-test.c new file mode 100644 index 0000000..0e0be91 --- /dev/null +++ b/test_src/main-arcfour-test.c @@ -0,0 +1,86 @@ +/* main-arcfour-test.c */ +/* + This file is part of the Crypto-avr-lib/microcrypt-lib. + Copyright (C) 2008 Daniel Otte (daniel.otte@rub.de) + + This program is free software: you can redistribute it and/or modify + it under the terms of the GNU General Public License as published by + the Free Software Foundation, either version 3 of the License, or + (at your option) any later version. + + This program is distributed in the hope that it will be useful, + but WITHOUT ANY WARRANTY; without even the implied warranty of + MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + GNU General Public License for more details. + + You should have received a copy of the GNU General Public License + along with this program. If not, see . +*/ +/* + * arcfour (RC4 compatible) test-suit + * +*/ + +#include "config.h" +#include "serial-tools.h" +#include "uart.h" +#include "debug.h" + +#include "arcfour.h" +#include "nessie_stream_test.h" + +#include +#include + +char* cipher_name = "Arcfour"; + +/***************************************************************************** + * additional validation-functions * + *****************************************************************************/ +void arcfour_genctx_dummy(uint8_t* key, uint16_t keysize, void* ctx){ + arcfour_init(ctx, key, (keysize+7)/8); +} + + + +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; + nessie_stream_ctx.cipher_enc = (nessie_stream_genenc_fpt)arcfour_gen; + + nessie_stream_run(); +} + + + +/***************************************************************************** + * main * + *****************************************************************************/ + +int main (void){ + char str[20]; + DEBUG_INIT(); + uart_putstr("\r\n"); + + uart_putstr_P(PSTR("\r\n\r\nCrypto-VS (")); + uart_putstr(cipher_name); + uart_putstr_P(PSTR(")\r\nloaded and running\r\n")); + +restart: + 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_arcfour(); + goto restart; + continue; + error: + uart_putstr("ERROR\r\n"); + } + + +} + diff --git a/test_src/main-camellia-test.c b/test_src/main-camellia-test.c new file mode 100644 index 0000000..4d64a50 --- /dev/null +++ b/test_src/main-camellia-test.c @@ -0,0 +1,135 @@ +/* main-camellia-test.c */ +/* + This file is part of the Crypto-avr-lib/microcrypt-lib. + Copyright (C) 2008 Daniel Otte (daniel.otte@rub.de) + + This program is free software: you can redistribute it and/or modify + it under the terms of the GNU General Public License as published by + the Free Software Foundation, either version 3 of the License, or + (at your option) any later version. + + This program is distributed in the hope that it will be useful, + but WITHOUT ANY WARRANTY; without even the implied warranty of + MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + GNU General Public License for more details. + + You should have received a copy of the GNU General Public License + along with this program. If not, see . +*/ +/* + * camellia test-suit + * + */ + +#include "config.h" +#include "serial-tools.h" +#include "uart.h" +#include "debug.h" + +#include "camellia.h" +#include "nessie_bc_test.h" +#include "performance_test.h" +#include "cli.h" + +char* cipher_name = "Camellia"; + + +#include +#include +#include +#include + + +/***************************************************************************** + * additional validation-functions * + *****************************************************************************/ +void camellia128_init_dummy(void* key, uint16_t keysize_b, void* ctx){ + camellia128_init(key, ctx); +} + +void testrun_nessie_camellia(void){ + nessie_bc_ctx.blocksize_B = 16; + nessie_bc_ctx.keysize_b = 128; + nessie_bc_ctx.name = cipher_name; + nessie_bc_ctx.ctx_size_B = sizeof(camellia128_ctx_t); + nessie_bc_ctx.cipher_enc = (nessie_bc_enc_fpt)camellia128_enc; + nessie_bc_ctx.cipher_dec = (nessie_bc_dec_fpt)camellia128_dec; + nessie_bc_ctx.cipher_genctx = (nessie_bc_gen_fpt)camellia128_init_dummy; + + nessie_bc_run(); +} + + +void test_performance_camellia(void){ + uint64_t t; + char str[6]; + uint8_t key[16], data[16]; + camellia128_ctx_t ctx; + + calibrateTimer(); + print_overhead(); + + memset(key, 0, 16); + memset(data, 0, 16); + + startTimer(1); + camellia128_init(key, &ctx); + t = stopTimer(); + uart_putstr_P(PSTR("\r\n\tctx-gen time: ")); + ultoa((unsigned long)t, str, 10); + uart_putstr(str); + + + startTimer(1); + camellia128_enc(data, &ctx); + t = stopTimer(); + uart_putstr_P(PSTR("\r\n\tencrypt time: ")); + ultoa((unsigned long)t, str, 10); + uart_putstr(str); + + + startTimer(1); + camellia128_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")); +} + + + +/***************************************************************************** + * self tests * + *****************************************************************************/ + +/***************************************************************************** + * main * + *****************************************************************************/ + +int main (void){ + char str[20]; + + + DEBUG_INIT(); + uart_putstr("\r\n"); + + 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[] = {testrun_nessie_camellia, testrun_nessie_camellia, test_performance_camellia}; + + while(1){ + 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"); + } +} + diff --git a/test_src/main-cast5-test.c b/test_src/main-cast5-test.c new file mode 100644 index 0000000..2cfb3d1 --- /dev/null +++ b/test_src/main-cast5-test.c @@ -0,0 +1,220 @@ +/* main-cast5-test.c */ +/* + This file is part of the Crypto-avr-lib/microcrypt-lib. + Copyright (C) 2008 Daniel Otte (daniel.otte@rub.de) + + This program is free software: you can redistribute it and/or modify + it under the terms of the GNU General Public License as published by + the Free Software Foundation, either version 3 of the License, or + (at your option) any later version. + + This program is distributed in the hope that it will be useful, + but WITHOUT ANY WARRANTY; without even the implied warranty of + MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + GNU General Public License for more details. + + You should have received a copy of the GNU General Public License + along with this program. If not, see . +*/ +/* + * cast5 test-suit + * +*/ + +#include "config.h" +#include "serial-tools.h" +#include "uart.h" +#include "debug.h" + +#include "cast5.h" +#include "nessie_bc_test.h" +#include "performance_test.h" +#include "cli.h" + +#include +#include +#include + +char* cipher_name = "cast-128 (cast5)"; + +/***************************************************************************** + * additional validation-functions * + *****************************************************************************/ + +void testrun_nessie_cast5(void){ + nessie_bc_ctx.blocksize_B = 8; + nessie_bc_ctx.keysize_b = 128; + nessie_bc_ctx.name = cipher_name; + nessie_bc_ctx.ctx_size_B = sizeof(cast5_ctx_t); + nessie_bc_ctx.cipher_enc = (nessie_bc_enc_fpt)cast5_enc; + nessie_bc_ctx.cipher_dec = (nessie_bc_dec_fpt)cast5_dec; + nessie_bc_ctx.cipher_genctx = (nessie_bc_gen_fpt)cast5_init; + + nessie_bc_run(); +} + +/***************************************************************************** + * self tests * + *****************************************************************************/ + +void cast5_ctx_dump(cast5_ctx_t *s){ + uint8_t i; + uart_putstr("\r\n==== cast5_ctx_dump ====\r\n shortkey: "); + uart_putstr(s->shortkey?"yes":"no"); + for(i=0;i<16;++i){ + uint8_t r; + uart_putstr("\r\n Km"); uart_hexdump(&i, 1); uart_putc(':'); + uart_hexdump(&(s->mask[i]), 4); + uart_putstr("\r\n Kr"); uart_hexdump(&i, 1); uart_putc(':'); + r = (s->rotl[i/2]); + if (i&0x01) r >>= 4; + r &= 0xf; + r += (s->roth[i>>3]&(1<<(i&0x7)))?0x10:0x00; + uart_hexdump(&r, 1); + } +} + + +void test_encrypt(uint8_t *block, uint8_t *key, uint8_t keylength, bool print){ + cast5_ctx_t s; + if (print){ + uart_putstr("\r\nCAST5:\r\n key:\t"); + uart_hexdump(key, keylength/8); + uart_putstr("\r\n plaintext:\t"); + uart_hexdump(block, 8); + } + cast5_init(key, keylength, &s); + cast5_enc(block, &s); + if (print){ + uart_putstr("\r\n ciphertext:\t"); + uart_hexdump(block, 8); + } +} + +void test_decrypt(uint8_t *block, uint8_t *key, uint8_t keylength, bool print){ + cast5_ctx_t s; + if (print){ + uart_putstr("\r\nCAST5:\r\n key:\t"); + uart_hexdump(key, keylength/8); + uart_putstr("\r\n ciphertext:\t"); + uart_hexdump(block, 8); + } + cast5_init(key, keylength, &s); + cast5_dec(block, &s); + if (print){ + uart_putstr("\r\n plaintext:\t"); + uart_hexdump(block, 8); + } +} + +void testrun_cast5(void){ + uint8_t block[8]; + uint8_t key[16]; + uint8_t *tda = (uint8_t*)"\x01\x23\x45\x67\x89\xAB\xCD\xEF", + *tka = (uint8_t*)"\x01\x23\x45\x67\x12\x34\x56\x78\x23\x45\x67\x89\x34\x56\x78\x9A"; + memcpy(block, tda, 8); + memcpy(key, tka, 16); + test_encrypt(block, key, 128, true); + test_decrypt(block, key, 128, true); + memcpy(block, tda, 8); + memcpy(key, tka, 16); + test_encrypt(block, key, 80, true); + test_decrypt(block, key, 80, true); + memcpy(block, tda, 8); + memcpy(key, tka, 16); + test_encrypt(block, key, 40, true); + test_decrypt(block, key, 40, true); + +/**** long test *****/ + uart_putstr("\r\nmaintance-test"); + uint8_t a[16]= {0x01, 0x23, 0x45, 0x67, 0x12, + 0x34, 0x56, 0x78, 0x23, 0x45, + 0x67, 0x89, 0x34, 0x56, 0x78, + 0x9A}, + b[16]= {0x01, 0x23, 0x45, 0x67, 0x12, + 0x34, 0x56, 0x78, 0x23, 0x45, + 0x67, 0x89, 0x34, 0x56, 0x78, + 0x9A}; + uint32_t i; + for(i=0;i<1000000; ++i){ + test_encrypt(&(a[0]), &(b[0]), 128, false); + test_encrypt(&(a[8]), &(b[0]), 128, false); + test_encrypt(&(b[0]), &(a[0]), 128, false); + test_encrypt(&(b[8]), &(a[0]), 128, false); + if ((i&0x000000ff) == 0){ + uart_putstr("\r\n"); + uart_hexdump(&i, 4); + } + } + uart_putstr("\r\na = "); uart_hexdump(a, 16); + uart_putstr("\r\nb = "); uart_hexdump(b, 16); + +} + +void testrun_performance_cast5(void){ + uint64_t t; + char str[6]; + uint8_t key[16], data[16]; + cast5_ctx_t ctx; + + calibrateTimer(); + print_overhead(); + + memset(key, 0, 16); + memset(data, 0, 16); + + startTimer(1); + cast5_init(key, 128, &ctx); + t = stopTimer(); + uart_putstr_P(PSTR("\r\n\tctx-gen time: ")); + ultoa((unsigned long)t, str, 10); + uart_putstr(str); + + + startTimer(1); + cast5_enc(data, &ctx); + t = stopTimer(); + uart_putstr_P(PSTR("\r\n\tencrypt time: ")); + ultoa((unsigned long)t, str, 10); + uart_putstr(str); + + + startTimer(1); + cast5_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 * + *****************************************************************************/ + +int main (void){ + char str[20]; + + + DEBUG_INIT(); + uart_putstr("\r\n"); + + 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[] = {testrun_nessie_cast5, testrun_cast5, testrun_performance_cast5}; + + while(1){ + 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"); + } +} + diff --git a/test_src/main-des-test.c b/test_src/main-des-test.c new file mode 100644 index 0000000..714781c --- /dev/null +++ b/test_src/main-des-test.c @@ -0,0 +1,123 @@ +/* main-des-test.c */ +/* + This file is part of the Crypto-avr-lib/microcrypt-lib. + Copyright (C) 2008 Daniel Otte (daniel.otte@rub.de) + + This program is free software: you can redistribute it and/or modify + it under the terms of the GNU General Public License as published by + the Free Software Foundation, either version 3 of the License, or + (at your option) any later version. + + This program is distributed in the hope that it will be useful, + but WITHOUT ANY WARRANTY; without even the implied warranty of + MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + GNU General Public License for more details. + + You should have received a copy of the GNU General Public License + along with this program. If not, see . +*/ +/* + * des test-suit + * +*/ + +#include "config.h" +#include "serial-tools.h" +#include "uart.h" +#include "debug.h" + +#include "des.h" +#include "nessie_bc_test.h" +#include "cli.h" +#include "performance_test.h" + +#include +#include +#include + +char* cipher_name = "DES"; + +/***************************************************************************** + * additional validation-functions * + *****************************************************************************/ +void des_init_dummy(const void* key, uint16_t keysize_b, void* ctx){ + memcpy(ctx, key, 8); +} + +void des_enc_dummy(void* buffer, void* ctx){ + des_enc(buffer, buffer, ctx); +} + +void des_dec_dummy(void* buffer, void* ctx){ + des_dec(buffer, buffer, ctx); +} + +void testrun_nessie_des(void){ + nessie_bc_init(); + nessie_bc_ctx.blocksize_B = 8; + nessie_bc_ctx.keysize_b = 64; + nessie_bc_ctx.name = cipher_name; + nessie_bc_ctx.ctx_size_B = 8; + nessie_bc_ctx.cipher_enc = (nessie_bc_enc_fpt)des_enc_dummy; + nessie_bc_ctx.cipher_dec = (nessie_bc_dec_fpt)des_dec_dummy; + nessie_bc_ctx.cipher_genctx = (nessie_bc_gen_fpt)des_init_dummy; + + nessie_bc_run(); +} + + +void testrun_performance_des(void){ + uint64_t t; + char str[16]; + uint8_t key[8], data[8]; + + + calibrateTimer(); + print_overhead(); + + memset(key, 0, 8); + memset(data, 0, 8); + + startTimer(1); + des_enc(data, data, key); + t = stopTimer(); + uart_putstr_P(PSTR("\r\n\tencrypt time: ")); + ultoa((unsigned long)t, str, 10); + uart_putstr(str); + + startTimer(1); + des_dec(data, data, key); + 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 + *****************************************************************************/ + +int main (void){ + char str[20]; + DEBUG_INIT(); + uart_putstr("\r\n"); + + 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[] = {testrun_nessie_des, testrun_nessie_des, testrun_performance_des}; + + while(1){ + 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"); + } + +} + diff --git a/test_src/main-entropium-test.c b/test_src/main-entropium-test.c new file mode 100644 index 0000000..3384396 --- /dev/null +++ b/test_src/main-entropium-test.c @@ -0,0 +1,116 @@ +/* main-entropium-test.c */ +/* + This file is part of the Crypto-avr-lib/microcrypt-lib. + Copyright (C) 2008 Daniel Otte (daniel.otte@rub.de) + + This program is free software: you can redistribute it and/or modify + it under the terms of the GNU General Public License as published by + the Free Software Foundation, either version 3 of the License, or + (at your option) any later version. + + This program is distributed in the hope that it will be useful, + but WITHOUT ANY WARRANTY; without even the implied warranty of + MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + GNU General Public License for more details. + + You should have received a copy of the GNU General Public License + along with this program. If not, see . +*/ +/* + * entropium test-suit + * +*/ + +#include "config.h" +#include "serial-tools.h" +#include "uart.h" +#include "debug.h" + +#include "entropium.h" +#include "nessie_bc_test.h" +#include "cli.h" +#include "performance_test.h" + +#include +#include +#include + +char* cipher_name = "Entropium"; + +/***************************************************************************** + * additional validation-functions * + *****************************************************************************/ + +void testrun_entropium(void){ + char c, str[16]; + uint8_t data[32]; + uint32_t i=0; + while(!uart_getc_nb(&c)){ + entropium_getRandomBlock(data); + uart_putstr_P(PSTR("\r\n ")); + ultoa(i, str, 10); + for(c=strlen(str); c<11; ++c){ + uart_putc(' '); + } + uart_putstr(str); + ++i; + uart_putstr_P(PSTR(" : ")); + uart_hexdump(data, 32); + } + uart_putstr_P(PSTR("\r\n\r\n")); +} + + +void testrun_performance_entropium(void){ + uint64_t t; + char str[16]; + uint8_t data[32]; + + calibrateTimer(); + print_overhead(); + + startTimer(1); + entropium_addEntropy(128, data); + t = stopTimer(); + uart_putstr_P(PSTR("\r\n\tadd entropy time: ")); + ultoa((unsigned long)t, str, 10); + uart_putstr(str); + + + startTimer(1); + entropium_getRandomBlock(data); + t = stopTimer(); + uart_putstr_P(PSTR("\r\n\tget random time: ")); + ultoa((unsigned long)t, str, 10); + uart_putstr(str); + + uart_putstr_P(PSTR("\r\n")); +} +/***************************************************************************** + * main * + *****************************************************************************/ + +int main (void){ + char str[20]; + DEBUG_INIT(); + uart_putstr("\r\n"); + + 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[] = {testrun_entropium, testrun_entropium, testrun_performance_entropium}; + + while(1){ + 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"); + } + +} + diff --git a/test_src/main-grain-test.c b/test_src/main-grain-test.c new file mode 100644 index 0000000..44f08f8 --- /dev/null +++ b/test_src/main-grain-test.c @@ -0,0 +1,180 @@ +/* main-grain-test.c */ +/* + This file is part of the Crypto-avr-lib/microcrypt-lib. + Copyright (C) 2008 Daniel Otte (daniel.otte@rub.de) + + This program is free software: you can redistribute it and/or modify + it under the terms of the GNU General Public License as published by + the Free Software Foundation, either version 3 of the License, or + (at your option) any later version. + + This program is distributed in the hope that it will be useful, + but WITHOUT ANY WARRANTY; without even the implied warranty of + MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + GNU General Public License for more details. + + You should have received a copy of the GNU General Public License + along with this program. If not, see . +*/ +/* + * grain test-suit + * +*/ + +#include "config.h" +#include "serial-tools.h" +#include "uart.h" +#include "debug.h" +#include "cli.h" + +#include "grain.h" +#include "nessie_stream_test.h" +#include "performance_test.h" + +#include +#include +#include + +char* cipher_name = "Grain"; + +/***************************************************************************** + * additional validation-functions * + *****************************************************************************/ +void grain_genctx_dummy(uint8_t* key, uint16_t keysize_b, void* ctx){ + uint8_t iv[8]={0}; + grain_init(key, &iv, ctx); +} + +uint8_t grain_getbyte_dummy(grain_ctx_t* ctx){ + uint8_t i,ret=0; + for(i=0; i<8; ++i){ + ret<<=1; + ret |= grain_enc(ctx); + } + return ret; +} + +uint8_t grain_getbyte_dummy_rev(grain_ctx_t* ctx){ + uint8_t i,ret=0; + for(i=0; i<8; ++i){ + ret >>= 1; + ret |= grain_enc(ctx)?0x80:0x00; + } + return ret; +} + +void testrun_nessie_grain(void){ + nessie_stream_ctx.outsize_b = 8; /* actually unused */ + nessie_stream_ctx.keysize_b = 80; /* this is the one we have refrence vectors for */ + nessie_stream_ctx.ivsize_b = 64; + nessie_stream_ctx.name = cipher_name; + nessie_stream_ctx.ctx_size_B = sizeof(grain_ctx_t); + nessie_stream_ctx.cipher_genctx = (nessie_stream_genctx_fpt)grain_genctx_dummy; + nessie_stream_ctx.cipher_enc = (nessie_stream_genenc_fpt)grain_getbyte_dummy_rev; + + nessie_stream_run(); +} + + +void testrun_std_grain(void){ + grain_ctx_t ctx; + uint8_t i, key[10], iv[8], out[10]; + + /* 1 */ + memset(key, 0, 10); + memset(iv, 0, 8); + uart_putstr_P(PSTR("\r\n=== std test ===")); + uart_putstr_P(PSTR("\r\n key: ")); + uart_hexdump(key, 10); + uart_putstr_P(PSTR("\r\n iv: ")); + uart_hexdump(key, 8); + grain_init(key, iv, &ctx); + for(i=0; i<10; ++i){ + out[i] = grain_getbyte_dummy(&ctx); + } + uart_putstr_P(PSTR("\r\n out: ")); + uart_hexdump(out, 10); + + /* 2 */ + for(i=0; i<8; ++i){ + key[i] = i*0x22+1; + } + key[8]=0x12; + key[9]=0x34; + + for(i=0; i<8; ++i){ + iv[i] = i*0x22+1; + } + uart_putstr_P(PSTR("\r\n\r\n key: ")); + uart_hexdump(key, 10); + uart_putstr_P(PSTR("\r\n iv: ")); + uart_hexdump(key, 8); + grain_init(key, iv, &ctx); + for(i=0; i<10; ++i){ + out[i] = grain_getbyte_dummy(&ctx); + } + uart_putstr_P(PSTR("\r\n out: ")); + uart_hexdump(out, 10); + + + uart_putstr_P(PSTR("\r\n\r\n")); +} + +void testrun_performance_grain(void){ + uint64_t t; + char str[16]; + uint8_t key[10], iv[8]; + grain_ctx_t ctx; + + calibrateTimer(); + print_overhead(); + + memset(key, 0, 10); + memset(iv, 0, 8); + + startTimer(1); + grain_init(key, iv, &ctx); + t = stopTimer(); + uart_putstr_P(PSTR("\r\n\tctx-gen time: ")); + ultoa((unsigned long)t, str, 10); + uart_putstr(str); + + startTimer(1); + grain_enc(&ctx); + t = stopTimer(); + uart_putstr_P(PSTR("\r\n\tencrypt time: ")); + ultoa((unsigned long)t, str, 10); + uart_putstr(str); + + uart_putstr_P(PSTR("\r\n")); +} + +/***************************************************************************** + * main * + *****************************************************************************/ + +int main (void){ + char str[20]; + DEBUG_INIT(); + uart_putstr("\r\n"); + + 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[] = {testrun_nessie_grain, testrun_std_grain, testrun_performance_grain}; + + while(1){ + 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"); + } +} + + + diff --git a/test_src/main-hmac-sha1-test.c b/test_src/main-hmac-sha1-test.c new file mode 100644 index 0000000..2a786df --- /dev/null +++ b/test_src/main-hmac-sha1-test.c @@ -0,0 +1,100 @@ +/* main-hmac-sha1-test.c */ +/* + This file is part of the Crypto-avr-lib/microcrypt-lib. + Copyright (C) 2008 Daniel Otte (daniel.otte@rub.de) + + This program is free software: you can redistribute it and/or modify + it under the terms of the GNU General Public License as published by + the Free Software Foundation, either version 3 of the License, or + (at your option) any later version. + + This program is distributed in the hope that it will be useful, + but WITHOUT ANY WARRANTY; without even the implied warranty of + MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + GNU General Public License for more details. + + You should have received a copy of the GNU General Public License + along with this program. If not, see . +*/ +/* + * HMAC-SHA1 test-suit + * +*/ + +#include "config.h" +#include "serial-tools.h" +#include "uart.h" +#include "debug.h" + +#include "sha1.h" +#include "hmac-sha1.h" + +#include "nessie_mac_test.h" + +#include +#include +#include "cli.h" + +char* algo_name = "HMAC-SHA1"; + +/***************************************************************************** + * additional validation-functions * + *****************************************************************************/ +void hmacsha1_next_dummy(void* buffer, void* ctx){ + sha1_nextBlock(ctx, buffer); +} + +void hmacsha1_init_dummy(void* key, uint16_t keysize_b, void* ctx){ + hmac_sha1_init(ctx, key, keysize_b); +} + +void hmacsha1_last_dummy(void* buffer, uint16_t size_b, void* key, uint16_t keysize_b, void* ctx){ + sha1_lastBlock(ctx, buffer, size_b); + hmac_sha1_final(ctx, key, keysize_b); +} + +void testrun_nessie_hmacsha1(void){ + nessie_mac_ctx.macsize_b = 160; + nessie_mac_ctx.keysize_b = 512; + nessie_mac_ctx.blocksize_B = 512/8; + nessie_mac_ctx.ctx_size_B = sizeof(hmac_sha1_ctx_t); + nessie_mac_ctx.name = algo_name; + nessie_mac_ctx.mac_init = (nessie_mac_init_fpt)hmacsha1_init_dummy; + nessie_mac_ctx.mac_next = (nessie_mac_next_fpt)hmacsha1_next_dummy; + nessie_mac_ctx.mac_last = (nessie_mac_last_fpt)hmacsha1_last_dummy; + nessie_mac_ctx.mac_conv = (nessie_mac_conv_fpt)sha1_ctx2hash; + + nessie_mac_run(); +} + + + +/***************************************************************************** + * main * + *****************************************************************************/ + +int main (void){ + char str[20]; + DEBUG_INIT(); + uart_putstr("\r\n"); + + uart_putstr_P(PSTR("\r\n\r\nCrypto-VS (")); + uart_putstr(algo_name); + uart_putstr_P(PSTR(")\r\nloaded and running\r\n")); + + PGM_P u = PSTR("nessie\0test\0"); + void_fpt v[] = {testrun_nessie_hmacsha1, testrun_nessie_hmacsha1}; + + while(1){ + 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"); + } + + +} + diff --git a/test_src/main-hmac-sha256-test.c b/test_src/main-hmac-sha256-test.c new file mode 100644 index 0000000..819ed57 --- /dev/null +++ b/test_src/main-hmac-sha256-test.c @@ -0,0 +1,96 @@ +/* main-hmac-sha256-test.c */ +/* + This file is part of the Crypto-avr-lib/microcrypt-lib. + Copyright (C) 2008 Daniel Otte (daniel.otte@rub.de) + + This program is free software: you can redistribute it and/or modify + it under the terms of the GNU General Public License as published by + the Free Software Foundation, either version 3 of the License, or + (at your option) any later version. + + This program is distributed in the hope that it will be useful, + but WITHOUT ANY WARRANTY; without even the implied warranty of + MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + GNU General Public License for more details. + + You should have received a copy of the GNU General Public License + along with this program. If not, see . +*/ +/* + * HMAC-SHA256 test-suit + * +*/ + +#include "config.h" +#include "serial-tools.h" +#include "uart.h" +#include "debug.h" + +#include "sha256.h" +#include "hmac-sha256.h" + +#include "nessie_mac_test.h" + +#include +#include + +char* algo_name = "HMAC-SHA256"; + +/***************************************************************************** + * additional validation-functions * + *****************************************************************************/ +void hmacsha256_next_dummy(void* buffer, void* ctx){ + sha256_nextBlock(ctx, buffer); +} + +void hmacsha256_init_dummy(void* key, uint16_t keysize_b, void* ctx){ + hmac_sha256_init(ctx, key, keysize_b); +} + +void hmacsha256_last_dummy(void* buffer, uint16_t size_b, void* key, uint16_t keysize_b, void* ctx){ + sha256_lastBlock(ctx, buffer, size_b); + hmac_sha256_final(ctx, key, keysize_b); +} + +void testrun_nessie_hmacsha256(void){ + nessie_mac_ctx.macsize_b = 256; + nessie_mac_ctx.keysize_b = 512; + nessie_mac_ctx.blocksize_B = 512/8; + nessie_mac_ctx.ctx_size_B = sizeof(hmac_sha256_ctx_t); + nessie_mac_ctx.name = algo_name; + nessie_mac_ctx.mac_init = (nessie_mac_init_fpt)hmacsha256_init_dummy; + nessie_mac_ctx.mac_next = (nessie_mac_next_fpt)hmacsha256_next_dummy; + nessie_mac_ctx.mac_last = (nessie_mac_last_fpt)hmacsha256_last_dummy; + nessie_mac_ctx.mac_conv = (nessie_mac_conv_fpt)sha256_ctx2hash; + + nessie_mac_run(); +} + + + +/***************************************************************************** + * main * + *****************************************************************************/ + +int main (void){ + char str[20]; + DEBUG_INIT(); + uart_putstr("\r\n"); + + uart_putstr_P(PSTR("\r\n\r\nCrypto-VS (")); + uart_putstr(algo_name); + uart_putstr_P(PSTR(")\r\nloaded and running\r\n")); + +restart: + 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_hmacsha256(); + goto restart; + continue; + error: + uart_putstr("ERROR\r\n"); + } + +} + diff --git a/test_src/main-md5-test.c b/test_src/main-md5-test.c new file mode 100644 index 0000000..490ee48 --- /dev/null +++ b/test_src/main-md5-test.c @@ -0,0 +1,168 @@ +/* main-md5-test.c */ +/* + This file is part of the Crypto-avr-lib/microcrypt-lib. + Copyright (C) 2008 Daniel Otte (daniel.otte@rub.de) + + This program is free software: you can redistribute it and/or modify + it under the terms of the GNU General Public License as published by + the Free Software Foundation, either version 3 of the License, or + (at your option) any later version. + + This program is distributed in the hope that it will be useful, + but WITHOUT ANY WARRANTY; without even the implied warranty of + MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + GNU General Public License for more details. + + You should have received a copy of the GNU General Public License + along with this program. If not, see . +*/ +/* + * md5 test suit + * +*/ + +#include "config.h" +#include "serial-tools.h" +#include "uart.h" +#include "debug.h" + +#include "md5.h" +#include "nessie_hash_test.h" +#include "performance_test.h" + +#include +#include +#include +#include "cli.h" + +char* algo_name = "MD5"; + +/***************************************************************************** + * additional validation-functions * + *****************************************************************************/ +void md5_next_dummy(void* buffer, void* ctx){ + md5_nextBlock(ctx, buffer); +} + +void md5_last_dummy(void* buffer, uint16_t size_b, void* ctx){ + md5_lastBlock(ctx, buffer, size_b); +} + +void md5_ctx2hash_dummy(void* buffer, void* ctx){ + memcpy(buffer, ctx, 16); +} + + +void testrun_nessie_md5(void){ + nessie_hash_ctx.hashsize_b = 128; + nessie_hash_ctx.blocksize_B = 512/8; + nessie_hash_ctx.ctx_size_B = sizeof(md5_ctx_t); + nessie_hash_ctx.name = algo_name; + nessie_hash_ctx.hash_init = (nessie_hash_init_fpt)md5_init; + nessie_hash_ctx.hash_next = (nessie_hash_next_fpt)md5_next_dummy; + nessie_hash_ctx.hash_last = (nessie_hash_last_fpt)md5_last_dummy; + nessie_hash_ctx.hash_conv = (nessie_hash_conv_fpt)md5_ctx2hash_dummy; + + nessie_hash_run(); +} + +/***************************************************************************** + * self tests * + *****************************************************************************/ + +/* + * MD5 test suite: + * MD5 ("") = d41d8cd98f00b204e9800998ecf8427e + * MD5 ("a") = 0cc175b9c0f1b6a831c399e269772661 + * MD5 ("abc") = 900150983cd24fb0d6963f7d28e17f72 + * MD5 ("message digest") = f96b697d7cb7938d525a2f31aaf161d0 + * MD5 ("abcdefghijklmnopqrstuvwxyz") = c3fcd3d76192e4007dfb496cca67e13b + * MD5 ("ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789") = + * d174ab98d277d9f5a5611c2c9f419d9f + * MD5 ("123456789012345678901234567890123456789012345678901234567890123456 + * 78901234567890") = 57edf4a22be3c955ac49da2e2107b67a + */ + +void testrun_md5(void){ + md5_ctx_t s; + char* testv[]={"", "a", "abc", "message digest", "abcdefghijklmnopqrstuvwxyz", + "ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789", + "12345678901234567890123456789012345678901234567890123456789012345678901234567890"}; + uint8_t i; + + uart_putstr("\r\n=== MD5 test suit ==="); + for(i=0; i<7; ++i){ + uart_putstr("\r\n MD5 (\""); + uart_putstr(testv[i]); + uart_putstr("\") = \r\n"); + md5_init(&s); + md5_lastBlock(&s, testv[i], strlen(testv[i])*8); + uart_hexdump(&s.a[0], 16); + } +} + + +void testrun_performance_md5(void){ + uint64_t t; + char str[16]; + uint8_t data[32]; + md5_ctx_t ctx; + + calibrateTimer(); + print_overhead(); + + memset(data, 0, 32); + + startTimer(1); + md5_init(&ctx); + t = stopTimer(); + uart_putstr_P(PSTR("\r\n\tctx-gen time: ")); + ultoa((unsigned long)t, str, 10); + uart_putstr(str); + + + startTimer(1); + md5_nextBlock(&ctx, data); + t = stopTimer(); + uart_putstr_P(PSTR("\r\n\tone-block time: ")); + ultoa((unsigned long)t, str, 10); + uart_putstr(str); + + + startTimer(1); + md5_lastBlock(&ctx, data, 0); + t = stopTimer(); + uart_putstr_P(PSTR("\r\n\tlast block time: ")); + ultoa((unsigned long)t, str, 10); + uart_putstr(str); + + uart_putstr_P(PSTR("\r\n")); +} + + +/***************************************************************************** + * main * + *****************************************************************************/ + +int main (void){ + char str[20]; + + + DEBUG_INIT(); + uart_putstr("\r\n"); + + uart_putstr("\r\n\r\nCrypto-VS (MD5)\r\nloaded and running\r\n"); + PGM_P u = PSTR("nessie\0test\0performance\0"); + void_fpt v[] = {testrun_nessie_md5, testrun_md5, testrun_performance_md5}; + + while(1){ + 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"); + } +} + diff --git a/test_src/main-noekeon-test.c b/test_src/main-noekeon-test.c new file mode 100644 index 0000000..851c7bc --- /dev/null +++ b/test_src/main-noekeon-test.c @@ -0,0 +1,241 @@ +/* main-noekeon-test.c */ +/* + This file is part of the Crypto-avr-lib/microcrypt-lib. + Copyright (C) 2008 Daniel Otte (daniel.otte@rub.de) + + This program is free software: you can redistribute it and/or modify + it under the terms of the GNU General Public License as published by + the Free Software Foundation, either version 3 of the License, or + (at your option) any later version. + + This program is distributed in the hope that it will be useful, + but WITHOUT ANY WARRANTY; without even the implied warranty of + MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + GNU General Public License for more details. + + You should have received a copy of the GNU General Public License + along with this program. If not, see . +*/ +/* + * serpent test-suit + * +*/ + +#include "config.h" +#include "serial-tools.h" +#include "uart.h" +#include "debug.h" + +#include "noekeon.h" +#include "nessie_bc_test.h" +#include "cli.h" +#include "performance_test.h" + +#include +#include +#include + +char* cipher_name = "Noekeon"; + +/***************************************************************************** + * additional validation-functions * + *****************************************************************************/ +void noekeon_genctx_dummy(uint8_t* key, uint16_t keysize, void* ctx){ + noekeon_init(key, ctx); +} + +void testrun_nessie_noekeon_indirect(void){ + char str[strlen(cipher_name)+10]; + strcpy(str, cipher_name); + strcat(str, "-indirect"); + + nessie_bc_ctx.blocksize_B = 16; + nessie_bc_ctx.keysize_b = 128; + nessie_bc_ctx.name = str; + nessie_bc_ctx.ctx_size_B = sizeof(noekeon_ctx_t); + nessie_bc_ctx.cipher_enc = (nessie_bc_enc_fpt)noekeon_enc; + nessie_bc_ctx.cipher_dec = (nessie_bc_dec_fpt)noekeon_dec; + nessie_bc_ctx.cipher_genctx = (nessie_bc_gen_fpt)noekeon_genctx_dummy; + + nessie_bc_run(); +} + +void noekeon_genctx_dummy_direct(uint8_t* key, uint16_t keysize, void* ctx){ + memcpy(ctx, key, 16); +} + +void testrun_nessie_noekeon_direct(void){ + char str[strlen(cipher_name)+10]; + strcpy(str, cipher_name); + strcat(str, "-Direct"); + + nessie_bc_ctx.blocksize_B = 16; + nessie_bc_ctx.keysize_b = 128; + nessie_bc_ctx.name = str; + nessie_bc_ctx.ctx_size_B = sizeof(noekeon_ctx_t); + nessie_bc_ctx.cipher_enc = (nessie_bc_enc_fpt)noekeon_enc; + nessie_bc_ctx.cipher_dec = (nessie_bc_dec_fpt)noekeon_dec; + nessie_bc_ctx.cipher_genctx = (nessie_bc_gen_fpt)noekeon_genctx_dummy_direct; + + nessie_bc_run(); +} + +void testrun_nessie_noekeon(void){ + testrun_nessie_noekeon_direct(); + testrun_nessie_noekeon_indirect(); +} + + +void testrun_stdtest_rundirect(void* data, void* key){ + uart_putstr_P(PSTR("\r\n ")); + uart_putstr_P(PSTR("k = ")); + uart_hexdump(key,16); + + uart_putstr_P(PSTR("\r\n ")); + uart_putstr_P(PSTR("a = ")); + uart_hexdump(data,16); + + noekeon_enc(data, key); + uart_putstr_P(PSTR("\r\nafter NESSIEencrypt, b = ")); + uart_hexdump(data,16); + + noekeon_dec(data, key); + uart_putstr_P(PSTR("\r\nafter NESSIEdecrypt, a?= ")); + uart_hexdump(data,16); + uart_putstr_P(PSTR("\r\n")); +} + +void testrun_stdtest_runindirect(void* data, void* key){ + noekeon_ctx_t ctx; + uart_putstr_P(PSTR("\r\n ")); + uart_putstr_P(PSTR("k = ")); + uart_hexdump(key,16); + + uart_putstr_P(PSTR("\r\n ")); + uart_putstr_P(PSTR("a = ")); + uart_hexdump(data,16); + noekeon_init(key, &ctx); + noekeon_enc(data, &ctx); + uart_putstr_P(PSTR("\r\nafter NESSIEencrypt, b = ")); + uart_hexdump(data,16); + + noekeon_dec(data, &ctx); + uart_putstr_P(PSTR("\r\nafter NESSIEdecrypt, a?= ")); + uart_hexdump(data,16); + uart_putstr_P(PSTR("\r\n")); +} + +void testrun_stdtest_noekeon(void){ + uint8_t key[16], data[16]; + uint8_t key3[16]; + noekeon_ctx_t ctx; + + uart_putstr_P(PSTR("\r\nTest vectors for block cipher Noekeon in Indirect-Key Mode:\r\n")); + + memset(key, 0, 16); + memset(data, 0, 16); + testrun_stdtest_runindirect(data, key); + + memset(key, 0xFF, 16); + memset(data, 0xFF, 16); + testrun_stdtest_runindirect(data, key); + + memset(key, 0, 16); + memset(data, 0, 16); + noekeon_init(key, &ctx); + noekeon_enc(data, &ctx); + memcpy(key3, data, 16); + memset(key, 0xFF, 16); + memset(data, 0xFF, 16); + noekeon_init(key, &ctx); + noekeon_enc(data, &ctx); + testrun_stdtest_runindirect(data, key3); + + uart_putstr_P(PSTR("\r\nTest vectors for block cipher Noekeon in Direct-Key Mode:\r\n")); + + memset(key, 0, 16); + memset(data, 0, 16); + testrun_stdtest_rundirect(data, key); + + memset(key, 0xFF, 16); + memset(data, 0xFF, 16); + testrun_stdtest_rundirect(data, key); + + memset(key, 0, 16); + memset(data, 0, 16); + noekeon_enc(data, key); + memcpy(key3, data, 16); + memset(key, 0xFF, 16); + memset(data, 0xFF, 16); + noekeon_enc(data, key); + testrun_stdtest_rundirect(data, key3); + +} + +void testrun_performance_noekeon(void){ + uint64_t t; + char str[16]; + uint8_t key[16], data[16]; + noekeon_ctx_t ctx; + + calibrateTimer(); + print_overhead(); + + memset(key, 0, 16); + memset(data, 0, 16); + + startTimer(1); + noekeon_init(key, &ctx); + t = stopTimer(); + uart_putstr_P(PSTR("\r\n\tctx-gen time: ")); + ultoa((unsigned long)t, str, 10); + uart_putstr(str); + + startTimer(1); + noekeon_enc(data, &ctx); + t = stopTimer(); + uart_putstr_P(PSTR("\r\n\tencrypt time: ")); + ultoa((unsigned long)t, str, 10); + uart_putstr(str); + + startTimer(1); + noekeon_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 * + *****************************************************************************/ + +int main (void){ + char str[20]; + DEBUG_INIT(); + uart_putstr("\r\n"); + + 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\0direct\0indirect\0performance\0"); + void_fpt v[] = {testrun_nessie_noekeon, + testrun_stdtest_noekeon, + testrun_nessie_noekeon_direct, + testrun_nessie_noekeon_indirect, + testrun_performance_noekeon}; + + while(1){ + 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"); + } + +} + diff --git a/test_src/main-present-test.c b/test_src/main-present-test.c new file mode 100644 index 0000000..4c739bc --- /dev/null +++ b/test_src/main-present-test.c @@ -0,0 +1,152 @@ +/* main-present-test.c */ +/* + This file is part of the Crypto-avr-lib/microcrypt-lib. + Copyright (C) 2008 Daniel Otte (daniel.otte@rub.de) + + This program is free software: you can redistribute it and/or modify + it under the terms of the GNU General Public License as published by + the Free Software Foundation, either version 3 of the License, or + (at your option) any later version. + + This program is distributed in the hope that it will be useful, + but WITHOUT ANY WARRANTY; without even the implied warranty of + MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + GNU General Public License for more details. + + You should have received a copy of the GNU General Public License + along with this program. If not, see . +*/ +/* + * present test-suit + * +*/ + +#include "config.h" +#include "serial-tools.h" +#include "uart.h" +#include "debug.h" + +#include "present.h" +#include "nessie_bc_test.h" +#include "cli.h" +#include "performance_test.h" + +#include +#include +#include + +char* cipher_name = "Present"; + +/***************************************************************************** + * additional validation-functions * + *****************************************************************************/ +void present_genctx_dummy(uint8_t* key, uint16_t keysize_b, present_ctx_t* ctx){ + present_init(key, keysize_b, ctx); +} + +void testrun_nessie_present(void){ + nessie_bc_ctx.blocksize_B = 8; + nessie_bc_ctx.keysize_b = 80; + nessie_bc_ctx.name = cipher_name; + nessie_bc_ctx.ctx_size_B = sizeof(present_ctx_t); + nessie_bc_ctx.cipher_enc = (nessie_bc_enc_fpt)present_enc; + nessie_bc_ctx.cipher_dec = (nessie_bc_dec_fpt)present_dec; + nessie_bc_ctx.cipher_genctx = (nessie_bc_gen_fpt)present_genctx_dummy; + + nessie_bc_run(); +} + +void testrun_selfenc(uint8_t* key, uint8_t* buffer){ + present_ctx_t ctx; + uart_putstr_P(PSTR("\r\nkey : ")); + uart_hexdump(key, 10); + uart_putstr_P(PSTR("\r\nplain : ")); + uart_hexdump(buffer, 8); + present_init(key, 80, &ctx); + present_enc(buffer, &ctx); + uart_putstr_P(PSTR("\r\ncipher: ")); + uart_hexdump(buffer, 8); + present_dec(buffer, &ctx); + uart_putstr_P(PSTR("\r\nplain : ")); + uart_hexdump(buffer, 8); + uart_putstr_P(PSTR("\r\n")); +} + +void testrun_self_present(void){ + uint8_t buffer[8], key[10]; + uart_putstr_P(PSTR("\r\n\r\n=== Testvectors from the paper ===\r\n")); + + memset(buffer, 0, 8); + memset(key, 0, 10); + testrun_selfenc(key, buffer); + + memset(buffer, 0, 8); + memset(key, 0xFF, 10); + testrun_selfenc(key, buffer); + + memset(buffer, 0xFF, 8); + memset(key, 0, 10); + testrun_selfenc(key, buffer); + + memset(buffer, 0xFF, 8); + memset(key, 0xFF, 10); + testrun_selfenc(key, buffer); + +} + +void testrun_performance_present(void){ + uint64_t t; + uint8_t key[10], data[8]; + present_ctx_t ctx; + + calibrateTimer(); + print_overhead(); + + memset(key, 0, 10); + memset(data, 0, 8); + + startTimer(1); + present_init(key, 80, &ctx); + t = stopTimer(); + print_time_P(PSTR("\tctx-gen time: "),t); + + startTimer(1); + present_enc(data, &ctx); + t = stopTimer(); + print_time_P(PSTR("\tencrypt time: "), t); + + startTimer(1); + present_dec(data, &ctx); + t = stopTimer(); + print_time_P(PSTR("\tdecrypt time: "), t); + + uart_putstr_P(PSTR("\r\n")); +} + +/***************************************************************************** + * main * + *****************************************************************************/ + +int main (void){ + char str[20]; + DEBUG_INIT(); + uart_putstr("\r\n"); + + 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[] = {testrun_nessie_present, testrun_self_present, testrun_performance_present}; + + while(1){ + 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"); + } + +} diff --git a/test_src/main-rc5-test.c b/test_src/main-rc5-test.c new file mode 100644 index 0000000..2c16aea --- /dev/null +++ b/test_src/main-rc5-test.c @@ -0,0 +1,131 @@ +/* main-rc5-test.c */ +/* + This file is part of the Crypto-avr-lib/microcrypt-lib. + Copyright (C) 2008 Daniel Otte (daniel.otte@rub.de) + + This program is free software: you can redistribute it and/or modify + it under the terms of the GNU General Public License as published by + the Free Software Foundation, either version 3 of the License, or + (at your option) any later version. + + This program is distributed in the hope that it will be useful, + but WITHOUT ANY WARRANTY; without even the implied warranty of + MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + GNU General Public License for more details. + + You should have received a copy of the GNU General Public License + along with this program. If not, see . +*/ +/* + * rc5 test-suit + * +*/ + +#include "config.h" +#include "serial-tools.h" +#include "uart.h" +#include "debug.h" + +#include "rc5.h" +#include "nessie_bc_test.h" +#include "cli.h" +#include "performance_test.h" + +#include +#include +#include + +#define RC5_ROUNDS 12 +char* cipher_name = "RC5-32/12/16"; + +/***************************************************************************** + * additional validation-functions * + *****************************************************************************/ +void rc5_genctx_dummy(uint8_t* key, uint16_t keysize_b, void* ctx){ + rc5_init(key, keysize_b, RC5_ROUNDS, ctx); +} + +void testrun_nessie_rc5(void){ + nessie_bc_init(); + nessie_bc_ctx.blocksize_B = 8; + nessie_bc_ctx.keysize_b = 128; + nessie_bc_ctx.name = cipher_name; + nessie_bc_ctx.ctx_size_B = sizeof(rc5_ctx_t); + nessie_bc_ctx.cipher_enc = (nessie_bc_enc_fpt)rc5_enc; + nessie_bc_ctx.cipher_dec = (nessie_bc_dec_fpt)rc5_dec; + nessie_bc_ctx.cipher_free = (nessie_bc_free_fpt)rc5_free; + nessie_bc_ctx.cipher_genctx = (nessie_bc_gen_fpt)rc5_genctx_dummy; + + nessie_bc_run(); +} + + +void testrun_performance_rc5(void){ + uint64_t t; + char str[16]; + uint8_t key[16], data[16]; + rc5_ctx_t ctx; + + calibrateTimer(); + print_overhead(); + + memset(key, 0, 16); + memset(data, 0, 16); + + startTimer(1); + rc5_init(key, 128, RC5_ROUNDS, &ctx); + t = stopTimer(); + uart_putstr_P(PSTR("\r\n\tctx-gen time: ")); + ultoa((unsigned long)t, str, 10); + uart_putstr(str); + + startTimer(1); + rc5_enc(data, &ctx); + t = stopTimer(); + uart_putstr_P(PSTR("\r\n\tencrypt time: ")); + ultoa((unsigned long)t, str, 10); + uart_putstr(str); + + startTimer(1); + rc5_dec(data, &ctx); + t = stopTimer(); + uart_putstr_P(PSTR("\r\n\tdecrypt time: ")); + ultoa((unsigned long)t, str, 10); + uart_putstr(str); + + startTimer(1); + rc5_free(&ctx); + t = stopTimer(); + uart_putstr_P(PSTR("\r\n\tfree time: ")); + ultoa((unsigned long)t, str, 10); + uart_putstr(str); + uart_putstr_P(PSTR("\r\n")); +} +/***************************************************************************** + * main * + *****************************************************************************/ + +int main (void){ + char str[20]; + DEBUG_INIT(); + uart_putstr("\r\n"); + + 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[] = {testrun_nessie_rc5, testrun_nessie_rc5, testrun_performance_rc5}; + + while(1){ + 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"); + } + +} + diff --git a/test_src/main-rc6-test.c b/test_src/main-rc6-test.c new file mode 100644 index 0000000..5d7ecda --- /dev/null +++ b/test_src/main-rc6-test.c @@ -0,0 +1,138 @@ +/* main-rc6-test.c */ +/* + This file is part of the Crypto-avr-lib/microcrypt-lib. + Copyright (C) 2008 Daniel Otte (daniel.otte@rub.de) + + This program is free software: you can redistribute it and/or modify + it under the terms of the GNU General Public License as published by + the Free Software Foundation, either version 3 of the License, or + (at your option) any later version. + + This program is distributed in the hope that it will be useful, + but WITHOUT ANY WARRANTY; without even the implied warranty of + MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + GNU General Public License for more details. + + You should have received a copy of the GNU General Public License + along with this program. If not, see . +*/ +/* + * rc5 test-suit + * +*/ + +#include "config.h" +#include "serial-tools.h" +#include "uart.h" +#include "debug.h" + +#include "rc6.h" +#include "nessie_bc_test.h" +#include "cli.h" +#include "performance_test.h" + +#include +#include +#include + +#define RC6_ROUNDS 20 +char* cipher_name = "RC6-32/20/16"; + +/***************************************************************************** + * additional validation-functions * + *****************************************************************************/ +void rc6_genctx_dummy(uint8_t* key, uint16_t keysize_b, void* ctx){ + rc6_initl(key, keysize_b, RC6_ROUNDS, ctx); +} + +void testrun_nessie_rc6(void){ + nessie_bc_init(); + nessie_bc_ctx.blocksize_B = 16; + nessie_bc_ctx.keysize_b = 128; + nessie_bc_ctx.name = cipher_name; + nessie_bc_ctx.ctx_size_B = sizeof(rc6_ctx_t); + nessie_bc_ctx.cipher_enc = (nessie_bc_enc_fpt)rc6_enc; + nessie_bc_ctx.cipher_dec = (nessie_bc_dec_fpt)rc6_dec; + nessie_bc_ctx.cipher_free = (nessie_bc_free_fpt)rc6_free; + nessie_bc_ctx.cipher_genctx = (nessie_bc_gen_fpt)rc6_init; + + nessie_bc_run(); + + nessie_bc_ctx.keysize_b = 192; + nessie_bc_run(); + + nessie_bc_ctx.keysize_b = 256; + nessie_bc_run(); + +} + + +void testrun_performance_rc6(void){ + uint64_t t; + char str[16]; + uint8_t key[16], data[16]; + rc6_ctx_t ctx; + + calibrateTimer(); + print_overhead(); + + memset(key, 0, 16); + memset(data, 0, 16); + + startTimer(1); + rc6_init(key, 128, &ctx); + t = stopTimer(); + uart_putstr_P(PSTR("\r\n\tctx-gen time: ")); + ultoa((unsigned long)t, str, 10); + uart_putstr(str); + + startTimer(1); + rc6_enc(data, &ctx); + t = stopTimer(); + uart_putstr_P(PSTR("\r\n\tencrypt time: ")); + ultoa((unsigned long)t, str, 10); + uart_putstr(str); + + startTimer(1); + rc6_dec(data, &ctx); + t = stopTimer(); + uart_putstr_P(PSTR("\r\n\tdecrypt time: ")); + ultoa((unsigned long)t, str, 10); + uart_putstr(str); + + startTimer(1); + rc6_free(&ctx); + t = stopTimer(); + uart_putstr_P(PSTR("\r\n\tfree time: ")); + ultoa((unsigned long)t, str, 10); + uart_putstr(str); + uart_putstr_P(PSTR("\r\n")); +} +/***************************************************************************** + * main * + *****************************************************************************/ + +int main (void){ + char str[20]; + DEBUG_INIT(); + uart_putstr("\r\n"); + + 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[] = {testrun_nessie_rc6, testrun_nessie_rc6, testrun_performance_rc6}; + + while(1){ + 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"); + } + +} + diff --git a/test_src/main-seed-test.c b/test_src/main-seed-test.c new file mode 100644 index 0000000..678d132 --- /dev/null +++ b/test_src/main-seed-test.c @@ -0,0 +1,189 @@ +/* main-seed-test.c */ +/* + This file is part of the Crypto-avr-lib/microcrypt-lib. + Copyright (C) 2008 Daniel Otte (daniel.otte@rub.de) + + This program is free software: you can redistribute it and/or modify + it under the terms of the GNU General Public License as published by + the Free Software Foundation, either version 3 of the License, or + (at your option) any later version. + + This program is distributed in the hope that it will be useful, + but WITHOUT ANY WARRANTY; without even the implied warranty of + MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + GNU General Public License for more details. + + You should have received a copy of the GNU General Public License + along with this program. If not, see . +*/ +/** + * \file main-seed-test.c + * \author Daniel Otte + * \email daniel.otte@rub.de + * \date 2007-06-01 + * \brief test suit for SEED + * \par License + * GPLv3 or later + * + */ +#include "config.h" +#include "serial-tools.h" +#include "uart.h" +#include "debug.h" + +#include "seed.h" +#include "nessie_bc_test.h" +#include "cli.h" +#include "performance_test.h" + +#include +#include +#include + +char* cipher_name = "Seed"; + +/***************************************************************************** + * additional validation-functions * + *****************************************************************************/ +void seed_genctx_dummy(uint8_t* key, uint16_t keysize, void* ctx){ + seed_init(key, ctx); +} + +void testrun_nessie_seed(void){ + nessie_bc_ctx.blocksize_B = 16; + nessie_bc_ctx.keysize_b = 128; + nessie_bc_ctx.name = cipher_name; + nessie_bc_ctx.ctx_size_B = sizeof(seed_ctx_t); + nessie_bc_ctx.cipher_enc = (nessie_bc_enc_fpt)seed_enc; + nessie_bc_ctx.cipher_dec = (nessie_bc_dec_fpt)seed_dec; + nessie_bc_ctx.cipher_genctx = (nessie_bc_gen_fpt)seed_genctx_dummy; + + nessie_bc_run(); + +} + + +void testrun_performance_seed(void){ + uint64_t t; + char str[16]; + uint8_t key[16], data[16]; + seed_ctx_t ctx; + + calibrateTimer(); + print_overhead(); + + memset(key, 0, 16); + memset(data, 0, 16); + + startTimer(1); + seed_init(key, &ctx); + t = stopTimer(); + uart_putstr_P(PSTR("\r\n\tctx-gen time: ")); + ultoa((unsigned long)t, str, 10); + uart_putstr(str); + + + startTimer(1); + seed_enc(data, &ctx); + t = stopTimer(); + uart_putstr_P(PSTR("\r\n\tencrypt time: ")); + ultoa((unsigned long)t, str, 10); + uart_putstr(str); + + + startTimer(1); + seed_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")); +} + +/***************************************************************************** + * self tests * + *****************************************************************************/ + +void testencrypt(uint8_t* block, uint8_t* key){ + seed_ctx_t ctx; + uart_putstr("\r\n==testy-encrypt==\r\n key: "); + uart_hexdump(key,16); + seed_init(key, &ctx); + uart_putstr("\r\n plain: "); + uart_hexdump(block,16); + seed_enc(block, &ctx); + uart_putstr("\r\n crypt: "); + uart_hexdump(block,16); +} + +void testdecrypt(uint8_t* block, uint8_t* key){ + seed_ctx_t ctx; + uart_putstr("\r\n==testy-decrypt==\r\n key: "); + uart_hexdump(key,16); + seed_init(key, &ctx); + uart_putstr("\r\n crypt: "); + uart_hexdump(block,16); + seed_dec(block, &ctx); + uart_putstr("\r\n plain: "); + uart_hexdump(block,16); +} + +void testrun_seed(void){ + uint8_t keys[4][16]= + { { 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, + 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00 }, + { 0x00, 0x01, 0x02, 0x03, 0x04, 0x05, 0x06, 0x07, + 0x08, 0x09, 0x0a, 0x0b, 0x0c, 0x0d, 0x0e, 0x0f }, + { 0x47, 0x06, 0x48, 0x08, 0x51, 0xE6, 0x1B, 0xE8, + 0x5D, 0x74, 0xBF, 0xB3, 0xFD, 0x95, 0x61, 0x85 }, + { 0x28, 0xDB, 0xC3, 0xBC, 0x49, 0xFF, 0xD8, 0x7D, + 0xCF, 0xA5, 0x09, 0xB1, 0x1D, 0x42, 0x2B, 0xE7,} + }; + uint8_t datas[4][16]= + { { 0x00, 0x01, 0x02, 0x03, 0x04, 0x05, 0x06, 0x07, + 0x08, 0x09, 0x0a, 0x0b, 0x0c, 0x0d, 0x0e, 0x0f }, + { 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, + 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00 }, + { 0x83, 0xA2, 0xF8, 0xA2, 0x88, 0x64, 0x1F, 0xB9, + 0xA4, 0xE9, 0xA5, 0xCC, 0x2F, 0x13, 0x1C, 0x7D }, + { 0xB4, 0x1E, 0x6B, 0xE2, 0xEB, 0xA8, 0x4A, 0x14, + 0x8E, 0x2E, 0xED, 0x84, 0x59, 0x3C, 0x5E, 0xC7 } + }; + uint8_t i=0; + for(i=0; i<4; ++i){ + testencrypt(datas[i],keys[i]); + testdecrypt(datas[i],keys[i]); + } +} + + + +/***************************************************************************** + * main * + *****************************************************************************/ + +int main (void){ + char str[20]; + + DEBUG_INIT(); + + 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[] = {testrun_nessie_seed, testrun_seed, testrun_performance_seed}; + + while(1){ + 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"); + } + +} + diff --git a/test_src/main-serpent-test.c b/test_src/main-serpent-test.c new file mode 100644 index 0000000..5c450b6 --- /dev/null +++ b/test_src/main-serpent-test.c @@ -0,0 +1,130 @@ +/* main-serpent-test.c */ +/* + This file is part of the Crypto-avr-lib/microcrypt-lib. + Copyright (C) 2008 Daniel Otte (daniel.otte@rub.de) + + This program is free software: you can redistribute it and/or modify + it under the terms of the GNU General Public License as published by + the Free Software Foundation, either version 3 of the License, or + (at your option) any later version. + + This program is distributed in the hope that it will be useful, + but WITHOUT ANY WARRANTY; without even the implied warranty of + MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + GNU General Public License for more details. + + You should have received a copy of the GNU General Public License + along with this program. If not, see . +*/ +/* + * serpent test-suit + * +*/ + +#include "config.h" +#include "serial-tools.h" +#include "uart.h" +#include "debug.h" + +#include "serpent.h" +#include "nessie_bc_test.h" +#include "cli.h" +#include "performance_test.h" + +#include +#include +#include + +char* cipher_name = "Serpent"; + +/***************************************************************************** + * additional validation-functions * + *****************************************************************************/ +void serpent_genctx_dummy(uint8_t* key, uint16_t keysize, void* ctx){ + serpent_init(key, keysize&0xff, ctx); +} + +void testrun_nessie_serpent(void){ + nessie_bc_ctx.blocksize_B = 16; + nessie_bc_ctx.keysize_b = 128; + nessie_bc_ctx.name = cipher_name; + nessie_bc_ctx.ctx_size_B = sizeof(serpent_ctx_t); + nessie_bc_ctx.cipher_enc = (nessie_bc_enc_fpt)serpent_enc; + nessie_bc_ctx.cipher_dec = (nessie_bc_dec_fpt)serpent_dec; + nessie_bc_ctx.cipher_genctx = (nessie_bc_gen_fpt)serpent_genctx_dummy; + + nessie_bc_run(); + + nessie_bc_ctx.keysize_b = 192; + nessie_bc_run(); + + nessie_bc_ctx.keysize_b = 256; + nessie_bc_run(); +} + + +void testrun_performance_serpent(void){ + uint64_t t; + char str[16]; + uint8_t key[32], data[16]; + serpent_ctx_t ctx; + + calibrateTimer(); + print_overhead(); + + memset(key, 0, 32); + memset(data, 0, 16); + + startTimer(1); + serpent_init(key, 0, &ctx); + t = stopTimer(); + uart_putstr_P(PSTR("\r\n\tctx-gen time: ")); + 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: ")); + 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: ")); + ultoa((unsigned long)t, str, 10); + uart_putstr(str); + + uart_putstr_P(PSTR("\r\n")); +} +/***************************************************************************** + * main * + *****************************************************************************/ + +int main (void){ + char str[20]; + DEBUG_INIT(); + uart_putstr("\r\n"); + + 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[] = {testrun_nessie_serpent, testrun_nessie_serpent, testrun_performance_serpent}; + + while(1){ + 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"); + } + +} + diff --git a/test_src/main-sha1-test.c b/test_src/main-sha1-test.c new file mode 100644 index 0000000..6f07227 --- /dev/null +++ b/test_src/main-sha1-test.c @@ -0,0 +1,171 @@ +/* main-sha1-test.c */ +/* + This file is part of the Crypto-avr-lib/microcrypt-lib. + Copyright (C) 2008 Daniel Otte (daniel.otte@rub.de) + + This program is free software: you can redistribute it and/or modify + it under the terms of the GNU General Public License as published by + the Free Software Foundation, either version 3 of the License, or + (at your option) any later version. + + This program is distributed in the hope that it will be useful, + but WITHOUT ANY WARRANTY; without even the implied warranty of + MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + GNU General Public License for more details. + + You should have received a copy of the GNU General Public License + along with this program. If not, see . +*/ +/* + * SHA-1 test-suit + * +*/ + +#include "config.h" +#include "serial-tools.h" +#include "uart.h" +#include "debug.h" + +#include "sha1.h" +#include "nessie_hash_test.h" +#include "performance_test.h" + +#include +#include +#include +#include "cli.h" + +char* algo_name = "SHA-1"; + +/***************************************************************************** + * additional validation-functions * + *****************************************************************************/ +void sha1_next_dummy(void* buffer, void* ctx){ + sha1_nextBlock(ctx, buffer); +} + +void sha1_last_dummy(void* buffer, uint16_t size_b, void* ctx){ + sha1_lastBlock(ctx, buffer, size_b); +} + +void testrun_nessie_sha1(void){ + nessie_hash_ctx.hashsize_b = 160; + nessie_hash_ctx.blocksize_B = 512/8; + nessie_hash_ctx.ctx_size_B = sizeof(sha1_ctx_t); + nessie_hash_ctx.name = algo_name; + nessie_hash_ctx.hash_init = (nessie_hash_init_fpt)sha1_init; + nessie_hash_ctx.hash_next = (nessie_hash_next_fpt)sha1_next_dummy; + nessie_hash_ctx.hash_last = (nessie_hash_last_fpt)sha1_last_dummy; + nessie_hash_ctx.hash_conv = (nessie_hash_conv_fpt)sha1_ctx2hash; + + nessie_hash_run(); +} + +/***************************************************************************** + * self tests * + *****************************************************************************/ + +void sha1_ctx_dump(sha1_ctx_t *s){ + uint8_t i; + uart_putstr("\r\n==== sha1_ctx_dump ===="); + for(i=0;i<5;++i){ + uart_putstr("\r\na["); uart_hexdump(&i, 1); uart_putstr("]: "); + uart_hexdump(&(s->h[i]), 4); + } + uart_putstr("\r\nlength"); uart_hexdump(&i, 8); +} + +void testrun_sha1(void){ + sha1_hash_t hash; + sha1(&hash,"abc",3*8); + uart_putstr("\r\nsha1(\"abc\") = \r\n\t"); + uart_hexdump(hash,SHA1_HASH_BITS/8); + + sha1(&hash,"abcdbcdecdefdefgefghfghighijhijkijkljklmklmnlmnomnopnopq",448); + uart_putstr("\r\nsha1(\"abcdbcdecdefdefgefghfghighijhijkijkljklmklmnlmnomnopnopq\") = \r\n\t"); + uart_hexdump(hash,SHA1_HASH_BITS/8); + + uart_putstr("\r\nsha1(1,000,000 * 'a') = \r\n\t"); + { + uint8_t block[SHA1_BLOCK_BITS/8]; + uint16_t i; + sha1_ctx_t s; + memset(block,'a',SHA1_BLOCK_BITS/8); + sha1_init(&s); + for(i=0;i<15625; ++i){ /* (1000000/(SHA1_BLOCK_BITS/8)) */ + sha1_nextBlock(&s, block); + } + sha1_lastBlock(&s,block,0); + sha1_ctx2hash(&hash, &s); + } + uart_hexdump(hash,SHA1_HASH_BITS/8); + + + uart_putstr("\r\nx"); +} + +void testrun_performance_sha1(void){ + uint64_t t; + char str[16]; + uint8_t data[32]; + sha1_ctx_t ctx; + + calibrateTimer(); + print_overhead(); + + memset(data, 0, 32); + + startTimer(1); + sha1_init(&ctx); + t = stopTimer(); + uart_putstr_P(PSTR("\r\n\tctx-gen time: ")); + ultoa((unsigned long)t, str, 10); + uart_putstr(str); + + + startTimer(1); + sha1_nextBlock(&ctx, data); + t = stopTimer(); + uart_putstr_P(PSTR("\r\n\tone-block time: ")); + ultoa((unsigned long)t, str, 10); + uart_putstr(str); + + + startTimer(1); + sha1_lastBlock(&ctx, data, 0); + t = stopTimer(); + uart_putstr_P(PSTR("\r\n\tlast block time: ")); + ultoa((unsigned long)t, str, 10); + uart_putstr(str); + + uart_putstr_P(PSTR("\r\n")); +} + + +/***************************************************************************** + * main * + *****************************************************************************/ + +int main (void){ + char str[20]; + + DEBUG_INIT(); + uart_putstr("\r\n"); + + uart_putstr("\r\n\r\nCrypto-VS (SHA-1)\r\nloaded and running\r\n"); + + PGM_P u = PSTR("nessie\0test\0performance\0"); + void_fpt v[] = {testrun_nessie_sha1, testrun_sha1, testrun_performance_sha1}; + + while(1){ + 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"); + } +} + + diff --git a/test_src/main-sha256-test.c b/test_src/main-sha256-test.c new file mode 100644 index 0000000..9c3031d --- /dev/null +++ b/test_src/main-sha256-test.c @@ -0,0 +1,127 @@ +/* main-sha256-test.c */ +/* + This file is part of the Crypto-avr-lib/microcrypt-lib. + Copyright (C) 2008 Daniel Otte (daniel.otte@rub.de) + + This program is free software: you can redistribute it and/or modify + it under the terms of the GNU General Public License as published by + the Free Software Foundation, either version 3 of the License, or + (at your option) any later version. + + This program is distributed in the hope that it will be useful, + but WITHOUT ANY WARRANTY; without even the implied warranty of + MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + GNU General Public License for more details. + + You should have received a copy of the GNU General Public License + along with this program. If not, see . +*/ +/* + * SHA-256 test-suit + * +*/ + +#include "config.h" +#include "serial-tools.h" +#include "uart.h" +#include "debug.h" + +#include "sha256.h" +#include "nessie_hash_test.h" +#include "performance_test.h" + +#include +#include +#include +#include "cli.h" + +char* algo_name = "SHA-256"; + +/***************************************************************************** + * additional validation-functions * + *****************************************************************************/ +void sha256_next_dummy(void* buffer, void* ctx){ + sha256_nextBlock(ctx, buffer); +} + +void sha256_last_dummy(void* buffer, uint16_t size_b, void* ctx){ + sha256_lastBlock(ctx, buffer, size_b); +} + +void testrun_nessie_sha256(void){ + nessie_hash_ctx.hashsize_b = 256; + nessie_hash_ctx.blocksize_B = 512/8; + nessie_hash_ctx.ctx_size_B = sizeof(sha256_ctx_t); + nessie_hash_ctx.name = algo_name; + nessie_hash_ctx.hash_init = (nessie_hash_init_fpt)sha256_init; + nessie_hash_ctx.hash_next = (nessie_hash_next_fpt)sha256_next_dummy; + nessie_hash_ctx.hash_last = (nessie_hash_last_fpt)sha256_last_dummy; + nessie_hash_ctx.hash_conv = (nessie_hash_conv_fpt)sha256_ctx2hash; + + nessie_hash_run(); +} + +void testrun_performance_sha256(void){ + uint64_t t; + char str[16]; + uint8_t data[32]; + sha256_ctx_t ctx; + + calibrateTimer(); + print_overhead(); + + memset(data, 0, 32); + + startTimer(1); + sha256_init(&ctx); + t = stopTimer(); + uart_putstr_P(PSTR("\r\n\tctx-gen time: ")); + ultoa((unsigned long)t, str, 10); + uart_putstr(str); + + + startTimer(1); + sha256_nextBlock(&ctx, data); + t = stopTimer(); + uart_putstr_P(PSTR("\r\n\tone-block time: ")); + ultoa((unsigned long)t, str, 10); + uart_putstr(str); + + + startTimer(1); + sha256_lastBlock(&ctx, data, 0); + t = stopTimer(); + uart_putstr_P(PSTR("\r\n\tlast block time: ")); + ultoa((unsigned long)t, str, 10); + uart_putstr(str); + + uart_putstr_P(PSTR("\r\n")); +} + +/***************************************************************************** + * main * + *****************************************************************************/ + +int main (void){ + char str[20]; + DEBUG_INIT(); + uart_putstr("\r\n"); + + uart_putstr_P(PSTR("\r\n\r\nCrypto-VS (")); + uart_putstr(algo_name); + uart_putstr_P(PSTR(")\r\nloaded and running\r\n")); + + PGM_P u = PSTR("nessie\0test\0performance\0"); + void_fpt v[] = {testrun_nessie_sha256, testrun_nessie_sha256, testrun_performance_sha256}; + + while(1){ + 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"); + } +} + diff --git a/test_src/main-shabea-test.c b/test_src/main-shabea-test.c new file mode 100644 index 0000000..f221fd5 --- /dev/null +++ b/test_src/main-shabea-test.c @@ -0,0 +1,193 @@ +/* main-shabea-test.c */ +/* + This file is part of the Crypto-avr-lib/microcrypt-lib. + Copyright (C) 2008 Daniel Otte (daniel.otte@rub.de) + + This program is free software: you can redistribute it and/or modify + it under the terms of the GNU General Public License as published by + the Free Software Foundation, either version 3 of the License, or + (at your option) any later version. + + This program is distributed in the hope that it will be useful, + but WITHOUT ANY WARRANTY; without even the implied warranty of + MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + GNU General Public License for more details. + + You should have received a copy of the GNU General Public License + along with this program. If not, see . +*/ +/** + * \file main-shabea-test.c + * \author Daniel Otte + * \date 2007-06-07 + * \brief test suit for SHABEA + * \par License + * GPLv3 or later + * + */ +#include "config.h" +#include "serial-tools.h" +#include "uart.h" +#include "debug.h" + +#include "shabea.h" +#include "nessie_bc_test.h" +#include "cli.h" +#include "performance_test.h" + +#include +#include +#include + +char* cipher_name = "Shabea"; + +/***************************************************************************** + * additional validation-functions * + *****************************************************************************/ +void shabea_genctx_dummy(uint8_t* key, uint16_t keysize_b, void* ctx){ + memcpy(ctx, key, (keysize_b+7)/8); +} + +void shabea_enc_dummy(void* buffer, void* ctx){ + shabea256(buffer, ctx, 256, 1, 16); +} + +void shabea_dec_dummy(void* buffer, void* ctx){ + shabea256(buffer, ctx, 256, 0, 16); +} + + +void testrun_nessie_shabea(void){ + nessie_bc_ctx.blocksize_B = 32; + nessie_bc_ctx.keysize_b = 256; + nessie_bc_ctx.name = cipher_name; + nessie_bc_ctx.ctx_size_B = 32; + nessie_bc_ctx.cipher_enc = (nessie_bc_enc_fpt)shabea_enc_dummy; + nessie_bc_ctx.cipher_dec = (nessie_bc_dec_fpt)shabea_dec_dummy; + nessie_bc_ctx.cipher_genctx = (nessie_bc_gen_fpt)shabea_genctx_dummy; + + nessie_bc_run(); +} + + +void testrun_performance_shabea(void){ + uint64_t t; + char str[16]; + uint8_t key[32], data[32]; + + calibrateTimer(); + print_overhead(); + + memset(key, 0, 32); + memset(data, 0, 32); + + startTimer(1); + shabea256(data, key, 256, 1, 16); + t = stopTimer(); + uart_putstr_P(PSTR("\r\n\tencrypt time: ")); + ultoa((unsigned long)t, str, 10); + uart_putstr(str); + + + startTimer(1); + shabea256(data, key, 256, 0, 16); + 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")); +} + +/***************************************************************************** + * self tests * + *****************************************************************************/ + +void testencrypt(uint8_t* block, uint8_t* key){ + uart_putstr("\r\n==testy-encrypt==\r\n key: "); + uart_hexdump(key,16); + uart_putstr("\r\n plain: "); + uart_hexdump(block,32); + shabea256(block,key,128,1,16); + uart_putstr("\r\n crypt: "); + uart_hexdump(block,32); +} + +void testdecrypt(uint8_t* block, uint8_t* key){ + + uart_putstr("\r\n==testy-decrypt==\r\n key: "); + uart_hexdump(key,16); + uart_putstr("\r\n crypt: "); + uart_hexdump(block,32); + shabea256(block,key,128,0,16); + uart_putstr("\r\n plain: "); + uart_hexdump(block,32); +} + +void testrun_shabea(void){ + uint8_t keys[4][16]= + { { 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, + 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00 }, + { 0x00, 0x01, 0x02, 0x03, 0x04, 0x05, 0x06, 0x07, + 0x08, 0x09, 0x0a, 0x0b, 0x0c, 0x0d, 0x0e, 0x0f }, + { 0x47, 0x06, 0x48, 0x08, 0x51, 0xE6, 0x1B, 0xE8, + 0x5D, 0x74, 0xBF, 0xB3, 0xFD, 0x95, 0x61, 0x85 }, + { 0x28, 0xDB, 0xC3, 0xBC, 0x49, 0xFF, 0xD8, 0x7D, + 0xCF, 0xA5, 0x09, 0xB1, 0x1D, 0x42, 0x2B, 0xE7,} + }; + uint8_t datas[4][32]= + { { 0x00, 0x01, 0x02, 0x03, 0x04, 0x05, 0x06, 0x07, + 0x08, 0x09, 0x0a, 0x0b, 0x0c, 0x0d, 0x0e, 0x0f, + 0x10, 0x11, 0x12, 0x13, 0x14, 0x15, 0x16, 0x17, + 0x18, 0x19, 0x1a, 0x1b, 0x1c, 0x1d, 0x1e, 0x1f }, + { 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, + 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, + 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, + 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00 }, + { 0x83, 0xA2, 0xF8, 0xA2, 0x88, 0x64, 0x1F, 0xB9, + 0xA4, 0xE9, 0xA5, 0xCC, 0x2F, 0x13, 0x1C, 0x7D, + 0x83, 0xA2, 0xF8, 0xA2, 0x88, 0x64, 0x1F, 0xB9, + 0xA4, 0xE9, 0xA5, 0xCC, 0x2F, 0x13, 0x1C, 0x7D }, + { 0xB4, 0x1E, 0x6B, 0xE2, 0xEB, 0xA8, 0x4A, 0x14, + 0x8E, 0x2E, 0xED, 0x84, 0x59, 0x3C, 0x5E, 0xC7, + 0xB4, 0x1E, 0x6B, 0xE2, 0xEB, 0xA8, 0x4A, 0x14, + 0x8E, 0x2E, 0xED, 0x84, 0x59, 0x3C, 0x5E, 0xC7 } + }; + uint8_t i=0; + for(i=0; i<4; ++i){ + testencrypt(datas[i],keys[i]); + testdecrypt(datas[i],keys[i]); + } +} + + + +/***************************************************************************** + * main * + *****************************************************************************/ + +int main (void){ + char str[20]; + + DEBUG_INIT(); + uart_putstr("\r\n"); + + 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[] = {testrun_nessie_shabea, testrun_shabea, testrun_performance_shabea}; + + while(1){ + 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"); + } + +} + diff --git a/test_src/main-shacal1_enc-test.c b/test_src/main-shacal1_enc-test.c new file mode 100644 index 0000000..a4a0a1f --- /dev/null +++ b/test_src/main-shacal1_enc-test.c @@ -0,0 +1,110 @@ +/* main-shacal1_enc-test.c */ +/* + This file is part of the Crypto-avr-lib/microcrypt-lib. + Copyright (C) 2008 Daniel Otte (daniel.otte@rub.de) + + This program is free software: you can redistribute it and/or modify + it under the terms of the GNU General Public License as published by + the Free Software Foundation, either version 3 of the License, or + (at your option) any later version. + + This program is distributed in the hope that it will be useful, + but WITHOUT ANY WARRANTY; without even the implied warranty of + MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + GNU General Public License for more details. + + You should have received a copy of the GNU General Public License + along with this program. If not, see . +*/ +/* + * Shacal1 encryption only test-suit + * +*/ + +#include "config.h" +#include "serial-tools.h" +#include "uart.h" +#include "debug.h" + +#include "shacal1_enc.h" +#include "nessie_bc_test.h" +#include "cli.h" +#include "performance_test.h" + +#include +#include +#include + +char* cipher_name = "Shacal1 encryption only"; + +/***************************************************************************** + * additional validation-functions * + *****************************************************************************/ +void shacal1_genctx_dummy(uint8_t* key, uint16_t keysize_b, void* ctx){ + memcpy(ctx, key, (keysize_b+7)/8); +} + +void shacal1_enc_dummy(void* buffer, void* ctx){ + shacal1_enc(buffer, ctx, 512); +} + +void testrun_nessie_shacal1enc(void){ + nessie_bc_ctx.blocksize_B = SHACAL1_BLOCKSIZE_B; + nessie_bc_ctx.keysize_b = SHACAL1_KEYSIZE; + nessie_bc_ctx.name = cipher_name; + nessie_bc_ctx.ctx_size_B = SHACAL1_KEYSIZE_B; + nessie_bc_ctx.cipher_enc = (nessie_bc_enc_fpt)shacal1_enc_dummy; + nessie_bc_ctx.cipher_dec = (nessie_bc_dec_fpt)NULL; + nessie_bc_ctx.cipher_genctx = (nessie_bc_gen_fpt)shacal1_genctx_dummy; + + nessie_bc_run(); +} + +void testrun_performance_shacal1enc(void){ + uint64_t t; + uint8_t key[SHACAL1_KEYSIZE_B], data[SHACAL1_BLOCKSIZE_B]; + + calibrateTimer(); + print_overhead(); + + memset(key, 0, SHACAL1_KEYSIZE_B); + memset(data, 0, SHACAL1_BLOCKSIZE_B); + + + startTimer(1); + shacal1_enc(data, key, SHACAL1_KEYSIZE); + t = stopTimer(); + print_time_P(PSTR("\tencrypt time: "), t); + + uart_putstr_P(PSTR("\r\n")); +} + +/***************************************************************************** + * main * + *****************************************************************************/ + +int main (void){ + char str[20]; + DEBUG_INIT(); + uart_putstr("\r\n"); + + 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[] = {testrun_nessie_shacal1enc, + testrun_nessie_shacal1enc, + testrun_performance_shacal1enc}; + + while(1){ + 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"); + } + +} diff --git a/test_src/main-shacal2_enc-test.c b/test_src/main-shacal2_enc-test.c new file mode 100644 index 0000000..3ffd131 --- /dev/null +++ b/test_src/main-shacal2_enc-test.c @@ -0,0 +1,110 @@ +/* main-shacal2_enc-test.c */ +/* + This file is part of the Crypto-avr-lib/microcrypt-lib. + Copyright (C) 2008 Daniel Otte (daniel.otte@rub.de) + + This program is free software: you can redistribute it and/or modify + it under the terms of the GNU General Public License as published by + the Free Software Foundation, either version 3 of the License, or + (at your option) any later version. + + This program is distributed in the hope that it will be useful, + but WITHOUT ANY WARRANTY; without even the implied warranty of + MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + GNU General Public License for more details. + + You should have received a copy of the GNU General Public License + along with this program. If not, see . +*/ +/* + * Shacal2 encryption only test-suit + * +*/ + +#include "config.h" +#include "serial-tools.h" +#include "uart.h" +#include "debug.h" + +#include "shacal2_enc.h" +#include "nessie_bc_test.h" +#include "cli.h" +#include "performance_test.h" + +#include +#include +#include + +char* cipher_name = "Shacal2 encryption only"; + +/***************************************************************************** + * additional validation-functions * + *****************************************************************************/ +void shacal2_genctx_dummy(uint8_t* key, uint16_t keysize_b, void* ctx){ + memcpy(ctx, key, (keysize_b+7)/8); +} + +void shacal2_enc_dummy(void* buffer, void* ctx){ + shacal2_enc(buffer, ctx, SHACAL2_KEYSIZE); +} + +void testrun_nessie_shacal2enc(void){ + nessie_bc_ctx.blocksize_B = SHACAL2_BLOCKSIZE_B; + nessie_bc_ctx.keysize_b = SHACAL2_KEYSIZE; + nessie_bc_ctx.name = cipher_name; + nessie_bc_ctx.ctx_size_B = SHACAL2_KEYSIZE_B; + nessie_bc_ctx.cipher_enc = (nessie_bc_enc_fpt)shacal2_enc_dummy; + nessie_bc_ctx.cipher_dec = (nessie_bc_dec_fpt)NULL; + nessie_bc_ctx.cipher_genctx = (nessie_bc_gen_fpt)shacal2_genctx_dummy; + + nessie_bc_run(); +} + +void testrun_performance_shacal2enc(void){ + uint64_t t; + uint8_t key[SHACAL2_KEYSIZE_B], data[SHACAL2_BLOCKSIZE_B]; + + calibrateTimer(); + print_overhead(); + + memset(key, 0, SHACAL2_KEYSIZE_B); + memset(data, 0, SHACAL2_BLOCKSIZE_B); + + + startTimer(1); + shacal2_enc(data, key, SHACAL2_KEYSIZE); + t = stopTimer(); + print_time_P(PSTR("\tencrypt time: "), t); + + uart_putstr_P(PSTR("\r\n")); +} + +/***************************************************************************** + * main * + *****************************************************************************/ + +int main (void){ + char str[20]; + DEBUG_INIT(); + uart_putstr("\r\n"); + + 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[] = {testrun_nessie_shacal2enc, + testrun_nessie_shacal2enc, + testrun_performance_shacal2enc}; + + while(1){ + 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"); + } + +} diff --git a/test_src/main-skipjack-test.c b/test_src/main-skipjack-test.c new file mode 100644 index 0000000..a7f1165 --- /dev/null +++ b/test_src/main-skipjack-test.c @@ -0,0 +1,150 @@ +/* main-skipjack-test.c */ +/* + This file is part of the Crypto-avr-lib/microcrypt-lib. + Copyright (C) 2008 Daniel Otte (daniel.otte@rub.de) + + This program is free software: you can redistribute it and/or modify + it under the terms of the GNU General Public License as published by + the Free Software Foundation, either version 3 of the License, or + (at your option) any later version. + + This program is distributed in the hope that it will be useful, + but WITHOUT ANY WARRANTY; without even the implied warranty of + MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + GNU General Public License for more details. + + You should have received a copy of the GNU General Public License + along with this program. If not, see . +*/ +/* + * skipjack test-suit + * +*/ + +#include "config.h" +#include "serial-tools.h" +#include "uart.h" +#include "debug.h" + +#include "skipjack.h" +#include "nessie_bc_test.h" +#include "cli.h" +#include "performance_test.h" + +#include +#include +#include + + +char* cipher_name = "Skipjack"; + +/***************************************************************************** + * additional validation-functions * + *****************************************************************************/ +void skipjack_genctx_dummy(uint8_t* key, uint16_t keysize, void* ctx){ + memcpy(ctx, key, 10); +} + +void testrun_nessie_skipjack(void){ + nessie_bc_ctx.blocksize_B = 8; + nessie_bc_ctx.keysize_b = 80; + nessie_bc_ctx.name = cipher_name; + nessie_bc_ctx.ctx_size_B = 10; + nessie_bc_ctx.cipher_enc = (nessie_bc_enc_fpt)skipjack_enc; + nessie_bc_ctx.cipher_dec = (nessie_bc_dec_fpt)skipjack_dec; + nessie_bc_ctx.cipher_genctx = (nessie_bc_gen_fpt)skipjack_genctx_dummy; + + nessie_bc_run(); +} + + +void testrun_performance_skipjack(void){ + uint64_t t; + char str[16]; + uint8_t key[10], data[8]; + + calibrateTimer(); + print_overhead(); + + memset(key, 0, 10); + memset(data, 0, 8); + + startTimer(1); + skipjack_enc(data, key); + t = stopTimer(); + uart_putstr_P(PSTR("\r\n\tencrypt time: ")); + ultoa((unsigned long)t, str, 10); + uart_putstr(str); + + + startTimer(1); + skipjack_dec(data, key); + 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")); +} + +/***************************************************************************** + * self tests * + *****************************************************************************/ + +void testencrypt(uint8_t* block, uint8_t* key){ + uart_putstr("\r\n==testy-encrypt==\r\n key: "); + uart_hexdump(key,10); + uart_putstr("\r\n plain: "); + uart_hexdump(block,8); + skipjack_enc(block,key); + uart_putstr("\r\n crypt: "); + uart_hexdump(block,8); +} + +void testdecrypt(uint8_t* block, uint8_t* key){ + uart_putstr("\r\n==testy-decrypt==\r\n key: "); + uart_hexdump(key,10); + uart_putstr("\r\n crypt: "); + uart_hexdump(block,8); + skipjack_dec(block,key); + uart_putstr("\r\n plain: "); + uart_hexdump(block,8); +} + +void testrun_skipjack(void){ + uint8_t key[]={ 0x00, 0x99, 0x88, 0x77, 0x66, + 0x55, 0x44, 0x33, 0x22, 0x11}; + uint8_t data[]={ 0x33, 0x22, 0x11, 0x00, 0xdd, 0xcc, 0xbb, 0xaa}; + testencrypt(data,key); + testdecrypt(data,key); +} + + + +/***************************************************************************** + * main * + *****************************************************************************/ + +int main (void){ + char str[20]; + + DEBUG_INIT(); + uart_putstr("\r\n"); + + uart_putstr("\r\n\r\nCrypto-VS (skipjack)\r\nloaded and running\r\n"); + + PGM_P u = PSTR("nessie\0test\0performance\0"); + void_fpt v[] = {testrun_nessie_skipjack, testrun_skipjack, testrun_performance_skipjack}; + + while(1){ + 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"); + } + +} + diff --git a/test_src/main-tdes-test.c b/test_src/main-tdes-test.c new file mode 100644 index 0000000..d5ae1a0 --- /dev/null +++ b/test_src/main-tdes-test.c @@ -0,0 +1,123 @@ +/* main-tdes-test.c */ +/* + This file is part of the Crypto-avr-lib/microcrypt-lib. + Copyright (C) 2008 Daniel Otte (daniel.otte@rub.de) + + This program is free software: you can redistribute it and/or modify + it under the terms of the GNU General Public License as published by + the Free Software Foundation, either version 3 of the License, or + (at your option) any later version. + + This program is distributed in the hope that it will be useful, + but WITHOUT ANY WARRANTY; without even the implied warranty of + MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + GNU General Public License for more details. + + You should have received a copy of the GNU General Public License + along with this program. If not, see . +*/ +/* + * tdes test-suit + * +*/ + +#include "config.h" +#include "serial-tools.h" +#include "uart.h" +#include "debug.h" + +#include "des.h" +#include "nessie_bc_test.h" +#include "cli.h" +#include "performance_test.h" + +#include +#include +#include + +char* cipher_name = "TDES"; + +/***************************************************************************** + * additional validation-functions * + *****************************************************************************/ +void tdes_init_dummy(const void* key, uint16_t keysize_b, void* ctx){ + memcpy(ctx, key, 8*3); +} + +void tdes_enc_dummy(void* buffer, void* ctx){ + tdes_enc(buffer, buffer, ctx); +} + +void tdes_dec_dummy(void* buffer, void* ctx){ + tdes_dec(buffer, buffer, ctx); +} + +void testrun_nessie_tdes(void){ + nessie_bc_init(); + nessie_bc_ctx.blocksize_B = 8; + nessie_bc_ctx.keysize_b = 192; + nessie_bc_ctx.name = cipher_name; + nessie_bc_ctx.ctx_size_B = sizeof(8*3); + nessie_bc_ctx.cipher_enc = (nessie_bc_enc_fpt)tdes_enc_dummy; + nessie_bc_ctx.cipher_dec = (nessie_bc_dec_fpt)tdes_dec_dummy; + nessie_bc_ctx.cipher_genctx = (nessie_bc_gen_fpt)tdes_init_dummy; + + nessie_bc_run(); +} + + +void testrun_performance_tdes(void){ + uint64_t t; + char str[16]; + uint8_t key[8*3], data[8]; + + + calibrateTimer(); + print_overhead(); + + memset(key, 0, 8*3); + memset(data, 0, 8); + + startTimer(1); + tdes_enc(data, data, key); + t = stopTimer(); + uart_putstr_P(PSTR("\r\n\tencrypt time: ")); + ultoa((unsigned long)t, str, 10); + uart_putstr(str); + + startTimer(1); + tdes_dec(data, data, key); + 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 * + *****************************************************************************/ + +int main (void){ + char str[20]; + DEBUG_INIT(); + uart_putstr("\r\n"); + + 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[] = {testrun_nessie_tdes, testrun_nessie_tdes, testrun_performance_tdes}; + + while(1){ + 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"); + } + +} + diff --git a/test_src/main-trivium-test.c b/test_src/main-trivium-test.c new file mode 100644 index 0000000..4d4e3d2 --- /dev/null +++ b/test_src/main-trivium-test.c @@ -0,0 +1,123 @@ +/* main-trivium-test.c */ +/* + This file is part of the Crypto-avr-lib/microcrypt-lib. + Copyright (C) 2008 Daniel Otte (daniel.otte@rub.de) + + This program is free software: you can redistribute it and/or modify + it under the terms of the GNU General Public License as published by + the Free Software Foundation, either version 3 of the License, or + (at your option) any later version. + + This program is distributed in the hope that it will be useful, + but WITHOUT ANY WARRANTY; without even the implied warranty of + MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + GNU General Public License for more details. + + You should have received a copy of the GNU General Public License + along with this program. If not, see . +*/ +/* + * Mickey128 test-suit + * +*/ + +#include "config.h" +#include "serial-tools.h" +#include "uart.h" +#include "debug.h" +#include "cli.h" + +#include "trivium.h" +#include "nessie_stream_test.h" +#include "performance_test.h" + +#include +#include +#include + +char* cipher_name = "Trivium"; + +/***************************************************************************** + * additional validation-functions * + *****************************************************************************/ +void trivium_genctx_dummy(uint8_t* key, uint16_t keysize_b, void* ctx){ + uint32_t iv=0; + trivium_init(key, 80, &iv, 32, ctx); +} + +uint8_t trivium_getbyte_dummy(trivium_ctx_t* ctx){ + uint8_t i,ret=0; + for(i=0; i<8; ++i){ + ret<<=1; + ret |= trivium_enc(ctx); + } + return ret; +} + +void testrun_nessie_trivium(void){ + nessie_stream_ctx.outsize_b = 8; /* actually unused */ + nessie_stream_ctx.keysize_b = 80; /* this is the one we have refrence vectors for */ + nessie_stream_ctx.ivsize_b = 32; + nessie_stream_ctx.name = cipher_name; + nessie_stream_ctx.ctx_size_B = sizeof(trivium_ctx_t); + nessie_stream_ctx.cipher_genctx = (nessie_stream_genctx_fpt)trivium_genctx_dummy; + nessie_stream_ctx.cipher_enc = (nessie_stream_genenc_fpt)trivium_getbyte_dummy; + + nessie_stream_run(); +} + +void testrun_performance_trivium(void){ + uint64_t t; + char str[16]; + uint8_t key[10], iv[10]; + trivium_ctx_t ctx; + + calibrateTimer(); + print_overhead(); + + memset(key, 0, 10); + memset(iv, 0, 10); + + startTimer(1); + trivium_init(key, 80, iv, 80, &ctx); + t = stopTimer(); + uart_putstr_P(PSTR("\r\n\tctx-gen time: ")); + ultoa((unsigned long)t, str, 10); + uart_putstr(str); + + startTimer(1); + trivium_enc(&ctx); + t = stopTimer(); + uart_putstr_P(PSTR("\r\n\tencrypt time: ")); + ultoa((unsigned long)t, str, 10); + uart_putstr(str); + + uart_putstr_P(PSTR("\r\n")); +} + +/***************************************************************************** + * main * + *****************************************************************************/ + +int main (void){ + char str[20]; + DEBUG_INIT(); + uart_putstr("\r\n"); + + 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[] = {testrun_nessie_trivium, testrun_nessie_trivium, testrun_performance_trivium}; + + while(1){ + 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"); + } +} diff --git a/test_src/main-xtea-test.c b/test_src/main-xtea-test.c new file mode 100644 index 0000000..07fcffe --- /dev/null +++ b/test_src/main-xtea-test.c @@ -0,0 +1,111 @@ +/* main-xtea-test.c */ +/* + This file is part of the Crypto-avr-lib/microcrypt-lib. + Copyright (C) 2008 Daniel Otte (daniel.otte@rub.de) + + This program is free software: you can redistribute it and/or modify + it under the terms of the GNU General Public License as published by + the Free Software Foundation, either version 3 of the License, or + (at your option) any later version. + + This program is distributed in the hope that it will be useful, + but WITHOUT ANY WARRANTY; without even the implied warranty of + MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + GNU General Public License for more details. + + You should have received a copy of the GNU General Public License + along with this program. If not, see . +*/ +/* + * XTEA test-suit + * +*/ + +#include "config.h" +#include "serial-tools.h" +#include "uart.h" +#include "debug.h" + +#include "xtea.h" +#include "nessie_bc_test.h" +#include "performance_test.h" +#include "cli.h" + +#include +#include + +char* cipher_name = "XTEA"; + +void xtea_genctx_dummy(uint8_t* key, uint16_t keysize, void* ctx){ + memcpy(ctx, key, (keysize+7)/8); +} + +void xtea_enc_dummy(uint8_t* buffer, void* ctx){ + xtea_enc((uint32_t*)buffer, (uint32_t*)buffer, ctx); +} + +void xtea_dec_dummy(uint8_t* buffer, void* ctx){ + xtea_dec((uint32_t*)buffer, (uint32_t*)buffer, ctx); +} + +void testrun_nessie_xtea(void){ + nessie_bc_ctx.blocksize_B = 8; + nessie_bc_ctx.keysize_b = 128; + nessie_bc_ctx.name = cipher_name; + nessie_bc_ctx.ctx_size_B = 128/8; + nessie_bc_ctx.cipher_enc = (nessie_bc_enc_fpt)xtea_enc_dummy; + nessie_bc_ctx.cipher_dec = (nessie_bc_dec_fpt)xtea_dec_dummy; + nessie_bc_ctx.cipher_genctx = (nessie_bc_gen_fpt)xtea_genctx_dummy; + + 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 * + *****************************************************************************/ + +int main (void){ + char str[20]; + DEBUG_INIT(); + uart_putstr("\r\n"); + + 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[] = {testrun_nessie_xtea, testrun_nessie_xtea, testrun_performance_xtea}; + + while(1){ + 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"); + } +} diff --git a/test_src/nessie_bc_test.c b/test_src/nessie_bc_test.c new file mode 100644 index 0000000..f9a91e5 --- /dev/null +++ b/test_src/nessie_bc_test.c @@ -0,0 +1,212 @@ +/* nessie_bc_test.c */ +/* + This file is part of the Crypto-avr-lib/microcrypt-lib. + Copyright (C) 2008 Daniel Otte (daniel.otte@rub.de) + + This program is free software: you can redistribute it and/or modify + it under the terms of the GNU General Public License as published by + the Free Software Foundation, either version 3 of the License, or + (at your option) any later version. + + This program is distributed in the hope that it will be useful, + but WITHOUT ANY WARRANTY; without even the implied warranty of + MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + GNU General Public License for more details. + + You should have received a copy of the GNU General Public License + along with this program. If not, see . +*/ +/** + * + * author: Daniel Otte + * email: daniel.otte@rub.de + * license: GPLv3 + * + * a suit for running the nessie-tests for blockciphers + * + * */ +#include +#include +#include "nessie_bc_test.h" +#include "nessie_common.h" +#include "uart.h" + +nessie_bc_ctx_t nessie_bc_ctx; + +void nessie_bc_init(void){ + memset(&nessie_bc_ctx, 0, sizeof(nessie_bc_ctx_t)); +} +static +void nessie_bc_free(void* ctx){ + if(nessie_bc_ctx.cipher_free) + nessie_bc_ctx.cipher_free(ctx); +} + +void nessie_bc_enc(uint8_t* key, uint8_t* pt){ + uint8_t ctx[nessie_bc_ctx.ctx_size_B]; + uint8_t buffer[nessie_bc_ctx.blocksize_B]; + uint16_t i; + + /* single test */ + nessie_print_item("key", key, (nessie_bc_ctx.keysize_b+7)/8); + nessie_bc_ctx.cipher_genctx(key, nessie_bc_ctx.keysize_b, ctx); + + memcpy(buffer, pt, nessie_bc_ctx.blocksize_B); + nessie_print_item("plain", buffer, nessie_bc_ctx.blocksize_B); + nessie_bc_ctx.cipher_enc(buffer, ctx); + nessie_print_item("cipher", buffer, nessie_bc_ctx.blocksize_B); + if(nessie_bc_ctx.cipher_dec){ + nessie_bc_ctx.cipher_dec(buffer, ctx); + nessie_print_item("decrypted", buffer, nessie_bc_ctx.blocksize_B); + } + /* 100 times test */ + memcpy(buffer, pt, nessie_bc_ctx.blocksize_B); + for(i=0; i<100; ++i){ + nessie_bc_ctx.cipher_enc(buffer, ctx); + } + nessie_print_item("Iterated 100 times", buffer, nessie_bc_ctx.blocksize_B); +#ifndef NESSIE_NO1KTEST + /* 1000 times test, we use the 100 precedig steps to fasten things a bit */ + for(; i<1000; ++i){ + nessie_bc_ctx.cipher_enc(buffer, ctx); + } + nessie_print_item("Iterated 1000 times", buffer, nessie_bc_ctx.blocksize_B); +#endif + nessie_bc_free(ctx); +} + +void nessie_bc_dec(uint8_t* key, uint8_t* ct){ + uint8_t ctx[nessie_bc_ctx.ctx_size_B]; + uint8_t buffer[nessie_bc_ctx.blocksize_B]; + + /* single test */ + nessie_print_item("key", key, (nessie_bc_ctx.keysize_b+7)/8); + nessie_bc_ctx.cipher_genctx(key, nessie_bc_ctx.keysize_b, ctx); + memcpy(buffer, ct, nessie_bc_ctx.blocksize_B); + nessie_print_item("cipher", buffer, nessie_bc_ctx.blocksize_B); + nessie_bc_ctx.cipher_dec(buffer, ctx); + nessie_print_item("plain", buffer, nessie_bc_ctx.blocksize_B); + nessie_bc_ctx.cipher_enc(buffer, ctx); + nessie_print_item("encrypted", buffer, nessie_bc_ctx.blocksize_B); + nessie_bc_free(ctx); +} + +void nessie_bc_run(void){ + uint16_t i; + uint8_t set; + uint8_t key[(nessie_bc_ctx.keysize_b+7)/8]; + uint8_t buffer[nessie_bc_ctx.blocksize_B]; + + nessie_print_header(nessie_bc_ctx.name, nessie_bc_ctx.keysize_b, + nessie_bc_ctx.blocksize_B*8, 0, 0, 0); + /* test set 1 */ + set=1; + nessie_print_setheader(set); + for(i=0; i>(i%8); + memset(buffer, 0, nessie_bc_ctx.blocksize_B); + nessie_bc_enc(key, buffer); + } + /* test set 2 */ + set=2; + nessie_print_setheader(set); + for(i=0; i>(i%8); + nessie_bc_enc(key, buffer); + } + /* test set 3 */ + set=3; + nessie_print_setheader(set); + for(i=0; i<256; ++i){ + nessie_print_set_vector(set, i); + memset(key, i, (nessie_bc_ctx.keysize_b+7)/8); + memset(buffer, i, nessie_bc_ctx.blocksize_B); + nessie_bc_enc(key, buffer); + } + /* test set 4 */ + set=4; + nessie_print_setheader(set); + /* 4 - 0*/ + nessie_print_set_vector(set, 0); + for(i=0; i<(nessie_bc_ctx.keysize_b+7)/8; ++i){ + key[i]=i; + } + for(i=0; i>(i%8); + memset(buffer, 0, nessie_bc_ctx.blocksize_B); + nessie_bc_dec(key, buffer); + } + /* test set 6 */ + set=6; + nessie_print_setheader(set); + for(i=0; i>(i%8); + nessie_bc_dec(key, buffer); + } + /* test set 7 */ + set=7; + nessie_print_setheader(set); + for(i=0; i<256; ++i){ + nessie_print_set_vector(set, i); + memset(key, i, (nessie_bc_ctx.keysize_b+7)/8); + memset(buffer, i, nessie_bc_ctx.blocksize_B); + nessie_bc_dec(key, buffer); + } + /* test set 8 */ + set=8; + nessie_print_setheader(set); + /* 8 - 0*/ + nessie_print_set_vector(set, 0); + for(i=0; i<(nessie_bc_ctx.keysize_b+7)/8; ++i){ + key[i]=i; + } + for(i=0; i. +*/ +#ifndef NESSIE_BC_TEST_H_ +#define NESSIE_BC_TEST_H_ + +#include + +typedef void (*nessie_bc_gen_fpt)(uint8_t* key, uint16_t keysize_b, void* ctx); +typedef void (*nessie_bc_free_fpt)(void* ctx); +typedef void (*nessie_bc_enc_fpt)(void* buffer, void* ctx); +typedef void (*nessie_bc_dec_fpt)(void* buffer, void* ctx); + +typedef struct nessie_bc_ctx_st{ + uint16_t keysize_b; + uint16_t blocksize_B; + uint16_t ctx_size_B; + char* name; + nessie_bc_gen_fpt cipher_genctx; + nessie_bc_free_fpt cipher_free; + nessie_bc_enc_fpt cipher_enc; + nessie_bc_dec_fpt cipher_dec; +} nessie_bc_ctx_t; + + +extern nessie_bc_ctx_t nessie_bc_ctx; + +void nessie_bc_run(void); +void nessie_bc_init(void); + + +#endif /*NESSIE_BC_TEST_H_*/ diff --git a/test_src/nessie_common.c b/test_src/nessie_common.c new file mode 100644 index 0000000..020d5ab --- /dev/null +++ b/test_src/nessie_common.c @@ -0,0 +1,178 @@ +/* nessie_common.c */ +/* + This file is part of the Crypto-avr-lib/microcrypt-lib. + Copyright (C) 2008 Daniel Otte (daniel.otte@rub.de) + + This program is free software: you can redistribute it and/or modify + it under the terms of the GNU General Public License as published by + the Free Software Foundation, either version 3 of the License, or + (at your option) any later version. + + This program is distributed in the hope that it will be useful, + but WITHOUT ANY WARRANTY; without even the implied warranty of + MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + GNU General Public License for more details. + + You should have received a copy of the GNU General Public License + along with this program. If not, see . +*/ +/** + * + * author: Daniel Otte + * email: daniel.otte@rub.de + * license: GPLv3 + * + * common function for nessie-tests + * + * */ + +#include +#include +#include +#include /* utoa() */ +#include "uart.h" + +void nessie_print_block(uint8_t* block, uint16_t blocksize_bit){ + char tab [] = {'0', '1', '2', '3', + '4', '5', '6', '7', + '8', '9', 'A', 'B', + 'C', 'D', 'E', 'F'}; + uint16_t i; + for(i=0; i<(blocksize_bit+7)/8; ++i){ + uart_putc(tab[(block[i])>>4]); + uart_putc(tab[(block[i])&0xf]); + } +} + +#define SPACES 31 +#define BYTESPERLINE 16 + +void nessie_print_item(char* name, uint8_t* buffer, uint16_t size_B){ + uint8_t name_len; + uint8_t i; + name_len=strlen(name); + if(name_len>SPACES-1){ + uart_putstr_P(PSTR("\r\n!!! formatting error !!!\r\n")); + return; + } + uart_putstr_P(PSTR("\r\n")); + for(i=0; iBYTESPERLINE)?BYTESPERLINE:toprint)*8); + buffer += BYTESPERLINE; + toprint -= BYTESPERLINE; + } + } +} + + +void nessie_print_set_vector(uint8_t set, uint16_t vector){ + uart_putstr_P(PSTR("\r\n\r\nSet ")); + uart_putc('0'+set%10); + uart_putstr_P(PSTR(", vector#")); + uart_putc((vector<100)?' ':'0'+vector/100); + uart_putc((vector<10 )?' ':'0'+(vector/10)%10); + uart_putc('0'+vector%10); + uart_putc(':'); +} + +/* example: +Test vectors -- set 3 +===================== + */ +void nessie_print_setheader(uint8_t set){ + uart_putstr_P(PSTR("\r\n\r\nTest vectors -- set ")); + uart_putc('0'+set%10); + uart_putstr_P(PSTR("\r\n=====================")); +} + +/* example: +******************************************************************************** +*Project NESSIE - New European Schemes for Signature, Integrity, and Encryption* +******************************************************************************** + +Primitive Name: Serpent +======================= +Key size: 256 bits +Block size: 128 bits +*/ + +void nessie_print_header(char* name, + uint16_t keysize_b, + uint16_t blocksize_b, + uint16_t hashsize_b, + uint16_t macsize_b, + uint16_t ivsize_b ){ + uint16_t i; + uart_putstr_P(PSTR("\r\n\r\n" + "********************************************************************************\r\n" + "* micro-crypt - crypto primitives for microcontrolles by Daniel Otte *\r\n" + "********************************************************************************\r\n" + "\r\n")); + uart_putstr_P(PSTR("Primitive Name: ")); + uart_putstr(name); + uart_putstr_P(PSTR("\r\n")); + /* underline */ + for(i=0; i<16+strlen(name); ++i){ + uart_putc('='); + } + char str[6]; /* must catch numbers up to 65535 + terminatin \0 */ + if(keysize_b){ + uart_putstr_P(PSTR("\r\nKey size: ")); + utoa(keysize_b, str, 10); + uart_putstr(str); + uart_putstr_P(PSTR(" bits")); + } + if(blocksize_b){ + uart_putstr_P(PSTR("\r\nBlock size: ")); + utoa(blocksize_b, str, 10); + uart_putstr(str); + uart_putstr_P(PSTR(" bits")); + } + if(hashsize_b){ + uart_putstr_P(PSTR("\r\nHash size: ")); + utoa(hashsize_b, str, 10); + uart_putstr(str); + uart_putstr_P(PSTR(" bits")); + } + if(macsize_b){ + uart_putstr_P(PSTR("\r\nMac size: ")); + utoa(macsize_b, str, 10); + uart_putstr(str); + uart_putstr_P(PSTR(" bits")); + } + if(ivsize_b){ + 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")); +} + +void nessie_print_footer(void){ + uart_putstr_P(PSTR("\r\n\r\n\r\n\r\nEnd of test vectors\r\n\r\n")); +} + diff --git a/test_src/nessie_common.h b/test_src/nessie_common.h new file mode 100644 index 0000000..4090e32 --- /dev/null +++ b/test_src/nessie_common.h @@ -0,0 +1,47 @@ +/* nessie_common.h */ +/* + This file is part of the Crypto-avr-lib/microcrypt-lib. + Copyright (C) 2008 Daniel Otte (daniel.otte@rub.de) + + This program is free software: you can redistribute it and/or modify + it under the terms of the GNU General Public License as published by + the Free Software Foundation, either version 3 of the License, or + (at your option) any later version. + + This program is distributed in the hope that it will be useful, + but WITHOUT ANY WARRANTY; without even the implied warranty of + MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + GNU General Public License for more details. + + You should have received a copy of the GNU General Public License + along with this program. If not, see . +*/ +/** + * + * author: Daniel Otte + * email: daniel.otte@rub.de + * license: GPLv3 + * + * common function for nessie-tests + * + * */ + +#ifndef NESSIE_COMMON_H_ +#define NESSIE_COMMON_H_ + + +#include + +void nessie_print_block(uint8_t* block, uint16_t blocksize_bit); +void nessie_print_item(char* name, uint8_t* buffer, uint16_t size_B); +void nessie_print_set_vector(uint8_t set, uint16_t vector); +void nessie_print_setheader(uint8_t set); +void nessie_print_header(char* name, + uint16_t keysize_b, + uint16_t blocksize_b, + uint16_t hashsize_b, + uint16_t macsize_b, + uint16_t ivsize_b ); +void nessie_print_footer(void); + +#endif /*NESSIE_COMMON_H_*/ diff --git a/test_src/nessie_hash_test.c b/test_src/nessie_hash_test.c new file mode 100644 index 0000000..a870b82 --- /dev/null +++ b/test_src/nessie_hash_test.c @@ -0,0 +1,240 @@ +/* nessie_hash_test.c */ +/* + This file is part of the Crypto-avr-lib/microcrypt-lib. + Copyright (C) 2008 Daniel Otte (daniel.otte@rub.de) + + This program is free software: you can redistribute it and/or modify + it under the terms of the GNU General Public License as published by + the Free Software Foundation, either version 3 of the License, or + (at your option) any later version. + + This program is distributed in the hope that it will be useful, + but WITHOUT ANY WARRANTY; without even the implied warranty of + MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + GNU General Public License for more details. + + You should have received a copy of the GNU General Public License + along with this program. If not, see . +*/ +/** + * + * author: Daniel Otte + * email: daniel.otte@rub.de + * license: GPLv3 + * + * a suit for running the nessie-tests for hashes + * + * */ +#include +#include +#include "nessie_hash_test.h" +#include "nessie_common.h" +#include "uart.h" + +nessie_hash_ctx_t nessie_hash_ctx; + +static +void ascii_hash(char* data, char* desc){ + uint8_t ctx[nessie_hash_ctx.ctx_size_B]; + uint8_t hash[(nessie_hash_ctx.hashsize_b+7)/8]; + uint16_t sl; + + uart_putstr_P(PSTR("\r\n message=")); + uart_putstr(desc); + nessie_hash_ctx.hash_init(ctx); + sl = strlen(data); + while(sl>=nessie_hash_ctx.blocksize_B){ + nessie_hash_ctx.hash_next(data, ctx); + data += nessie_hash_ctx.blocksize_B; + sl -= nessie_hash_ctx.blocksize_B; + } + nessie_hash_ctx.hash_last(data, sl*8, ctx); + nessie_hash_ctx.hash_conv(hash, ctx); + nessie_print_item("hash", hash, (nessie_hash_ctx.hashsize_b+7)/8); +} + +// message=1 million times "a" + +static +void amillion_hash(void){ + uint8_t ctx[nessie_hash_ctx.ctx_size_B]; + uint8_t hash[(nessie_hash_ctx.hashsize_b+7)/8]; + uint8_t block[nessie_hash_ctx.blocksize_B]; + uint32_t n=1000000LL; + + uart_putstr_P(PSTR("\r\n message=")); + uart_putstr_P(PSTR("1 million times \"a\"")); + memset(block, 'a', nessie_hash_ctx.blocksize_B); + nessie_hash_ctx.hash_init(ctx); + while(n>=nessie_hash_ctx.blocksize_B){ + nessie_hash_ctx.hash_next(block, ctx); + n -= nessie_hash_ctx.blocksize_B; + } + nessie_hash_ctx.hash_last(block, n*8, ctx); + nessie_hash_ctx.hash_conv(hash, ctx); + nessie_print_item("hash", hash, (nessie_hash_ctx.hashsize_b+7)/8); +} + + +static +void zero_hash(uint16_t n){ + uint8_t ctx[nessie_hash_ctx.ctx_size_B]; + uint8_t hash[(nessie_hash_ctx.hashsize_b+7)/8]; + uint8_t block[nessie_hash_ctx.blocksize_B]; + + uart_putstr_P(PSTR("\r\n message=")); + if(n>=10000) + uart_putc('0'+n/10000); + if(n>=1000) + uart_putc('0'+(n/1000)%10); + if(n>=100) + uart_putc('0'+(n/100)%10); + if(n>=10) + uart_putc('0'+(n/10)%10); + uart_putc('0'+n%10); + uart_putstr_P(PSTR(" zero bits")); + + memset(block, 0, nessie_hash_ctx.blocksize_B); + nessie_hash_ctx.hash_init(ctx); + while(n>=nessie_hash_ctx.blocksize_B*8){ + nessie_hash_ctx.hash_next(block, ctx); + n -= nessie_hash_ctx.blocksize_B*8; + } + nessie_hash_ctx.hash_last(block, n, ctx); + nessie_hash_ctx.hash_conv(hash, ctx); + nessie_print_item("hash", hash, (nessie_hash_ctx.hashsize_b+7)/8); +} + +static +void one_in512_hash(uint16_t pos){ + uint8_t ctx[nessie_hash_ctx.ctx_size_B]; + uint8_t hash[(nessie_hash_ctx.hashsize_b+7)/8]; + uint8_t block[nessie_hash_ctx.blocksize_B]; + uint16_t n=512; + char* tab[8]={"80", "40", "20", "10", + "08", "04", "02", "01" }; + + pos&=511; + uart_putstr_P(PSTR("\r\n message=")); + uart_putstr_P(PSTR("512-bit string: ")); + if((pos/8) >=10){ + uart_putc('0'+(pos/8/10)%10); + } else { + uart_putc(' '); + } + uart_putc('0'+(pos/8)%10); + uart_putstr_P(PSTR("*00,")); + uart_putstr(tab[pos&7]); + uart_putc(','); + if(63-(pos/8) >=10){ + uart_putc('0'+((63-pos/8)/10)%10); + } else { + uart_putc(' '); + } + uart_putc('0'+(63-pos/8)%10); + uart_putstr_P(PSTR("*00")); + + /* now the real stuff */ + memset(block, 0, 512/8); + block[pos>>3] = 0x80>>(pos&0x7); + nessie_hash_ctx.hash_init(ctx); + while(n>=nessie_hash_ctx.blocksize_B*8){ + nessie_hash_ctx.hash_next(block, ctx); + n -= nessie_hash_ctx.blocksize_B*8; + } + nessie_hash_ctx.hash_last(block, n, ctx); + nessie_hash_ctx.hash_conv(hash, ctx); + nessie_print_item("hash", hash, (nessie_hash_ctx.hashsize_b+7)/8); +} + +static +void tv4_hash(void){ + uint8_t ctx[nessie_hash_ctx.ctx_size_B]; + uint8_t hash[(nessie_hash_ctx.hashsize_b+7)/8]; + uint8_t block[256/8]; + uint16_t n=256; + uint32_t i; + + uart_putstr_P(PSTR("\r\n message=")); + uart_putstr(PSTR("256 zero bits")); + memset(block, 0, 256/8); + + nessie_hash_ctx.hash_init(ctx); + while(n>=nessie_hash_ctx.blocksize_B*8){ + nessie_hash_ctx.hash_next(block, ctx); + n -= nessie_hash_ctx.blocksize_B*8; + } + nessie_hash_ctx.hash_last(block, n, ctx); + nessie_hash_ctx.hash_conv(hash, ctx); + nessie_print_item("hash", hash, (nessie_hash_ctx.hashsize_b+7)/8); + for(i=1; i<100000L; ++i){ /* this assumes BLOCKSIZE >= HASHSIZE */ + nessie_hash_ctx.hash_init(ctx); + nessie_hash_ctx.hash_last(hash, nessie_hash_ctx.hashsize_b, ctx); + nessie_hash_ctx.hash_conv(hash, ctx); + } + nessie_print_item("iterated 100000 times", hash, (nessie_hash_ctx.hashsize_b+7)/8); +} + +/* + "" (empty string) + message="a" + message="abc" + message="message digest" + message="abcdefghijklmnopqrstuvwxyz" + message="abcdbcdecdefdefgefghfghighijhijkijkljklmklmnlmnomnopnopq" + message="A...Za...z0...9" + message=8 times "1234567890" +*/ + + +void nessie_hash_run(void){ + uint16_t i; + uint8_t set; + + nessie_print_header(nessie_hash_ctx.name, 0, 0, nessie_hash_ctx.hashsize_b, 0, 0); + /* test set 1 */ + char* challange[8][2]= { + {"", "\"\" (empty string)"}, + {"a", "\"a\""}, + {"abc", "\"abc\""}, + {"message digest", "\"message digest\""}, + {"abcdefghijklmnopqrstuvwxyz","\"abcdefghijklmnopqrstuvwxyz\""}, + {"abcdbcdecdefdefgefghfghighijhijkijkljklmklmnlmnomnopnopq", + "\"abcdbcdecdefdefgefghfghighijhijkijkljklmklmnlmnomnopnopq\""}, + {"ABCDEFGHIJKLMNOPQRSTUVWXYZ" + "abcdefghijklmnopqrstuvwxyz" + "0123456789" , "\"A...Za...z0...9\""}, + {"1234567890" "1234567890" "1234567890" "1234567890" + "1234567890" "1234567890" "1234567890" "1234567890", + "8 times \"1234567890\""} + }; + set=1; + nessie_print_setheader(set); + for(i=0; i<8; ++i){ + nessie_print_set_vector(set, i); + ascii_hash(challange[i][0], challange[i][1]); + } + nessie_print_set_vector(set, i); + amillion_hash(); + /* test set 2 */ + set=2; + nessie_print_setheader(set); + for(i=0; i<1024; ++i){ + nessie_print_set_vector(set, i); + zero_hash(i); + } + /* test set 3 */ + set=3; + nessie_print_setheader(set); + for(i=0; i<512; ++i){ + nessie_print_set_vector(set, i); + one_in512_hash(i); + } + /* test set 4 */ + set=4; + nessie_print_setheader(set); + nessie_print_set_vector(set, 0); + tv4_hash(); + + nessie_print_footer(); +} diff --git a/test_src/nessie_hash_test.h b/test_src/nessie_hash_test.h new file mode 100644 index 0000000..aa88bdb --- /dev/null +++ b/test_src/nessie_hash_test.h @@ -0,0 +1,46 @@ +/* nessie_hash_test.h */ +/* + This file is part of the Crypto-avr-lib/microcrypt-lib. + Copyright (C) 2008 Daniel Otte (daniel.otte@rub.de) + + This program is free software: you can redistribute it and/or modify + it under the terms of the GNU General Public License as published by + the Free Software Foundation, either version 3 of the License, or + (at your option) any later version. + + This program is distributed in the hope that it will be useful, + but WITHOUT ANY WARRANTY; without even the implied warranty of + MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + GNU General Public License for more details. + + You should have received a copy of the GNU General Public License + along with this program. If not, see . +*/ +#ifndef NESSIE_HASH_TEST_H_ +#define NESSIE_HASH_TEST_H_ + +#include + +typedef void (*nessie_hash_init_fpt)(void* ctx); +typedef void (*nessie_hash_next_fpt)(void* buffer, void* ctx); +typedef void (*nessie_hash_last_fpt)(void* buffer, uint16_t size_b, void* ctx); +typedef void (*nessie_hash_conv_fpt)(void* buffer, void* ctx); + + +typedef struct nessie_hash_ctx_st{ + uint16_t hashsize_b; + uint16_t blocksize_B; + uint16_t ctx_size_B; + char* name; + nessie_hash_init_fpt hash_init; + nessie_hash_next_fpt hash_next; + nessie_hash_last_fpt hash_last; + nessie_hash_conv_fpt hash_conv; +} nessie_hash_ctx_t; + + +extern nessie_hash_ctx_t nessie_hash_ctx; + +void nessie_hash_run(void); + +#endif /*NESSIE_HASH_TEST_H_*/ diff --git a/test_src/nessie_mac_test.c b/test_src/nessie_mac_test.c new file mode 100644 index 0000000..12863df --- /dev/null +++ b/test_src/nessie_mac_test.c @@ -0,0 +1,270 @@ +/* nessie_mac_test.c */ +/* + This file is part of the Crypto-avr-lib/microcrypt-lib. + Copyright (C) 2008 Daniel Otte (daniel.otte@rub.de) + + This program is free software: you can redistribute it and/or modify + it under the terms of the GNU General Public License as published by + the Free Software Foundation, either version 3 of the License, or + (at your option) any later version. + + This program is distributed in the hope that it will be useful, + but WITHOUT ANY WARRANTY; without even the implied warranty of + MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + GNU General Public License for more details. + + You should have received a copy of the GNU General Public License + along with this program. If not, see . +*/ +/** + * + * author: Daniel Otte + * email: daniel.otte@rub.de + * license: GPLv3 + * + * a suit for running the nessie-tests for MACs + * + * */ +#include +#include +#include "nessie_mac_test.h" +#include "nessie_common.h" +#include "uart.h" + +nessie_mac_ctx_t nessie_mac_ctx; + +#define KEYSIZE_B ((nessie_mac_ctx.keysize_b+7)/8) +#define MACSIZE_B ((nessie_mac_ctx.macsize_b+7)/8) + +#define PRINTKEY nessie_print_item("key", key, KEYSIZE_B) +#define PRINTMAC nessie_print_item("MAC", mac, MACSIZE_B) + +static +void ascii_mac(char* data, char* desc, uint8_t* key){ + uint8_t ctx[nessie_mac_ctx.ctx_size_B]; + uint8_t mac[MACSIZE_B]; + uint16_t sl; + + uart_putstr_P(PSTR("\r\n message=")); + uart_putstr(desc); + PRINTKEY; + nessie_mac_ctx.mac_init(key, nessie_mac_ctx.keysize_b, ctx); + sl = strlen(data); + while(sl>=nessie_mac_ctx.blocksize_B){ + nessie_mac_ctx.mac_next(data, ctx); + data += nessie_mac_ctx.blocksize_B; + sl -= nessie_mac_ctx.blocksize_B; + } + nessie_mac_ctx.mac_last(data, sl*8, key, nessie_mac_ctx.keysize_b, ctx); + nessie_mac_ctx.mac_conv(mac, ctx); + PRINTMAC; +} + +// message=1 million times "a" + +static +void amillion_mac(uint8_t* key){ + uint8_t ctx[nessie_mac_ctx.ctx_size_B]; + uint8_t mac[MACSIZE_B]; + uint8_t block[nessie_mac_ctx.blocksize_B]; + uint32_t n=1000000LL; + + uart_putstr_P(PSTR("\r\n message=")); + uart_putstr_P(PSTR("1 million times \"a\"")); + PRINTKEY; + + memset(block, 'a', nessie_mac_ctx.blocksize_B); + nessie_mac_ctx.mac_init(key, nessie_mac_ctx.keysize_b, ctx); + while(n>=nessie_mac_ctx.blocksize_B){ + nessie_mac_ctx.mac_next(block, ctx); + n -= nessie_mac_ctx.blocksize_B; + } + nessie_mac_ctx.mac_last(block, n*8, key, nessie_mac_ctx.keysize_b, ctx); + nessie_mac_ctx.mac_conv(mac, ctx); + PRINTMAC; +} + + +static +void zero_mac(uint16_t n, uint8_t* key){ + uint8_t ctx[nessie_mac_ctx.ctx_size_B]; + uint8_t mac[MACSIZE_B]; + uint8_t block[nessie_mac_ctx.blocksize_B]; + + uart_putstr_P(PSTR("\r\n message=")); + if(n>=10000) + uart_putc('0'+n/10000); + if(n>=1000) + uart_putc('0'+(n/1000)%10); + if(n>=100) + uart_putc('0'+(n/100)%10); + if(n>=10) + uart_putc('0'+(n/10)%10); + uart_putc('0'+n%10); + uart_putstr_P(PSTR(" zero bits")); + PRINTKEY; + + memset(block, 0, nessie_mac_ctx.blocksize_B); + nessie_mac_ctx.mac_init(key, nessie_mac_ctx.keysize_b,ctx);; + while(n>=nessie_mac_ctx.blocksize_B*8){ + nessie_mac_ctx.mac_next(block, ctx); + n -= nessie_mac_ctx.blocksize_B*8; + } + nessie_mac_ctx.mac_last(block, n, key, nessie_mac_ctx.keysize_b, ctx); + nessie_mac_ctx.mac_conv(mac, ctx); + PRINTMAC; +} + +static +void one_in512_mac(uint16_t pos, uint8_t* key){ + uint8_t ctx[nessie_mac_ctx.ctx_size_B]; + uint8_t mac[MACSIZE_B]; + uint8_t block[nessie_mac_ctx.blocksize_B]; + uint16_t n=512; + char* tab[8]={"80", "40", "20", "10", + "08", "04", "02", "01" }; + + pos&=511; + uart_putstr_P(PSTR("\r\n message=")); + uart_putstr_P(PSTR("512-bit string: ")); + if((pos/8) >=10){ + uart_putc('0'+(pos/8/10)%10); + } else { + uart_putc(' '); + } + uart_putc('0'+(pos/8)%10); + uart_putstr_P(PSTR("*00,")); + uart_putstr(tab[pos&7]); + uart_putc(','); + if(63-(pos/8) >=10){ + uart_putc('0'+((63-pos/8)/10)%10); + } else { + uart_putc(' '); + } + uart_putc('0'+(63-pos/8)%10); + uart_putstr_P(PSTR("*00")); + PRINTKEY; + + /* now the real stuff */ + memset(block, 0, 512/8); + block[pos>>3] = 0x80>>(pos&0x7); + nessie_mac_ctx.mac_init(key, nessie_mac_ctx.keysize_b, ctx);; + while(n>=nessie_mac_ctx.blocksize_B*8){ + nessie_mac_ctx.mac_next(block, ctx); + n -= nessie_mac_ctx.blocksize_B*8; + } + nessie_mac_ctx.mac_last(block, n, key, nessie_mac_ctx.keysize_b, ctx); + nessie_mac_ctx.mac_conv(mac, ctx); + PRINTMAC; +} + +static +void tv4_mac(uint8_t* key){ + uint8_t ctx[nessie_mac_ctx.ctx_size_B]; + uint8_t mac[MACSIZE_B]; + uint8_t block[256/8]; + uint16_t n=256; + uint32_t i; + + uart_putstr_P(PSTR("\r\n message=")); + uart_putstr(PSTR("256 zero bits")); + memset(block, 0, 256/8); + + nessie_mac_ctx.mac_init(key, nessie_mac_ctx.keysize_b, ctx);; + while(n>=nessie_mac_ctx.blocksize_B*8){ + nessie_mac_ctx.mac_next(block, ctx); + n -= nessie_mac_ctx.blocksize_B*8; + } + nessie_mac_ctx.mac_last(block, n, key, nessie_mac_ctx.keysize_b, ctx); + nessie_mac_ctx.mac_conv(mac, ctx); + PRINTMAC; + for(i=1; i<100000L; ++i){ /* this assumes BLOCKSIZE >= HASHSIZE */ + nessie_mac_ctx.mac_init(key, nessie_mac_ctx.keysize_b, ctx);; + nessie_mac_ctx.mac_last(mac, nessie_mac_ctx.macsize_b, key, nessie_mac_ctx.keysize_b, ctx); + nessie_mac_ctx.mac_conv(mac, ctx); + } + nessie_print_item("iterated 100000 times", mac, MACSIZE_B); +} + + +void nessie_mac_run(void){ + uint16_t i; + uint8_t set; + uint8_t keyproto[] = {0x00, 0x11, 0x22, 0x33, 0x44, 0x55, 0x66, 0x77, + 0x88, 0x99, 0xaa, 0xbb, 0xcc, 0xdd, 0xee, 0xff, + 0x01, 0x23, 0x45, 0x67, 0x89, 0xab, 0xcd, 0xef }; + uint8_t key[KEYSIZE_B]; + + nessie_print_header(nessie_mac_ctx.name, nessie_mac_ctx.keysize_b, 0, 0, + nessie_mac_ctx.macsize_b, 0); + /* test set 1 */ + char* challange[10][2]= { + {"", "\"\" (empty string)"}, + {"a", "\"a\""}, + {"abc", "\"abc\""}, + {"message digest", "\"message digest\""}, + {"abcdefghijklmnopqrstuvwxyz","\"abcdefghijklmnopqrstuvwxyz\""}, + {"abcdbcdecdefdefgefghfghighijhijkijkljklmklmnlmnomnopnopq", + "\"abcdbcdecdefdefgefghfghighijhijkijkljklmklmnlmnomnopnopq\""}, + {"ABCDEFGHIJKLMNOPQRSTUVWXYZ" + "abcdefghijklmnopqrstuvwxyz" + "0123456789" , "\"A...Za...z0...9\""}, + {"1234567890" "1234567890" "1234567890" "1234567890" + "1234567890" "1234567890" "1234567890" "1234567890", + "8 times \"1234567890\""}, + {"Now is the time for all ", "\"Now is the time for all \""}, + {"Now is the time for it", "\"Now is the time for it\""} + }; + set=1; + nessie_print_setheader(set); + for(i=0; i>3]=0x80>>(i&0x7); + ascii_mac("ABC", "\"ABC\"", key); + } + nessie_print_footer(); +} diff --git a/test_src/nessie_mac_test.h b/test_src/nessie_mac_test.h new file mode 100644 index 0000000..ed83133 --- /dev/null +++ b/test_src/nessie_mac_test.h @@ -0,0 +1,47 @@ +/* nessie_mac_test.h */ +/* + This file is part of the Crypto-avr-lib/microcrypt-lib. + Copyright (C) 2008 Daniel Otte (daniel.otte@rub.de) + + This program is free software: you can redistribute it and/or modify + it under the terms of the GNU General Public License as published by + the Free Software Foundation, either version 3 of the License, or + (at your option) any later version. + + This program is distributed in the hope that it will be useful, + but WITHOUT ANY WARRANTY; without even the implied warranty of + MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + GNU General Public License for more details. + + You should have received a copy of the GNU General Public License + along with this program. If not, see . +*/ +#ifndef NESSIE_MAC_TEST_H_ +#define NESSIE_MAC_TEST_H_ + +#include + +typedef void (*nessie_mac_init_fpt)(void* key, uint16_t keysize_b, void* ctx); +typedef void (*nessie_mac_next_fpt)(void* buffer, void* ctx); +typedef void (*nessie_mac_last_fpt)(void* buffer, uint16_t size_b, void* key, uint16_t keysize_b, void* ctx); +typedef void (*nessie_mac_conv_fpt)(void* buffer, void* ctx); + + +typedef struct nessie_mac_ctx_st{ + uint16_t macsize_b; + uint16_t keysize_b; + uint16_t blocksize_B; + uint16_t ctx_size_B; + char* name; + nessie_mac_init_fpt mac_init; + nessie_mac_next_fpt mac_next; + nessie_mac_last_fpt mac_last; + nessie_mac_conv_fpt mac_conv; +} nessie_mac_ctx_t; + + +extern nessie_mac_ctx_t nessie_mac_ctx; + +void nessie_mac_run(void); + +#endif /*NESSIE_MAC_TEST_H_*/ diff --git a/test_src/nessie_stream_test.c b/test_src/nessie_stream_test.c new file mode 100644 index 0000000..3866b21 --- /dev/null +++ b/test_src/nessie_stream_test.c @@ -0,0 +1,192 @@ +/* nessie_stream_test.c */ +/* + This file is part of the Crypto-avr-lib/microcrypt-lib. + Copyright (C) 2008 Daniel Otte (daniel.otte@rub.de) + + This program is free software: you can redistribute it and/or modify + it under the terms of the GNU General Public License as published by + the Free Software Foundation, either version 3 of the License, or + (at your option) any later version. + + This program is distributed in the hope that it will be useful, + but WITHOUT ANY WARRANTY; without even the implied warranty of + MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + GNU General Public License for more details. + + You should have received a copy of the GNU General Public License + along with this program. If not, see . +*/ +/** + * + * author: Daniel Otte + * email: daniel.otte@rub.de + * license: GPLv3 + * + * a suit for running the nessie-tests for streamciphers + * + * */ +#include +#include +#include "nessie_stream_test.h" +#include "nessie_common.h" +#include "uart.h" + +nessie_stream_ctx_t nessie_stream_ctx; + + +#define BLOCKSIZE_B 64 + +static +void memxor(void* dest, void* src, uint8_t length){ + while(length--){ + *((uint8_t*)dest) ^= *((uint8_t*)src); + dest = (uint8_t*)dest +1; + src = (uint8_t*)src +1; + } +} + + +static +void nessie_gen_block(void* ctx, uint8_t* block){ + uint16_t i; + for(i=0; i>(i%8); + nessie_stream_enc(key); + } + /* test set 2 */ + set=2; + nessie_print_setheader(set); + for(i=0; i<256; ++i){ + nessie_print_set_vector(set, i); + memset(key, i, (nessie_stream_ctx.keysize_b+7)/8); + nessie_stream_enc(key); + } + /* test set 3 */ + set=3; + nessie_print_setheader(set); + for(i=0; i<256; ++i){ + uint8_t j; + nessie_print_set_vector(set, i); + for(j=0; j<(nessie_stream_ctx.keysize_b+7)/8; ++j){ + key[j]=(i+j)&0xff; + } + nessie_stream_enc(key); + } + /* test set 4 */ + set=4; + nessie_print_setheader(set); + for(i=0; i<4; ++i){ + uint8_t j; + nessie_print_set_vector(set, i); + for(j=0; j<(nessie_stream_ctx.keysize_b+7)/8; ++j){ + key[j]=(i*5+j*0x53)&0xff; + } + nessie_stream_enc_large(key); + } + + nessie_print_footer(); +} diff --git a/test_src/nessie_stream_test.h b/test_src/nessie_stream_test.h new file mode 100644 index 0000000..8422f45 --- /dev/null +++ b/test_src/nessie_stream_test.h @@ -0,0 +1,42 @@ +/* nessie_stream_test.h */ +/* + This file is part of the Crypto-avr-lib/microcrypt-lib. + Copyright (C) 2008 Daniel Otte (daniel.otte@rub.de) + + This program is free software: you can redistribute it and/or modify + it under the terms of the GNU General Public License as published by + the Free Software Foundation, either version 3 of the License, or + (at your option) any later version. + + This program is distributed in the hope that it will be useful, + but WITHOUT ANY WARRANTY; without even the implied warranty of + MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + GNU General Public License for more details. + + You should have received a copy of the GNU General Public License + along with this program. If not, see . +*/ +#ifndef NESSIE_STREAM_TEST_H_ +#define NESSIE_STREAM_TEST_H_ + +#include + +typedef void (*nessie_stream_genctx_fpt)(uint8_t* key, uint16_t keylength_b, void* ctx); +typedef uint8_t (*nessie_stream_genenc_fpt)(void* ctx); + +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; + nessie_stream_genctx_fpt cipher_genctx; + nessie_stream_genenc_fpt cipher_enc; +} nessie_stream_ctx_t; + + +extern nessie_stream_ctx_t nessie_stream_ctx; + +void nessie_stream_run(void); + +#endif /*NESSIE_STREAM_TEST_H_*/ diff --git a/test_src/performance_test.c b/test_src/performance_test.c new file mode 100644 index 0000000..04a26bd --- /dev/null +++ b/test_src/performance_test.c @@ -0,0 +1,112 @@ +/* performance_test.c */ +/* + This file is part of the Crypto-avr-lib/microcrypt-lib. + Copyright (C) 2008 Daniel Otte (daniel.otte@rub.de) + + This program is free software: you can redistribute it and/or modify + it under the terms of the GNU General Public License as published by + the Free Software Foundation, either version 3 of the License, or + (at your option) any later version. + + This program is distributed in the hope that it will be useful, + but WITHOUT ANY WARRANTY; without even the implied warranty of + MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + GNU General Public License for more details. + + You should have received a copy of the GNU General Public License + along with this program. If not, see . +*/ +/* + * author: Daniel Otte + * email: daniel.otte@rub.de + * license: GPLv3 + * + * + **/ + +#include "config.h" +#include +#include +#include +#include +#include +#include +#include "uart.h" +#include "performance_test.h" + + +#ifdef ATMEGA644 + #define TIMSK TIMSK1 +#endif + + + +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(TOIE1); /* 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; +} + +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); +} + + diff --git a/test_src/performance_test.h b/test_src/performance_test.h new file mode 100644 index 0000000..d8b1565 --- /dev/null +++ b/test_src/performance_test.h @@ -0,0 +1,33 @@ +/* performance_test.h */ +/* + This file is part of the Crypto-avr-lib/microcrypt-lib. + Copyright (C) 2008 Daniel Otte (daniel.otte@rub.de) + + This program is free software: you can redistribute it and/or modify + it under the terms of the GNU General Public License as published by + the Free Software Foundation, either version 3 of the License, or + (at your option) any later version. + + This program is distributed in the hope that it will be useful, + but WITHOUT ANY WARRANTY; without even the implied warranty of + MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + GNU General Public License for more details. + + You should have received a copy of the GNU General Public License + along with this program. If not, see . +*/ +#ifndef PERFORMANCE_TEST_H_ +#define PERFORMANCE_TEST_H_ + +#include +#include + +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_*/ diff --git a/test_src/serial-tools.c b/test_src/serial-tools.c new file mode 100644 index 0000000..47b6439 --- /dev/null +++ b/test_src/serial-tools.c @@ -0,0 +1,82 @@ +/* serial-tools.c */ +/* + This file is part of the Crypto-avr-lib/microcrypt-lib. + Copyright (C) 2008 Daniel Otte (daniel.otte@rub.de) + + This program is free software: you can redistribute it and/or modify + it under the terms of the GNU General Public License as published by + the Free Software Foundation, either version 3 of the License, or + (at your option) any later version. + + This program is distributed in the hope that it will be useful, + but WITHOUT ANY WARRANTY; without even the implied warranty of + MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + GNU General Public License for more details. + + You should have received a copy of the GNU General Public License + along with this program. If not, see . +*/ +/** + * + * Author: Daniel Otte + * Date: 16.05.2006 + * + * This tools should help to parse some input. + * + */ + +#include "config.h" +#include "uart.h" +#include +#include + +int getnextwordn(char *s, int n){ /* words are seperated by spaces */ + char c = ' '; + while ((c=uart_getc()) == ' ') + ; + *s++ = c; + while (n && (*s++=uart_getc())!=' ') + ; + *(s-1) = '\0'; + return n; +} + + +void readhex2buffer(void* buffer, int n){ + char c; + uint8_t i; + +// DEBUG_S("\r\nDBG: n="); DEBUG_B(n&0xff); DEBUG_S("\r\n"); + for(i=0; i=c){ + ((uint8_t*)buffer)[i] = c - '0'; + } else { + c &= ~('A' ^ 'a'); /* make all uppercase */ + if ('A'<= c && 'F'>=c){ + ((uint8_t*)buffer)[i] = c - 'A' + 10; + } else { + /* oh shit, wrong char */ + } + } + + ((uint8_t*)buffer)[i] <<= 4; + + c = uart_getc(); + if ('0'<= c && '9'>=c){ + ((uint8_t*)buffer)[i] |= c - '0'; + } else { + c &= ~('A' ^ 'a'); /* make all uppercase */ + if ('A'<= c && 'F'>=c){ + ((uint8_t*)buffer)[i] |= c - 'A' + 10; + } else { + /* oh shit, wrong char */ + } + } + } /* for i=0 .. n */ +} + +void uart_putptr(void* p){ + uart_hexdump((void*) &p,2); +} + diff --git a/test_src/serial-tools.h b/test_src/serial-tools.h new file mode 100644 index 0000000..c76b4d5 --- /dev/null +++ b/test_src/serial-tools.h @@ -0,0 +1,27 @@ +/* serial-tools.h */ +/* + This file is part of the Crypto-avr-lib/microcrypt-lib. + Copyright (C) 2008 Daniel Otte (daniel.otte@rub.de) + + This program is free software: you can redistribute it and/or modify + it under the terms of the GNU General Public License as published by + the Free Software Foundation, either version 3 of the License, or + (at your option) any later version. + + This program is distributed in the hope that it will be useful, + but WITHOUT ANY WARRANTY; without even the implied warranty of + MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + GNU General Public License for more details. + + You should have received a copy of the GNU General Public License + along with this program. If not, see . +*/ +#ifndef SERIALTOOLS_H_ +#define SERIALTOOLS_H_ + + +int getnextwordn(char *s, int n); /* words are seperated by spaces */ +void readhex2buffer(void* buffer, int n); +void uart_putptr(void* p); + +#endif /*SERIALTOOLS_H_*/ diff --git a/test_src/uart.c b/test_src/uart.c new file mode 100644 index 0000000..e35106c --- /dev/null +++ b/test_src/uart.c @@ -0,0 +1,324 @@ +/* uart.c */ +/* + This file is part of the Crypto-avr-lib/microcrypt-lib. + Copyright (C) 2008 Daniel Otte (daniel.otte@rub.de) + + This program is free software: you can redistribute it and/or modify + it under the terms of the GNU General Public License as published by + the Free Software Foundation, either version 3 of the License, or + (at your option) any later version. + + This program is distributed in the hope that it will be useful, + but WITHOUT ANY WARRANTY; without even the implied warranty of + MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + GNU General Public License for more details. + + You should have received a copy of the GNU General Public License + along with this program. If not, see . +*/ +/* USART-Init beim ATmegaXX */ + +#include "config.h" + +#include +#include +#include + +#include "uart.h" + +#ifdef ATMEGA128 +#define UCSRB UCSR0B +#define UCSRC UCSR0C +#define UDR UDR0 +#define UBRRH UBRR0H +#define UBRRL UBRR0L +#define URSEL UMSEL +#endif + +#ifdef ATMEGA644 +#define UCSRB UCSR0B +#define UCSRC UCSR0C +#define UDR UDR0 +#define UBRRH UBRR0H +#define UBRRL UBRR0L +#define URSEL UMSEL00 +#define USART_UDRE_vect USART0_UDRE_vect +#define USART_RXC_vect USART0_RX_vect +#define UDRIE UDRIE0 +#define TXEN TXEN0 +#define UMSEL UMSEL0 +#define RXEN RXEN0 +#define RXCIE RXCIE0 +#define UCSZ0 UCSZ00 +#define UCSRA UCSR0A +#define UDRE UDRE0 +#define RXC RXC0 +#endif + + +#ifdef UART_XON_XOFF + #ifdef UART_INTERRUPT + void uart_insertc(char c); + #else + #define uart_insertc uart_putc + #endif /* UART_INTERRUPT */ +#endif + +#define UART_BAUD_CALC(UART_BAUD_RATE,F_OSC) ((F_OSC)/((UART_BAUD_RATE)*16L)-1) + +#ifdef UART_XON_XOFF + typedef enum{go=1,nogo=0} gonogo; + static gonogo txon=go; + static gonogo rxon=go; +#endif + +#ifdef UART_INTERRUPT +volatile static char rxbuf[UART_RXBUFSIZE]; +volatile static char txbuf[UART_TXBUFSIZE]; +volatile static char *volatile rxhead, *volatile rxtail; +volatile static char *volatile txhead, *volatile txtail; + +#ifdef UART_HOOK + void (*uart_hook) (uint8_t) = (void*)0; /* this is a pointer to a function ;-) */ +#endif + +ISR(USART_UDRE_vect) { +#ifdef UART_LEDS + PORTC ^= 0x01; +#endif + + if ( txhead == txtail ) { + UCSRB &= ~(1 << UDRIE); /* disable data register empty IRQ */ + } else { + #ifdef UART_XON_XOFF + while(txon==nogo) + ; + #endif + UDR = *txtail; /* schreibt das Zeichen x auf die Schnittstelle */ + if (++txtail == (txbuf + UART_TXBUFSIZE)) txtail = txbuf; + } +} + +ISR(USART_RXC_vect) { + int diff; + char c; +#ifdef UART_HOOK + static volatile uint8_t hook_running=0; +#endif +#ifdef UART_LEDS + PORTC ^= 0x02; +#endif + c=UDR; + #ifdef UART_XON_XOFF + if (c==XON){ + txon=go; + return; + } + if (c==XOFF){ + txon=nogo; + return; + } + #endif + /* buffer full? */ + diff = rxhead - rxtail; + if (diff < 0) diff += UART_RXBUFSIZE; /* diff is the amount of bytes in buffer */ + if (diff < UART_RXBUFSIZE -1) { + // buffer NOT full +#ifdef UART_HOOK + if(!hook_running && uart_hook){ + uint8_t t=c; + hook_running = 1; + sei(); /* reenable interrupts, avoid recursion!!! */ + do { + uart_hook(t); + } while(uart_getc_nb((char*)&t)); + hook_running = 0; + } else { + *rxhead = c; + ++rxhead; + if (rxhead == (rxbuf + UART_RXBUFSIZE)) rxhead = rxbuf; + } +#else + *rxhead = c; + ++rxhead; + if (rxhead == (rxbuf + UART_RXBUFSIZE)) + rxhead = rxbuf; +#endif + } else { + //reads the buffer to clear the interrupt condition + } +#ifdef UART_XON_XOFF + if((diff > UART_XON_XOFF_THRESHOLD_1) && (rxon==go)){ + rxon=nogo; + uart_insertc(XOFF); + } + if((diff < UART_XON_XOFF_THRESHOLD_2) && (rxon==nogo)){ + rxon=go; + uart_insertc(XON); + } +#endif +} + +#endif // UART_INTERRUPT + + +void uart_init() { + PORTD |= 0x01; //Pullup an RXD an + + UCSRB |= (1<>8); + UBRRL=(uint8_t)(UART_BAUD_CALC(UART_BAUD_RATE,F_CPU)); + +#ifdef UART_INTERRUPT + // init buffers + rxhead = rxtail = rxbuf; + txhead = txtail = txbuf; + + // activate rx IRQ + UCSRB |= _BV(RXCIE) | _BV(UDRIE); + sei(); +// #ifdef ATMEGA644 +// UCSRB |= _BV(UDRIE); +// #endif +#endif // UART_INTERRUPT +} + +#ifdef UART_INTERRUPT +#ifdef UART_XON_XOFF + +void uart_insertc(char c){ + volatile int diff; + do { + diff = txhead - txtail; + if ( diff < 0 ) diff += UART_TXBUFSIZE; + } while ( diff >= UART_TXBUFSIZE -1 ); + + cli(); + if (--txtail == (txbuf-1)) txtail += UART_TXBUFSIZE; + *txtail = c; + + UCSRB |= (1 << UDRIE); /* enable data register empty IRQ */ + sei(); +} +#endif /* UART_XON_XOFF */ +void uart_putc(char c) { + volatile int diff; + + /* buffer full? */ + do { + diff = txhead - txtail; + if ( diff < 0 ) diff += UART_TXBUFSIZE; + } while ( diff >= UART_TXBUFSIZE -1 ); + + cli(); + *txhead = c; + if (++txhead == (txbuf + UART_TXBUFSIZE)) txhead = txbuf; + + UCSRB |= (1 << UDRIE); /* enable data register empty IRQ */ + sei(); +} +#else // WITHOUT INTERRUPT +void uart_putc(char c) { + while (!(UCSRA & (1<>4)&0xf]); + uart_putc(table[(*((char*)buf))&0xf]); + uart_putc(' '); + buf=(uint8_t*)buf+1; + } +} + + +#ifdef UART_INTERRUPT +char uart_getc(void) +{ + char val; + + while(rxhead==rxtail) + ; + + val = *rxtail; + ++rxtail; + if (rxtail == (rxbuf + UART_RXBUFSIZE)) + rxtail = rxbuf; + + return val; +} +#else // WITHOUT INTERRUPT +char uart_getc(void) +{ + char t; + while (!(UCSRA & (1<. -*/ -/* USART-Init beim ATmegaXX */ - -#include "config.h" - -#include -#include -#include - -#include "uart.h" - -#ifdef ATMEGA128 -#define UCSRB UCSR0B -#define UCSRC UCSR0C -#define UDR UDR0 -#define UBRRH UBRR0H -#define UBRRL UBRR0L -#define URSEL UMSEL -#endif - -#ifdef ATMEGA644 -#define UCSRB UCSR0B -#define UCSRC UCSR0C -#define UDR UDR0 -#define UBRRH UBRR0H -#define UBRRL UBRR0L -#define URSEL UMSEL00 -#define USART_UDRE_vect USART0_UDRE_vect -#define USART_RXC_vect USART0_RX_vect -#define UDRIE UDRIE0 -#define TXEN TXEN0 -#define UMSEL UMSEL0 -#define RXEN RXEN0 -#define RXCIE RXCIE0 -#define UCSZ0 UCSZ00 -#define UCSRA UCSR0A -#define UDRE UDRE0 -#define RXC RXC0 -#endif - - -#ifdef UART_XON_XOFF - #ifdef UART_INTERRUPT - void uart_insertc(char c); - #else - #define uart_insertc uart_putc - #endif /* UART_INTERRUPT */ -#endif - -#define UART_BAUD_CALC(UART_BAUD_RATE,F_OSC) ((F_OSC)/((UART_BAUD_RATE)*16L)-1) - -#ifdef UART_XON_XOFF - typedef enum{go=1,nogo=0} gonogo; - static gonogo txon=go; - static gonogo rxon=go; -#endif - -#ifdef UART_INTERRUPT -volatile static char rxbuf[UART_RXBUFSIZE]; -volatile static char txbuf[UART_TXBUFSIZE]; -volatile static char *volatile rxhead, *volatile rxtail; -volatile static char *volatile txhead, *volatile txtail; - -#ifdef UART_HOOK - void (*uart_hook) (uint8_t) = (void*)0; /* this is a pointer to a function ;-) */ -#endif - -ISR(USART_UDRE_vect) { -#ifdef UART_LEDS - PORTC ^= 0x01; -#endif - - if ( txhead == txtail ) { - UCSRB &= ~(1 << UDRIE); /* disable data register empty IRQ */ - } else { - #ifdef UART_XON_XOFF - while(txon==nogo) - ; - #endif - UDR = *txtail; /* schreibt das Zeichen x auf die Schnittstelle */ - if (++txtail == (txbuf + UART_TXBUFSIZE)) txtail = txbuf; - } -} - -ISR(USART_RXC_vect) { - int diff; - char c; -#ifdef UART_HOOK - static volatile uint8_t hook_running=0; -#endif -#ifdef UART_LEDS - PORTC ^= 0x02; -#endif - c=UDR; - #ifdef UART_XON_XOFF - if (c==XON){ - txon=go; - return; - } - if (c==XOFF){ - txon=nogo; - return; - } - #endif - /* buffer full? */ - diff = rxhead - rxtail; - if (diff < 0) diff += UART_RXBUFSIZE; /* diff is the amount of bytes in buffer */ - if (diff < UART_RXBUFSIZE -1) { - // buffer NOT full -#ifdef UART_HOOK - if(!hook_running && uart_hook){ - uint8_t t=c; - hook_running = 1; - sei(); /* reenable interrupts, avoid recursion!!! */ - do { - uart_hook(t); - } while(uart_getc_nb((char*)&t)); - hook_running = 0; - } else { - *rxhead = c; - ++rxhead; - if (rxhead == (rxbuf + UART_RXBUFSIZE)) rxhead = rxbuf; - } -#else - *rxhead = c; - ++rxhead; - if (rxhead == (rxbuf + UART_RXBUFSIZE)) - rxhead = rxbuf; -#endif - } else { - //reads the buffer to clear the interrupt condition - } -#ifdef UART_XON_XOFF - if((diff > UART_XON_XOFF_THRESHOLD_1) && (rxon==go)){ - rxon=nogo; - uart_insertc(XOFF); - } - if((diff < UART_XON_XOFF_THRESHOLD_2) && (rxon==nogo)){ - rxon=go; - uart_insertc(XON); - } -#endif -} - -#endif // UART_INTERRUPT - - -void uart_init() { - PORTD |= 0x01; //Pullup an RXD an - - UCSRB |= (1<>8); - UBRRL=(uint8_t)(UART_BAUD_CALC(UART_BAUD_RATE,F_CPU)); - -#ifdef UART_INTERRUPT - // init buffers - rxhead = rxtail = rxbuf; - txhead = txtail = txbuf; - - // activate rx IRQ - UCSRB |= _BV(RXCIE) | _BV(UDRIE); - sei(); -// #ifdef ATMEGA644 -// UCSRB |= _BV(UDRIE); -// #endif -#endif // UART_INTERRUPT -} - -#ifdef UART_INTERRUPT -#ifdef UART_XON_XOFF - -void uart_insertc(char c){ - volatile int diff; - do { - diff = txhead - txtail; - if ( diff < 0 ) diff += UART_TXBUFSIZE; - } while ( diff >= UART_TXBUFSIZE -1 ); - - cli(); - if (--txtail == (txbuf-1)) txtail += UART_TXBUFSIZE; - *txtail = c; - - UCSRB |= (1 << UDRIE); /* enable data register empty IRQ */ - sei(); -} -#endif /* UART_XON_XOFF */ -void uart_putc(char c) { - volatile int diff; - - /* buffer full? */ - do { - diff = txhead - txtail; - if ( diff < 0 ) diff += UART_TXBUFSIZE; - } while ( diff >= UART_TXBUFSIZE -1 ); - - cli(); - *txhead = c; - if (++txhead == (txbuf + UART_TXBUFSIZE)) txhead = txbuf; - - UCSRB |= (1 << UDRIE); /* enable data register empty IRQ */ - sei(); -} -#else // WITHOUT INTERRUPT -void uart_putc(char c) { - while (!(UCSRA & (1<>4)&0xf]); - uart_putc(table[(*((char*)buf))&0xf]); - uart_putc(' '); - buf=(uint8_t*)buf+1; - } -} - - -#ifdef UART_INTERRUPT -char uart_getc(void) -{ - char val; - - while(rxhead==rxtail) - ; - - val = *rxtail; - ++rxtail; - if (rxtail == (rxbuf + UART_RXBUFSIZE)) - rxtail = rxbuf; - - return val; -} -#else // WITHOUT INTERRUPT -char uart_getc(void) -{ - char t; - while (!(UCSRA & (1<