From 91bece1f7822ccaae033989525ee08f613de3802 Mon Sep 17 00:00:00 2001 From: bg Date: Wed, 9 Jul 2008 05:41:43 +0000 Subject: [PATCH] nessie for the rest (skipjack seems broken, shabea req. more testing) --- avr-makefile.inc | 2 +- main-md5-test.c | 42 +++++++++++++++--- main-seed-test.c | 103 ++++++++++++++++++++++++++++++++++--------- main-sha1-test.c | 38 +++++++++++++--- main-sha256-test.c | 14 +++--- main-shabea-test.c | 89 ++++++++++++++++++++++++++++++++----- main-skipjack-test.c | 72 +++++++++++++++++++++++++++--- mkfiles/md5.mk | 3 +- mkfiles/seed.mk | 3 +- mkfiles/sha1.mk | 2 +- mkfiles/sha256.mk | 2 +- mkfiles/shabea.mk | 3 +- mkfiles/skipjack.mk | 3 +- seed.c | 6 +-- seed.h | 6 +-- shabea.c | 14 +++--- shabea.h | 2 +- 17 files changed, 327 insertions(+), 77 deletions(-) diff --git a/avr-makefile.inc b/avr-makefile.inc index f0ea6c8..4d9555c 100644 --- a/avr-makefile.inc +++ b/avr-makefile.inc @@ -12,7 +12,7 @@ ERASECMD = 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,$<) -pedantic -std=c99 -Wall -Wstrict-prototypes $(OPTIMIZE) -mmcu=$(MCU_TARGET) $(DEFS) override LDFLAGS = -Wl,-Map, override ASFLAGS = -mmcu=$(MCU_TARGET) diff --git a/main-md5-test.c b/main-md5-test.c index 3ed1a1a..921b408 100644 --- a/main-md5-test.c +++ b/main-md5-test.c @@ -27,14 +27,42 @@ #include "debug.h" #include "md5.h" +#include "nessie_hash_test.h" #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 * @@ -85,15 +113,17 @@ int main (void){ uart_putstr("\r\n"); uart_putstr("\r\n\r\nCrypto-VS (MD5)\r\nloaded and running\r\n"); -restart: + PGM_P u = PSTR("nessie\0test\0"); + void_fpt v[] = {testrun_nessie_md5, testrun_md5}; + while(1){ - if (!getnextwordn(str,20)) {DEBUG_S("DBG: W1\r\n"); goto error;} - if (strcmp(str, "test")) {DEBUG_S("DBG: 1b\r\n"); goto error;} - testrun_md5(); - goto restart; + if (!getnextwordn(str,20)){DEBUG_S("DBG: W1\r\n"); goto error;} + if(execcommand_d0_P(str, u, v)<0){ + uart_putstr_P(PSTR("\r\nunknown command\r\n")); + } continue; error: uart_putstr("ERROR\r\n"); - } /* while (1) */ + } } diff --git a/main-seed-test.c b/main-seed-test.c index 813cb5c..1dc4259 100644 --- a/main-seed-test.c +++ b/main-seed-test.c @@ -32,14 +32,82 @@ #include "debug.h" #include "seed.h" +#include "nessie_bc_test.h" +#include "cli.h" +#include "performance_test.h" #include #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_encrypt; + nessie_bc_ctx.cipher_dec = (nessie_bc_dec_fpt)seed_decrypt; + nessie_bc_ctx.cipher_genctx = (nessie_bc_gen_fpt)seed_genctx_dummy; + + nessie_bc_run(); + +} + + +void testrun_performance_seed(void){ + uint16_t i,c; + uint64_t t; + char str[16]; + uint8_t key[16], data[16]; + seed_ctx_t ctx; + + calibrateTimer(); + getOverhead(&c, &i); + uart_putstr_P(PSTR("\r\n\r\n=== benchmark ===")); + utoa(c, str, 10); + uart_putstr_P(PSTR("\r\n\tconst overhead: ")); + uart_putstr(str); + utoa(i, str, 10); + uart_putstr_P(PSTR("\r\n\tinterrupt overhead: ")); + uart_putstr(str); + + memset(key, 0, 16); + memset(data, 0, 16); + + startTimer(1); + 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_encrypt(data, &ctx); + t = stopTimer(); + uart_putstr_P(PSTR("\r\n\tencrypt time: ")); + ultoa((unsigned long)t, str, 10); + uart_putstr(str); + + + startTimer(1); + seed_decrypt(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 * @@ -49,30 +117,24 @@ 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(&ctx, key); + seed_init(key, &ctx); uart_putstr("\r\n plain: "); uart_hexdump(block,16); - _delay_ms(50); - seed_encrypt(&ctx, block); + seed_encrypt(block, &ctx); uart_putstr("\r\n crypt: "); uart_hexdump(block,16); -// uart_putstr("\r\n post-state: "); -// uart_hexdump(ctx.k,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(&ctx, key); + seed_init(key, &ctx); uart_putstr("\r\n crypt: "); uart_hexdump(block,16); - _delay_ms(50); - seed_decrypt(&ctx, block); + seed_decrypt(block, &ctx); uart_putstr("\r\n plain: "); uart_hexdump(block,16); -// uart_putstr("\r\n post-state: "); -// uart_hexdump(ctx.k,16); } void testrun_seed(void){ @@ -101,7 +163,6 @@ void testrun_seed(void){ testencrypt(datas[i],keys[i]); testdecrypt(datas[i],keys[i]); } -// testdecrypt(data,key); } @@ -114,21 +175,23 @@ int main (void){ char str[20]; DEBUG_INIT(); - uart_putstr("\r\n"); - uart_putstr("\r\n\r\nCrypto-VS (seed)\r\nloaded and running\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_seed, testrun_seed, testrun_performance_seed}; -restart: while(1){ - if (!getnextwordn(str,20)) {DEBUG_S("DBG: W1\r\n"); goto error;} - if (strcmp(str, "test")) {DEBUG_S("DBG: 1b\r\n"); goto error;} - testrun_seed(); - goto restart; + if (!getnextwordn(str,20)){DEBUG_S("DBG: W1\r\n"); goto error;} + if(execcommand_d0_P(str, u, v)<0){ + uart_putstr_P(PSTR("\r\nunknown command\r\n")); + } continue; error: uart_putstr("ERROR\r\n"); } - } diff --git a/main-sha1-test.c b/main-sha1-test.c index c30c3c7..3fb74bd 100644 --- a/main-sha1-test.c +++ b/main-sha1-test.c @@ -27,14 +27,37 @@ #include "debug.h" #include "sha1.h" +#include "nessie_hash_test.h" #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 * @@ -93,17 +116,18 @@ int main (void){ uart_putstr("\r\n\r\nCrypto-VS (SHA-1)\r\nloaded and running\r\n"); -restart: + PGM_P u = PSTR("nessie\0test\0"); + void_fpt v[] = {testrun_nessie_sha1, testrun_sha1}; + while(1){ - if (!getnextwordn(str,20)) {DEBUG_S("DBG: W1\r\n"); goto error;} - if (strcmp(str, "test")) {DEBUG_S("DBG: 1b\r\n"); goto error;} - testrun_sha1(); - goto restart; + if (!getnextwordn(str,20)){DEBUG_S("DBG: W1\r\n"); goto error;} + if(execcommand_d0_P(str, u, v)<0){ + uart_putstr_P(PSTR("\r\nunknown command\r\n")); + } continue; error: uart_putstr("ERROR\r\n"); } - - } + diff --git a/main-sha256-test.c b/main-sha256-test.c index 4f8346f..552356c 100644 --- a/main-sha256-test.c +++ b/main-sha256-test.c @@ -31,6 +31,7 @@ #include #include +#include "cli.h" char* algo_name = "SHA-256"; @@ -73,16 +74,17 @@ int main (void){ uart_putstr(algo_name); uart_putstr_P(PSTR(")\r\nloaded and running\r\n")); -restart: + PGM_P u = PSTR("nessie\0test\0"); + void_fpt v[] = {testrun_nessie_sha256, testrun_nessie_sha256}; + 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_sha256(); - goto restart; + if (!getnextwordn(str,20)){DEBUG_S("DBG: W1\r\n"); goto error;} + if(execcommand_d0_P(str, u, v)<0){ + uart_putstr_P(PSTR("\r\nunknown command\r\n")); + } continue; error: uart_putstr("ERROR\r\n"); } - } diff --git a/main-shabea-test.c b/main-shabea-test.c index a83d0c7..418bcf6 100644 --- a/main-shabea-test.c +++ b/main-shabea-test.c @@ -31,14 +31,81 @@ #include "debug.h" #include "shabea.h" +#include "nessie_bc_test.h" +#include "cli.h" +#include "performance_test.h" #include #include -#include +#include + +char* cipher_name = "Shabea"; /***************************************************************************** * additional validation-functions * *****************************************************************************/ +void shabea_genctx_dummy(uint8_t* key, uint16_t keysize, void* ctx){ + memcpy(ctx, key, keysize); +} + +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){ + uint16_t i,c; + uint64_t t; + char str[16]; + uint8_t key[32], data[32]; + + calibrateTimer(); + getOverhead(&c, &i); + uart_putstr_P(PSTR("\r\n\r\n=== benchmark ===")); + utoa(c, str, 10); + uart_putstr_P(PSTR("\r\n\tconst overhead: ")); + uart_putstr(str); + utoa(i, str, 10); + uart_putstr_P(PSTR("\r\n\tinterrupt overhead: ")); + uart_putstr(str); + + memset(key, 0, 32); + memset(data, 0, 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 * @@ -49,7 +116,6 @@ void testencrypt(uint8_t* block, uint8_t* key){ uart_hexdump(key,16); uart_putstr("\r\n plain: "); uart_hexdump(block,32); - _delay_ms(50); shabea256(block,key,128,1,16); uart_putstr("\r\n crypt: "); uart_hexdump(block,32); @@ -61,7 +127,6 @@ void testdecrypt(uint8_t* block, uint8_t* key){ uart_hexdump(key,16); uart_putstr("\r\n crypt: "); uart_hexdump(block,32); - _delay_ms(50); shabea256(block,key,128,0,16); uart_putstr("\r\n plain: "); uart_hexdump(block,32); @@ -101,7 +166,6 @@ void testrun_shabea(void){ testencrypt(datas[i],keys[i]); testdecrypt(datas[i],keys[i]); } -// testdecrypt(data,key); } @@ -116,19 +180,22 @@ int main (void){ DEBUG_INIT(); uart_putstr("\r\n"); - uart_putstr("\r\n\r\nCrypto-VS (shabea)\r\nloaded and running\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}; -restart: while(1){ - if (!getnextwordn(str,20)) {DEBUG_S("DBG: W1\r\n"); goto error;} - if (strcmp(str, "test")) {DEBUG_S("DBG: 1b\r\n"); goto error;} - testrun_shabea(); - goto restart; + if (!getnextwordn(str,20)){DEBUG_S("DBG: W1\r\n"); goto error;} + if(execcommand_d0_P(str, u, v)<0){ + uart_putstr_P(PSTR("\r\nunknown command\r\n")); + } continue; error: uart_putstr("ERROR\r\n"); } - } diff --git a/main-skipjack-test.c b/main-skipjack-test.c index 7218d99..65f0d1f 100644 --- a/main-skipjack-test.c +++ b/main-skipjack-test.c @@ -27,14 +27,73 @@ #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){ + uint16_t i,c; + uint64_t t; + char str[16]; + uint8_t key[10], data[8]; + + calibrateTimer(); + getOverhead(&c, &i); + uart_putstr_P(PSTR("\r\n\r\n=== benchmark ===")); + utoa(c, str, 10); + uart_putstr_P(PSTR("\r\n\tconst overhead: ")); + uart_putstr(str); + utoa(i, str, 10); + uart_putstr_P(PSTR("\r\n\tinterrupt overhead: ")); + uart_putstr(str); + + memset(key, 0, 10); + memset(data, 0, 8); + + startTimer(1); + 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 * @@ -82,17 +141,18 @@ int main (void){ uart_putstr("\r\n\r\nCrypto-VS (skipjack)\r\nloaded and running\r\n"); -restart: + 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 (strcmp(str, "test")) {DEBUG_S("DBG: 1b\r\n"); goto error;} - testrun_skipjack(); - goto restart; + if (!getnextwordn(str,20)){DEBUG_S("DBG: W1\r\n"); goto error;} + if(execcommand_d0_P(str, u, v)<0){ + uart_putstr_P(PSTR("\r\nunknown command\r\n")); + } continue; error: uart_putstr("ERROR\r\n"); } - } diff --git a/mkfiles/md5.mk b/mkfiles/md5.mk index e6aeaa4..047fb21 100644 --- a/mkfiles/md5.mk +++ b/mkfiles/md5.mk @@ -5,7 +5,8 @@ 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 md5.o \ + nessie_hash_test.o nessie_common.o cli.o $(ALGO_NAME)_NESSIE_TEST := "nessie" $(ALGO_NAME)_PEROFRMANCE_TEST := "performance" diff --git a/mkfiles/seed.mk b/mkfiles/seed.mk index 37888a5..515597c 100644 --- a/mkfiles/seed.mk +++ b/mkfiles/seed.mk @@ -6,7 +6,8 @@ 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 + seed.o seed-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/sha1.mk b/mkfiles/sha1.mk index 96595e9..d4c1b5a 100644 --- a/mkfiles/sha1.mk +++ b/mkfiles/sha1.mk @@ -6,7 +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 + sha1-asm.o nessie_hash_test.o nessie_common.o cli.o $(ALGO_NAME)_NESSIE_TEST := "nessie" $(ALGO_NAME)_PEROFRMANCE_TEST := "performance" diff --git a/mkfiles/sha256.mk b/mkfiles/sha256.mk index 9d9dbaa..c1a3d58 100644 --- a/mkfiles/sha256.mk +++ b/mkfiles/sha256.mk @@ -6,7 +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 + sha256-asm.o nessie_hash_test.o nessie_common.o cli.o $(ALGO_NAME)_NESSIE_TEST := "nessie" $(ALGO_NAME)_PEROFRMANCE_TEST := "performance" diff --git a/mkfiles/shabea.mk b/mkfiles/shabea.mk index 3accd1f..8c9cc95 100644 --- a/mkfiles/shabea.mk +++ b/mkfiles/shabea.mk @@ -6,7 +6,8 @@ BLOCK_CIPHERS += $(ALGO_NAME) $(ALGO_NAME)_OBJ := shabea.o sha256-asm.o $(ALGO_NAME)_TEST_BIN := main-shabea-test.o debug.o uart.o serial-tools.o \ - shabea.o sha256-asm.o + shabea.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 a04ba8a..2a117a9 100644 --- a/mkfiles/skipjack.mk +++ b/mkfiles/skipjack.mk @@ -6,7 +6,8 @@ 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 + skipjack.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/seed.c b/seed.c index da240bd..29cd991 100644 --- a/seed.c +++ b/seed.c @@ -220,7 +220,7 @@ typedef struct{ /******************************************************************************/ -void seed_init(seed_ctx_t * ctx, uint8_t * key){ +void seed_init(uint8_t * key, seed_ctx_t * ctx){ memcpy(ctx->k, key, 128/8); } @@ -229,7 +229,7 @@ void seed_init(seed_ctx_t * ctx, uint8_t * key){ #define L (((uint64_t*)buffer)[0]) #define R (((uint64_t*)buffer)[1]) -void seed_encrypt(seed_ctx_t * ctx, void * buffer){ +void seed_encrypt(void * buffer, seed_ctx_t * ctx){ uint8_t r; keypair_t k; for(r=0; r<8; ++r){ @@ -262,7 +262,7 @@ void seed_encrypt(seed_ctx_t * ctx, void * buffer){ #define L (((uint64_t*)buffer)[0]) #define R (((uint64_t*)buffer)[1]) -void seed_decrypt(seed_ctx_t * ctx, void * buffer){ +void seed_decrypt(void * buffer, seed_ctx_t * ctx){ int8_t r; keypair_t k; for(r=7; r>=0; --r){ diff --git a/seed.h b/seed.h index 330944d..04b3566 100644 --- a/seed.h +++ b/seed.h @@ -36,8 +36,8 @@ typedef struct{ /******************************************************************************/ -void seed_init(seed_ctx_t * ctx, uint8_t * key); -void seed_encrypt(seed_ctx_t * ctx, void * buffer); -void seed_decrypt(seed_ctx_t * ctx, void * buffer); +void seed_init(uint8_t * key, seed_ctx_t * ctx); +void seed_encrypt(void * buffer, seed_ctx_t * ctx); +void seed_decrypt(void * buffer, seed_ctx_t * ctx); #endif /*SEED_H_*/ diff --git a/shabea.c b/shabea.c index 62ff6b4..49a1321 100644 --- a/shabea.c +++ b/shabea.c @@ -55,26 +55,26 @@ void memxor(uint8_t * dest, uint8_t * src, uint8_t length){ #define L ((uint8_t*)block+ 0) #define R ((uint8_t*)block+16) -void shabea256(void * block, void * key, uint16_t keysize, uint8_t enc, uint8_t rounds){ +void shabea256(void * block, void * key, uint16_t keysize_b, uint8_t enc, uint8_t rounds){ int8_t r; /**/ - uint8_t tb[HALFSIZEB+2+(keysize+7)/8]; /**/ + uint8_t tb[HALFSIZEB+2+(keysize_b+7)/8]; /**/ uint16_t kbs; /* bytes used for the key / temporary block */ sha256_hash_t hash; r = (enc?0:(rounds-1)); - kbs = (keysize+7)/8; + kbs = (keysize_b+7)/8; memcpy(tb+HALFSIZEB+2, key, kbs); /* copy key to temporary block */ tb[HALFSIZEB+0] = 0; /* set round counter high value to zero */ for(;r!=(enc?(rounds):-1);enc?r++:r--){ /* enc: 0..(rounds-1) ; !enc: (rounds-1)..0 */ memcpy(tb, R, HALFSIZEB); /* copy right half into tb */ tb[HALFSIZEB+1] = r; - sha256(&hash, tb, HALFSIZE+16+keysize); + sha256(&hash, tb, HALFSIZE+16+keysize_b); if(!(r==(enc?(rounds-1):0))){ /* swap */ - memxor(hash, L, HALFSIZE); - memcpy(L, R, HALFSIZE); - memcpy(R, hash, HALFSIZE); + memxor(hash, L, HALFSIZEB); + memcpy(L, R, HALFSIZEB); + memcpy(R, hash, HALFSIZEB); } else { /* no swap */ memxor(L, hash, HALFSIZE); diff --git a/shabea.h b/shabea.h index b2d4227..0adaade 100644 --- a/shabea.h +++ b/shabea.h @@ -31,5 +31,5 @@ #ifndef SHABEA_H_ #define SHABEA_H_ -void shabea256(void * block, void * key, uint16_t keysize, uint8_t enc, uint8_t rounds); +void shabea256(void * block, void * key, uint16_t keysize_b, uint8_t enc, uint8_t rounds); #endif /*SHABEA_H_*/