From f746b1cd8b111c52014e72d6c86d0d159721b5ce Mon Sep 17 00:00:00 2001 From: bg Date: Thu, 8 May 2008 18:39:12 +0000 Subject: [PATCH] +SHACAL-[1,2] --- main-cast5-test.c | 2 - main-des-test.c | 2 - main-entropium-test.c | 2 - main-grain-test.c | 2 - main-noekeon-test.c | 2 - main-rc5-test.c | 2 - main-rc6-test.c | 2 - main-serpent-test.c | 2 - main-shacal1_enc-test.c | 92 +++++++++++++++++++++++++++++++++++++++++ main-shacal2_enc-test.c | 92 +++++++++++++++++++++++++++++++++++++++++ main-tdes-test.c | 2 - main-trivium-test.c | 2 - nessie_bc_test.c | 10 +++-- sha1.c | 2 +- shacal1_enc.c | 36 ++++++++++++++++ shacal1_enc.h | 13 ++++++ shacal1enc.mk | 14 +++++++ shacal2_enc.c | 39 +++++++++++++++++ shacal2_enc.h | 15 +++++++ shacal2enc.mk | 14 +++++++ 20 files changed, 323 insertions(+), 24 deletions(-) create mode 100644 main-shacal1_enc-test.c create mode 100644 main-shacal2_enc-test.c create mode 100644 shacal1_enc.c create mode 100644 shacal1_enc.h create mode 100644 shacal1enc.mk create mode 100644 shacal2_enc.c create mode 100644 shacal2_enc.h create mode 100644 shacal2enc.mk diff --git a/main-cast5-test.c b/main-cast5-test.c index 514a635..2a3841b 100644 --- a/main-cast5-test.c +++ b/main-cast5-test.c @@ -202,8 +202,6 @@ void test_performance_cast5(void){ * main * *****************************************************************************/ -typedef void(*void_fpt)(void); - int main (void){ char str[20]; diff --git a/main-des-test.c b/main-des-test.c index 86b76e1..289f25b 100644 --- a/main-des-test.c +++ b/main-des-test.c @@ -87,8 +87,6 @@ void testrun_performance_des(void){ * main * *****************************************************************************/ -typedef void(*void_fpt)(void); - int main (void){ char str[20]; DEBUG_INIT(); diff --git a/main-entropium-test.c b/main-entropium-test.c index 82f0c29..1268a73 100644 --- a/main-entropium-test.c +++ b/main-entropium-test.c @@ -80,8 +80,6 @@ void testrun_performance_entropium(void){ * main * *****************************************************************************/ -typedef void(*void_fpt)(void); - int main (void){ char str[20]; DEBUG_INIT(); diff --git a/main-grain-test.c b/main-grain-test.c index d8da791..30149f4 100644 --- a/main-grain-test.c +++ b/main-grain-test.c @@ -143,8 +143,6 @@ void testrun_performance_grain(void){ * main * *****************************************************************************/ -typedef void(*void_fpt)(void); - int main (void){ char str[20]; DEBUG_INIT(); diff --git a/main-noekeon-test.c b/main-noekeon-test.c index b5965ec..ff0d68d 100644 --- a/main-noekeon-test.c +++ b/main-noekeon-test.c @@ -195,8 +195,6 @@ void testrun_performance_noekeon(void){ * main * *****************************************************************************/ -typedef void(*void_fpt)(void); - int main (void){ char str[20]; DEBUG_INIT(); diff --git a/main-rc5-test.c b/main-rc5-test.c index f3258b5..2eec747 100644 --- a/main-rc5-test.c +++ b/main-rc5-test.c @@ -95,8 +95,6 @@ void testrun_performance_rc5(void){ * main * *****************************************************************************/ -typedef void(*void_fpt)(void); - int main (void){ char str[20]; DEBUG_INIT(); diff --git a/main-rc6-test.c b/main-rc6-test.c index cf00207..5be9a3e 100644 --- a/main-rc6-test.c +++ b/main-rc6-test.c @@ -102,8 +102,6 @@ void testrun_performance_rc6(void){ * main * *****************************************************************************/ -typedef void(*void_fpt)(void); - int main (void){ char str[20]; DEBUG_INIT(); diff --git a/main-serpent-test.c b/main-serpent-test.c index 801e2b8..9f385b1 100644 --- a/main-serpent-test.c +++ b/main-serpent-test.c @@ -94,8 +94,6 @@ void testrun_performance_serpent(void){ * main * *****************************************************************************/ -typedef void(*void_fpt)(void); - int main (void){ char str[20]; DEBUG_INIT(); diff --git a/main-shacal1_enc-test.c b/main-shacal1_enc-test.c new file mode 100644 index 0000000..d49169d --- /dev/null +++ b/main-shacal1_enc-test.c @@ -0,0 +1,92 @@ +/* + * 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 new file mode 100644 index 0000000..7c5d1ea --- /dev/null +++ b/main-shacal2_enc-test.c @@ -0,0 +1,92 @@ +/* + * 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-tdes-test.c b/main-tdes-test.c index aefcb2f..7e99dea 100644 --- a/main-tdes-test.c +++ b/main-tdes-test.c @@ -87,8 +87,6 @@ void testrun_performance_tdes(void){ * main * *****************************************************************************/ -typedef void(*void_fpt)(void); - int main (void){ char str[20]; DEBUG_INIT(); diff --git a/main-trivium-test.c b/main-trivium-test.c index 7e3faa2..feeb52e 100644 --- a/main-trivium-test.c +++ b/main-trivium-test.c @@ -89,8 +89,6 @@ void testrun_performance_trivium(void){ * main * *****************************************************************************/ -typedef void(*void_fpt)(void); - int main (void){ char str[20]; DEBUG_INIT(); diff --git a/nessie_bc_test.c b/nessie_bc_test.c index 11deea7..a69e9d1 100644 --- a/nessie_bc_test.c +++ b/nessie_bc_test.c @@ -32,13 +32,15 @@ void nessie_bc_enc(uint8_t* key, uint8_t* pt){ /* 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); - nessie_bc_ctx.cipher_dec(buffer, ctx); - nessie_print_item("decrypted", 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){ @@ -136,6 +138,8 @@ void nessie_bc_run(void){ } nessie_bc_enc(key, buffer); /* half done ;-) */ + if(nessie_bc_ctx.cipher_dec==NULL) + return; /* test set 5 */ set=5; nessie_print_setheader(set); diff --git a/sha1.c b/sha1.c index 711c51c..d45f769 100644 --- a/sha1.c +++ b/sha1.c @@ -3,7 +3,7 @@ * \author Daniel Otte * \date 08.10.2006 * \par License: - * GPL + * GPLv3 * \brief SHA-1 implementation. * */ diff --git a/shacal1_enc.c b/shacal1_enc.c new file mode 100644 index 0000000..82fb722 --- /dev/null +++ b/shacal1_enc.c @@ -0,0 +1,36 @@ +/** + * \file shacal1_enc.c + * \author Daniel Otte + * \date 2008-05-06 + * \par License: + * GPL + * \brief SHACAL1 encryption only implementation. + * + */ + +#include +#include +#include "sha1.h" +#include "shacal1_enc.h" + +void shacal1_enc(void* buffer, void* key, uint16_t keysize_b){ + sha1_ctx_t ctx, t_ctx; + uint8_t i; + memcpy(t_ctx.h, buffer, SHA1_HASH_BITS/8); + + uint8_t keybuffer[SHA1_BLOCK_BITS/8]; + memset(keybuffer, 0, SHA1_BLOCK_BITS/8); + if(keysize_b>SHA1_BLOCK_BITS) + keysize_b=SHA1_BLOCK_BITS; + memcpy(keybuffer, key, (keysize_b+7)/8); + + memcpy(t_ctx.h, buffer, SHA1_HASH_BITS/8); + sha1_ctx2hash((sha1_hash_t*)(&(ctx.h[0])), &t_ctx); + memcpy(t_ctx.h, ctx.h, SHA1_HASH_BITS/8); + sha1_nextBlock(&ctx, keybuffer); + for(i=0; i<5; ++i) + ctx.h[i] -= t_ctx.h[i]; + sha1_ctx2hash(buffer, &ctx); +} + + diff --git a/shacal1_enc.h b/shacal1_enc.h new file mode 100644 index 0000000..8c64340 --- /dev/null +++ b/shacal1_enc.h @@ -0,0 +1,13 @@ +#ifndef SHACAL1_ENC_H_ +#define SHACAL1_ENC_H_ + +#include + +#define SHACAL1_BLOCKSIZE 160 +#define SHACAL1_BLOCKSIZE_B ((SHACAL1_BLOCKSIZE+7)/8) +#define SHACAL1_KEYSIZE 512 +#define SHACAL1_KEYSIZE_B ((SHACAL1_KEYSIZE+7)/8) + +void shacal1_enc(void* buffer, void* key, uint16_t keysize_b); + +#endif /*SHACAL1_ENC_H_*/ diff --git a/shacal1enc.mk b/shacal1enc.mk new file mode 100644 index 0000000..1e19794 --- /dev/null +++ b/shacal1enc.mk @@ -0,0 +1,14 @@ +# Makefile for present +ALGO_NAME := SHACAL1ENC + +# comment out the following line for removement of present from the build process +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 +$(ALGO_NAME)_NESSIE_TEST := "nessie" +$(ALGO_NAME)_PEROFRMANCE_TEST := "performance" + diff --git a/shacal2_enc.c b/shacal2_enc.c new file mode 100644 index 0000000..50743a9 --- /dev/null +++ b/shacal2_enc.c @@ -0,0 +1,39 @@ +/** + * \file shacal2_enc.c + * \author Daniel Otte + * \date 2008-05-07 + * \par License: + * GPL + * \brief SHACAL2 encryption only implementation. + * + */ + +#include +#include +#include "sha256.h" +#include "shacal2_enc.h" + + +void shacal2_enc(void* buffer, void* key, uint16_t keysize_b){ + uint8_t i; + sha256_ctx_t ctx, t_ctx; + memcpy(ctx.h, buffer, SHACAL2_BLOCKSIZE_B); + + uint8_t keybuffer[SHACAL2_KEYSIZE_B]; + memset(keybuffer, 0, SHACAL2_KEYSIZE_B); + if(keysize_b>SHACAL2_KEYSIZE) + keysize_b=SHACAL2_KEYSIZE; + memcpy(keybuffer, key, (keysize_b+7)/8); + + memcpy(t_ctx.h, buffer, SHACAL2_BLOCKSIZE_B); + sha256_ctx2hash((sha256_hash_t*)(&(ctx.h[0])), &t_ctx); + memcpy(t_ctx.h, ctx.h, SHACAL2_BLOCKSIZE_B); + sha256_nextBlock(&ctx, keybuffer); + for(i=0; i +#include "sha256.h" + +#define SHACAL2_BLOCKSIZE SHA256_HASH_BITS +#define SHACAL2_BLOCKSIZE_B ((SHACAL2_BLOCKSIZE+7)/8) +#define SHACAL2_KEYSIZE SHA256_BLOCK_BITS +#define SHACAL2_KEYSIZE_B ((SHACAL2_KEYSIZE+7)/8) + +void shacal2_enc(void* buffer, void* key, uint16_t keysize_b); + + +#endif /*SHACAL2_ENC_H_*/ diff --git a/shacal2enc.mk b/shacal2enc.mk new file mode 100644 index 0000000..44ba529 --- /dev/null +++ b/shacal2enc.mk @@ -0,0 +1,14 @@ +# Makefile for present +ALGO_NAME := SHACAL2ENC + +# comment out the following line for removement of present from the build process +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 +$(ALGO_NAME)_NESSIE_TEST := "nessie" +$(ALGO_NAME)_PEROFRMANCE_TEST := "performance" + -- 2.39.5