From: bg Date: Thu, 12 Mar 2009 20:23:49 +0000 (+0000) Subject: +skein X-Git-Url: https://git.cryptolib.org/?p=avr-crypto-lib.git;a=commitdiff_plain;h=b5a057d2dfa6b43f3850b3858c11a079eb9086f0 +skein --- diff --git a/mkfiles/base64.mk b/mkfiles/base64.mk index ef652aa..35695c4 100644 --- a/mkfiles/base64.mk +++ b/mkfiles/base64.mk @@ -1,4 +1,4 @@ -# Makefile for noekeon +# Makefile for Base64-encoding ALGO_NAME := BASE64 # comment out the following line for removement of base64 from the build process diff --git a/mkfiles/skein.mk b/mkfiles/skein.mk new file mode 100644 index 0000000..a2d6ea4 --- /dev/null +++ b/mkfiles/skein.mk @@ -0,0 +1,14 @@ +# Makefile for Skein +ALGO_NAME := SKEIN_C + +# comment out the following line for removement of Skein from the build process +HASHES += $(ALGO_NAME) + + +$(ALGO_NAME)_OBJ := threefish256_enc.o threefish512_enc.o threefish1024_enc.o \ + ubi256.o ubi512.o ubi1024.o memxor.o skein256.o skein512.o skein1024.o +$(ALGO_NAME)_TEST_BIN := main-skein-test.o debug.o uart.o hexdigit_tab.o \ + dbz_strings.o nessie_common.o cli.o string-extras.o performance_test.o +$(ALGO_NAME)_NESSIE_TEST := test nessie +$(ALGO_NAME)_PERFORMANCE_TEST := performance + diff --git a/mkfiles/threefish.mk b/mkfiles/threefish.mk index 71a4da4..a2e47ca 100644 --- a/mkfiles/threefish.mk +++ b/mkfiles/threefish.mk @@ -1,4 +1,4 @@ -# Makefile for noekeon +# Makefile for threefish ALGO_NAME := THREEFISH_C # comment out the following line for removement of threefish from the build process diff --git a/mkfiles/ubi.mk b/mkfiles/ubi.mk index 06ca291..f331cb6 100644 --- a/mkfiles/ubi.mk +++ b/mkfiles/ubi.mk @@ -1,8 +1,8 @@ -# Makefile for noekeon +# Makefile for UBI ALGO_NAME := UBI_C -# comment out the following line for removement of threefish from the build process -BLOCK_CIPHERS += $(ALGO_NAME) +# comment out the following line for removement of ubi from the build process +HASHES += $(ALGO_NAME) $(ALGO_NAME)_OBJ := threefish256_enc.o threefish512_enc.o threefish1024_enc.o \ diff --git a/skein.h b/skein.h new file mode 100644 index 0000000..94eceac --- /dev/null +++ b/skein.h @@ -0,0 +1,62 @@ +/* skein.h */ +/* + This file is part of the AVR-Crypto-Lib. + Copyright (C) 2009 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 + * \date 2009-03-12 + * \license GPLv3 or later + * + */ + +#ifndef SKEIN_H_ +#define SKEIN_H_ + +#include "ubi.h" + +typedef struct{ + uint16_t outsize_b; + ubi256_ctx_t ubictx; +}skein256_ctx_t; + +void skein256_init(skein256_ctx_t* ctx, uint16_t outsize_b); +void skein256_nextBlock(skein256_ctx_t* ctx, void* block); +void skein256_lastBlock(skein256_ctx_t* ctx, void* block, uint16_t length_b); +void skein256_ctx2hash(void* dest, skein256_ctx_t* ctx); + +typedef struct{ + uint16_t outsize_b; + ubi512_ctx_t ubictx; +}skein512_ctx_t; + +void skein512_init(skein512_ctx_t* ctx, uint16_t outsize_b); +void skein512_nextBlock(skein512_ctx_t* ctx, void* block); +void skein512_lastBlock(skein512_ctx_t* ctx, void* block, uint16_t length_b); +void skein512_ctx2hash(void* dest, skein512_ctx_t* ctx); + +typedef struct{ + uint16_t outsize_b; + ubi1024_ctx_t ubictx; +}skein1024_ctx_t; + +void skein1024_init(skein1024_ctx_t* ctx, uint16_t outsize_b); +void skein1024_nextBlock(skein1024_ctx_t* ctx, void* block); +void skein1024_lastBlock(skein1024_ctx_t* ctx, void* block, uint16_t length_b); +void skein1024_ctx2hash(void* dest, skein1024_ctx_t* ctx); + +#endif /* SKEIN_H_ */ diff --git a/skein1024.c b/skein1024.c new file mode 100644 index 0000000..d8e9b47 --- /dev/null +++ b/skein1024.c @@ -0,0 +1,82 @@ +/* skein1024.c */ +/* + This file is part of the AVR-Crypto-Lib. + Copyright (C) 2009 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 + * \date 2009-03-12 + * \license GPLv3 or later + * + */ + +#include +#include +#include "ubi.h" +#include "skein.h" + + +void skein1024_init(skein1024_ctx_t* ctx, uint16_t outsize_b){ + skein_config_t conf; + uint8_t null[UBI1024_BLOCKSIZE_B]; + memset(null, 0, UBI1024_BLOCKSIZE_B); + memset(&conf, 0, sizeof(skein_config_t)); + conf.schema[0] = 'S'; + conf.schema[1] = 'H'; + conf.schema[2] = 'A'; + conf.schema[3] = '3'; + conf.version = 1; + conf.out_length = outsize_b; + ctx->outsize_b = outsize_b; + ubi1024_init(&(ctx->ubictx), null, UBI_TYPE_CFG); + ubi1024_lastBlock(&(ctx->ubictx), &conf, 256); + ubi1024_init(&(ctx->ubictx), ctx->ubictx.g, UBI_TYPE_MSG); +} + +void skein1024_nextBlock(skein1024_ctx_t* ctx, void* block){ + ubi1024_nextBlock(&(ctx->ubictx), block); +} + +void skein1024_lastBlock(skein1024_ctx_t* ctx, void* block, uint16_t length_b){ + ubi1024_lastBlock(&(ctx->ubictx), block, length_b); +} + +void skein1024_ctx2hash(void* dest, skein1024_ctx_t* ctx){ + ubi1024_ctx_t uctx; + uint16_t outsize_b; + + uint64_t counter=0; + uint8_t outbuffer[UBI1024_BLOCKSIZE_B]; + ubi1024_init(&(ctx->ubictx), ctx->ubictx.g, UBI_TYPE_OUT); + + outsize_b = ctx->outsize_b; + while(outsize_b){ + memcpy(&uctx, &(ctx->ubictx), sizeof(ubi1024_ctx_t)); + ubi1024_lastBlock(&uctx, &counter, 64); + ubi1024_ctx2hash(outbuffer, &uctx); + if(outsize_b<=UBI1024_BLOCKSIZE_B){ + memcpy(dest, outbuffer, (ctx->outsize_b+7)/8); + outsize_b=0; + }else{ + memcpy(dest, outbuffer, UBI1024_BLOCKSIZE_B); + dest = (uint8_t*)dest + UBI1024_BLOCKSIZE_B; + outsize_b -= UBI1024_BLOCKSIZE; + counter++; + } + } +} + diff --git a/skein256.c b/skein256.c new file mode 100644 index 0000000..f397415 --- /dev/null +++ b/skein256.c @@ -0,0 +1,83 @@ +/* skein256.c */ +/* + This file is part of the AVR-Crypto-Lib. + Copyright (C) 2009 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 + * \date 2009-03-12 + * \license GPLv3 or later + * + */ + +#include +#include +#include "ubi.h" +#include "skein.h" + + +void skein256_init(skein256_ctx_t* ctx, uint16_t outsize_b){ + skein_config_t conf; + uint8_t null[UBI256_BLOCKSIZE_B]; + memset(null, 0, UBI256_BLOCKSIZE_B); + memset(&conf, 0, sizeof(skein_config_t)); + conf.schema[0] = 'S'; + conf.schema[1] = 'H'; + conf.schema[2] = 'A'; + conf.schema[3] = '3'; + conf.version = 1; + conf.out_length = outsize_b; + ctx->outsize_b = outsize_b; + ubi256_init(&(ctx->ubictx), null, UBI_TYPE_CFG); + ubi256_lastBlock(&(ctx->ubictx), &conf, 256); + ubi256_init(&(ctx->ubictx), ctx->ubictx.g, UBI_TYPE_MSG); +} + +void skein256_nextBlock(skein256_ctx_t* ctx, void* block){ + ubi256_nextBlock(&(ctx->ubictx), block); +} + +void skein256_lastBlock(skein256_ctx_t* ctx, void* block, uint16_t length_b){ + ubi256_lastBlock(&(ctx->ubictx), block, length_b); +} + +void skein256_ctx2hash(void* dest, skein256_ctx_t* ctx){ + ubi256_ctx_t uctx; + uint16_t outsize_b; + + uint64_t counter=0; + uint8_t outbuffer[UBI256_BLOCKSIZE_B]; + ubi256_init(&(ctx->ubictx), ctx->ubictx.g, UBI_TYPE_OUT); + + outsize_b = ctx->outsize_b; + while(outsize_b){ + memcpy(&uctx, &(ctx->ubictx), sizeof(ubi256_ctx_t)); + ubi256_lastBlock(&uctx, &counter, 64); + ubi256_ctx2hash(outbuffer, &uctx); + if(outsize_b<=UBI256_BLOCKSIZE_B){ + memcpy(dest, outbuffer, (ctx->outsize_b+7)/8); + outsize_b=0; + }else{ + memcpy(dest, outbuffer, UBI256_BLOCKSIZE_B); + dest = (uint8_t*)dest + UBI256_BLOCKSIZE_B; + outsize_b -= UBI256_BLOCKSIZE; + counter++; + } + } +} + + diff --git a/skein512.c b/skein512.c new file mode 100644 index 0000000..8603575 --- /dev/null +++ b/skein512.c @@ -0,0 +1,82 @@ +/* skein512.c */ +/* + This file is part of the AVR-Crypto-Lib. + Copyright (C) 2009 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 + * \date 2009-03-12 + * \license GPLv3 or later + * + */ + +#include +#include +#include "ubi.h" +#include "skein.h" + + +void skein512_init(skein512_ctx_t* ctx, uint16_t outsize_b){ + skein_config_t conf; + uint8_t null[UBI512_BLOCKSIZE_B]; + memset(null, 0, UBI512_BLOCKSIZE_B); + memset(&conf, 0, sizeof(skein_config_t)); + conf.schema[0] = 'S'; + conf.schema[1] = 'H'; + conf.schema[2] = 'A'; + conf.schema[3] = '3'; + conf.version = 1; + conf.out_length = outsize_b; + ctx->outsize_b = outsize_b; + ubi512_init(&(ctx->ubictx), null, UBI_TYPE_CFG); + ubi512_lastBlock(&(ctx->ubictx), &conf, 256); + ubi512_init(&(ctx->ubictx), ctx->ubictx.g, UBI_TYPE_MSG); +} + +void skein512_nextBlock(skein512_ctx_t* ctx, void* block){ + ubi512_nextBlock(&(ctx->ubictx), block); +} + +void skein512_lastBlock(skein512_ctx_t* ctx, void* block, uint16_t length_b){ + ubi512_lastBlock(&(ctx->ubictx), block, length_b); +} + +void skein512_ctx2hash(void* dest, skein512_ctx_t* ctx){ + ubi512_ctx_t uctx; + uint16_t outsize_b; + + uint64_t counter=0; + uint8_t outbuffer[UBI512_BLOCKSIZE_B]; + ubi512_init(&(ctx->ubictx), ctx->ubictx.g, UBI_TYPE_OUT); + + outsize_b = ctx->outsize_b; + while(outsize_b){ + memcpy(&uctx, &(ctx->ubictx), sizeof(ubi512_ctx_t)); + ubi512_lastBlock(&uctx, &counter, 64); + ubi512_ctx2hash(outbuffer, &uctx); + if(outsize_b<=UBI512_BLOCKSIZE_B){ + memcpy(dest, outbuffer, (ctx->outsize_b+7)/8); + outsize_b=0; + }else{ + memcpy(dest, outbuffer, UBI512_BLOCKSIZE_B); + dest = (uint8_t*)dest + UBI512_BLOCKSIZE_B; + outsize_b -= UBI512_BLOCKSIZE; + counter++; + } + } +} + diff --git a/test_src/cli.c b/test_src/cli.c index 68d6cf6..2bfbae7 100644 --- a/test_src/cli.c +++ b/test_src/cli.c @@ -169,6 +169,29 @@ void cli_hexdump2(void* data, uint16_t length){ } } +/** + * \brief dumps the contents of a buffer to the console + * Like cli_hexdump but bytes are seperated with a single space + * on the console output. + */ +void cli_hexdump_block(void* data, uint16_t length, uint8_t indent, uint8_t width){ + uint16_t i; + uint8_t j; + if(!cli_tx) + return; + for(i=0; i>4))); + cli_tx(pgm_read_byte(hexdigit_tab_P +((*((uint8_t*)data))&0xf))); + cli_tx(' '); + data = (uint8_t*)data +1; + } +} static void cli_auto_help(uint16_t maxcmdlength, PGM_VOID_P cmdlist){ diff --git a/test_src/cli.h b/test_src/cli.h index 3156d7e..58c3bfc 100644 --- a/test_src/cli.h +++ b/test_src/cli.h @@ -62,6 +62,8 @@ void cli_putstr_P(PGM_P s); void cli_hexdump(void* data, uint16_t length); void cli_hexdump_rev(void* data, uint16_t length); void cli_hexdump2(void* data, uint16_t length); +void cli_hexdump_block(void* data, uint16_t length, uint8_t indent, uint8_t width); + void echo_ctrl(char* s); int8_t cmd_interface(PGM_VOID_P cmd_desc); diff --git a/test_src/main-skein-test.c b/test_src/main-skein-test.c new file mode 100644 index 0000000..7faaa68 --- /dev/null +++ b/test_src/main-skein-test.c @@ -0,0 +1,286 @@ +/* main-skein-test.c */ +/* + This file is part of the AVR-Crypto-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 . +*/ +/* + * threefish test-suit + * +*/ + +#include "config.h" +#include "serial-tools.h" +#include "uart.h" +#include "debug.h" + +#include "skein.h" +#include "cli.h" +#include "performance_test.h" + +#include +#include +#include + +char* algo_name = "Skein"; + +/***************************************************************************** + * additional validation-functions * + *****************************************************************************/ +void testrun_stdtest_skein256(uint16_t outsize_b){ + uint8_t message[64]; + uint8_t hash[(outsize_b+7)/8]; + uint8_t i; + skein256_ctx_t ctx; + + cli_putstr_P(PSTR("\r\n\r\nTest vectors for Skein (256 bits):")); + for(i=0; i<64; ++i) + message[i] = 0xFF-i; + + cli_putstr_P(PSTR("\r\nmessage: ")); + cli_hexdump(message, 1); + skein256_init(&ctx, outsize_b); + skein256_lastBlock(&ctx, message, 8); + skein256_ctx2hash(hash, &ctx); + cli_putstr_P(PSTR("\r\nhash:")); + cli_hexdump_block(hash, (outsize_b+7)/8, 4, 16); + + cli_putstr_P(PSTR("\r\nmessage:")); + cli_hexdump_block(message, 32, 4, 16); + skein256_init(&ctx, outsize_b); + skein256_lastBlock(&ctx, message, 32*8); + skein256_ctx2hash(hash, &ctx); + cli_putstr_P(PSTR("\r\nhash:")); + cli_hexdump_block(hash, (outsize_b+7)/8, 4, 16); + + cli_putstr_P(PSTR("\r\nmessage:")); + cli_hexdump_block(message, 64, 4, 16); + skein256_init(&ctx, outsize_b); + skein256_lastBlock(&ctx, message, 64*8); + skein256_ctx2hash(hash, &ctx); + cli_putstr_P(PSTR("\r\nhash:")); + cli_hexdump_block(hash, (outsize_b+7)/8, 4, 16); +} + +void testrun_stdtest_skein512(uint16_t outsize_b){ + uint8_t message[128]; + uint8_t hash[(outsize_b+7)/8]; + uint8_t i; + skein512_ctx_t ctx; + + cli_putstr_P(PSTR("\r\n\r\nTest vectors for Skein (512 bits):")); + for(i=0; i<128; ++i) + message[i] = 0xFF-i; + + cli_putstr_P(PSTR("\r\nmessage: ")); + cli_hexdump(message, 1); + skein512_init(&ctx, outsize_b); + skein512_lastBlock(&ctx, message, 8); + skein512_ctx2hash(hash, &ctx); + cli_putstr_P(PSTR("\r\nhash:")); + cli_hexdump_block(hash, (outsize_b+7)/8, 4, 16); + + cli_putstr_P(PSTR("\r\nmessage:")); + cli_hexdump_block(message, 64, 4, 16); + skein512_init(&ctx, outsize_b); + skein512_lastBlock(&ctx, message, 64*8); + skein512_ctx2hash(hash, &ctx); + cli_putstr_P(PSTR("\r\nhash:")); + cli_hexdump_block(hash, (outsize_b+7)/8, 4, 16); + + cli_putstr_P(PSTR("\r\nmessage:")); + cli_hexdump_block(message, 128, 4, 16); + skein512_init(&ctx, outsize_b); + skein512_lastBlock(&ctx, message, 128*8); + skein512_ctx2hash(hash, &ctx); + cli_putstr_P(PSTR("\r\nhash:")); + cli_hexdump_block(hash, (outsize_b+7)/8, 4, 16); +} + +void testrun_stdtest_skein1024(uint16_t outsize_b){ + uint8_t message[256]; + uint8_t hash[(outsize_b+7)/8]; + uint16_t i; + skein1024_ctx_t ctx; + + cli_putstr_P(PSTR("\r\n\r\nTest vectors for Skein (1024 bits):")); + for(i=0; i<256; ++i) + message[i] = 0xFF-i; + + cli_putstr_P(PSTR("\r\nmessage: ")); + cli_hexdump(message, 1); + skein1024_init(&ctx, outsize_b); + skein1024_lastBlock(&ctx, message, 8); + skein1024_ctx2hash(hash, &ctx); + cli_putstr_P(PSTR("\r\nhash:")); + cli_hexdump_block(hash, (outsize_b+7)/8, 4, 16); + + cli_putstr_P(PSTR("\r\nmessage:")); + cli_hexdump_block(message, 128, 4, 16); + skein1024_init(&ctx, outsize_b); + skein1024_lastBlock(&ctx, message, 128*8); + skein1024_ctx2hash(hash, &ctx); + cli_putstr_P(PSTR("\r\nhash:")); + cli_hexdump_block(hash, (outsize_b+7)/8, 4, 16); + + cli_putstr_P(PSTR("\r\nmessage:")); + cli_hexdump_block(message, 256, 4, 16); + skein1024_init(&ctx, outsize_b); + skein1024_lastBlock(&ctx, message, 256*8); + skein1024_ctx2hash(hash, &ctx); + cli_putstr_P(PSTR("\r\nhash:")); + cli_hexdump_block(hash, (outsize_b+7)/8, 4, 16); +} + +void testrun_stdtest_skein(void){ + testrun_stdtest_skein256(256); + testrun_stdtest_skein512(512); + testrun_stdtest_skein1024(1024); +} +/* +void testrun_performance_threefish256(void){ + uint64_t t; + char str[16]; + uint8_t key[THREEFISH256_BLOCKSIZE_B]; + uint8_t data[THREEFISH256_BLOCKSIZE_B]; + uint8_t tweak[16]; + threefish256_ctx_t ctx; + + cli_putstr_P(PSTR("\r\nThreefish-256 performance:")); + + calibrateTimer(); + print_overhead(); + +// memset(key, 0, THREEFISH256_BLOCKSIZE_B); +// memset(tweak, 0, 16); + + startTimer(1); + threefish256_init(key, tweak, &ctx); + t = stopTimer(); + cli_putstr_P(PSTR("\r\n\tctx-gen time: ")); + ultoa((unsigned long)t, str, 10); + cli_putstr(str); + + startTimer(1); + threefish256_enc(data, &ctx); + t = stopTimer(); + cli_putstr_P(PSTR("\r\n\tencrypt time: ")); + ultoa((unsigned long)t, str, 10); + cli_putstr(str); + + cli_putstr_P(PSTR("\r\n")); +} + +void testrun_performance_threefish512(void){ + uint64_t t; + char str[16]; + uint8_t key[THREEFISH512_BLOCKSIZE_B]; + uint8_t data[THREEFISH512_BLOCKSIZE_B]; + uint8_t tweak[16]; + threefish512_ctx_t ctx; + + cli_putstr_P(PSTR("\r\nThreefish-512 performance:")); + + calibrateTimer(); + print_overhead(); + +// memset(key, 0, THREEFISH512_BLOCKSIZE_B); +// memset(tweak, 0, 16); + + startTimer(1); + threefish512_init(key, tweak, &ctx); + t = stopTimer(); + cli_putstr_P(PSTR("\r\n\tctx-gen time: ")); + ultoa((unsigned long)t, str, 10); + cli_putstr(str); + + startTimer(1); + threefish512_enc(data, &ctx); + t = stopTimer(); + cli_putstr_P(PSTR("\r\n\tencrypt time: ")); + ultoa((unsigned long)t, str, 10); + cli_putstr(str); + + cli_putstr_P(PSTR("\r\n")); +} + +void testrun_performance_threefish1024(void){ + uint64_t t; + char str[16]; + uint8_t key[THREEFISH1024_BLOCKSIZE_B]; + uint8_t data[THREEFISH1024_BLOCKSIZE_B]; + uint8_t tweak[16]; + threefish1024_ctx_t ctx; + + cli_putstr_P(PSTR("\r\nThreefish-1024 performance:")); + + calibrateTimer(); + print_overhead(); + +// memset(key, 0, THREEFISH1024_BLOCKSIZE_B); +// memset(tweak, 0, 16); + + startTimer(1); + threefish1024_init(key, tweak, &ctx); + t = stopTimer(); + cli_putstr_P(PSTR("\r\n\tctx-gen time: ")); + ultoa((unsigned long)t, str, 10); + cli_putstr(str); + + startTimer(1); + threefish1024_enc(data, &ctx); + t = stopTimer(); + cli_putstr_P(PSTR("\r\n\tencrypt time: ")); + ultoa((unsigned long)t, str, 10); + cli_putstr(str); + + cli_putstr_P(PSTR("\r\n")); +} + +void testrun_performance_threefish(void){ + testrun_performance_threefish256(); + testrun_performance_threefish512(); + testrun_performance_threefish1024(); +} +*/ +/***************************************************************************** + * main * + *****************************************************************************/ + +const char nessie_str[] PROGMEM = "nessie"; +const char test_str[] PROGMEM = "test"; +const char performance_str[] PROGMEM = "performance"; +const char echo_str[] PROGMEM = "echo"; + +cmdlist_entry_t cmdlist[] PROGMEM = { +// { nessie_str, NULL, testrun_nessie_noekeon}, + { test_str, NULL, testrun_stdtest_skein}, +// { performance_str, NULL, testrun_performance_threefish}, + { echo_str, (void*)1, (void_fpt)echo_ctrl}, + { NULL, NULL, NULL} +}; + +int main (void){ + DEBUG_INIT(); + + cli_rx = uart_getc; + cli_tx = uart_putc; + for(;;){ + cli_putstr_P(PSTR("\r\n\r\nCrypto-VS (")); + cli_putstr(algo_name); + cli_putstr_P(PSTR(")\r\nloaded and running\r\n")); + cmd_interface(cmdlist); + } +} diff --git a/test_src/main-threefish-test.c b/test_src/main-threefish-test.c index 6197e63..da964b3 100644 --- a/test_src/main-threefish-test.c +++ b/test_src/main-threefish-test.c @@ -217,6 +217,112 @@ void testrun_stdtest_threefish(void){ testrun_stdtest_threefish512(); testrun_stdtest_threefish1024(); } + +void testrun_performance_threefish256(void){ + uint64_t t; + char str[16]; + uint8_t key[THREEFISH256_BLOCKSIZE_B]; + uint8_t data[THREEFISH256_BLOCKSIZE_B]; + uint8_t tweak[16]; + threefish256_ctx_t ctx; + + cli_putstr_P(PSTR("\r\nThreefish-256 performance:")); + + calibrateTimer(); + print_overhead(); + +// memset(key, 0, THREEFISH256_BLOCKSIZE_B); +// memset(tweak, 0, 16); + + startTimer(1); + threefish256_init(key, tweak, &ctx); + t = stopTimer(); + cli_putstr_P(PSTR("\r\n\tctx-gen time: ")); + ultoa((unsigned long)t, str, 10); + cli_putstr(str); + + startTimer(1); + threefish256_enc(data, &ctx); + t = stopTimer(); + cli_putstr_P(PSTR("\r\n\tencrypt time: ")); + ultoa((unsigned long)t, str, 10); + cli_putstr(str); + + cli_putstr_P(PSTR("\r\n")); +} + +void testrun_performance_threefish512(void){ + uint64_t t; + char str[16]; + uint8_t key[THREEFISH512_BLOCKSIZE_B]; + uint8_t data[THREEFISH512_BLOCKSIZE_B]; + uint8_t tweak[16]; + threefish512_ctx_t ctx; + + cli_putstr_P(PSTR("\r\nThreefish-512 performance:")); + + calibrateTimer(); + print_overhead(); + +// memset(key, 0, THREEFISH512_BLOCKSIZE_B); +// memset(tweak, 0, 16); + + startTimer(1); + threefish512_init(key, tweak, &ctx); + t = stopTimer(); + cli_putstr_P(PSTR("\r\n\tctx-gen time: ")); + ultoa((unsigned long)t, str, 10); + cli_putstr(str); + + startTimer(1); + threefish512_enc(data, &ctx); + t = stopTimer(); + cli_putstr_P(PSTR("\r\n\tencrypt time: ")); + ultoa((unsigned long)t, str, 10); + cli_putstr(str); + + cli_putstr_P(PSTR("\r\n")); +} + +void testrun_performance_threefish1024(void){ + uint64_t t; + char str[16]; + uint8_t key[THREEFISH1024_BLOCKSIZE_B]; + uint8_t data[THREEFISH1024_BLOCKSIZE_B]; + uint8_t tweak[16]; + threefish1024_ctx_t ctx; + + cli_putstr_P(PSTR("\r\nThreefish-1024 performance:")); + + calibrateTimer(); + print_overhead(); + +// memset(key, 0, THREEFISH1024_BLOCKSIZE_B); +// memset(tweak, 0, 16); + + startTimer(1); + threefish1024_init(key, tweak, &ctx); + t = stopTimer(); + cli_putstr_P(PSTR("\r\n\tctx-gen time: ")); + ultoa((unsigned long)t, str, 10); + cli_putstr(str); + + startTimer(1); + threefish1024_enc(data, &ctx); + t = stopTimer(); + cli_putstr_P(PSTR("\r\n\tencrypt time: ")); + ultoa((unsigned long)t, str, 10); + cli_putstr(str); + + cli_putstr_P(PSTR("\r\n")); +} + +void testrun_performance_threefish(void){ + testrun_performance_threefish256(); + testrun_performance_threefish512(); + testrun_performance_threefish1024(); +} + /***************************************************************************** * main * *****************************************************************************/ @@ -229,7 +335,7 @@ const char echo_str[] PROGMEM = "echo"; cmdlist_entry_t cmdlist[] PROGMEM = { // { nessie_str, NULL, testrun_nessie_noekeon}, { test_str, NULL, testrun_stdtest_threefish}, -// { performance_str, NULL, testrun_performance_noekeon}, + { performance_str, NULL, testrun_performance_threefish}, { echo_str, (void*)1, (void_fpt)echo_ctrl}, { NULL, NULL, NULL} }; diff --git a/threefish.h b/threefish.h index 73871a4..618babe 100644 --- a/threefish.h +++ b/threefish.h @@ -28,6 +28,14 @@ #include +#define THREEFISH256_BLOCKSIZE 256 +#define THREEFISH256_BLOCKSIZE_B ((THREEFISH256_BLOCKSIZE+7)/8) +#define THREEFISH512_BLOCKSIZE 512 +#define THREEFISH512_BLOCKSIZE_B ((THREEFISH512_BLOCKSIZE+7)/8) +#define THREEFISH1024_BLOCKSIZE 1024 +#define THREEFISH1024_BLOCKSIZE_B ((THREEFISH1024_BLOCKSIZE+7)/8) + + typedef struct{ uint64_t k[5]; uint64_t t[3];