]> git.cryptolib.org Git - avr-crypto-lib.git/commitdiff
+SHACAL-[1,2]
authorbg <bg@b1d182e4-1ff8-0310-901f-bddb46175740>
Thu, 8 May 2008 18:39:12 +0000 (18:39 +0000)
committerbg <bg@b1d182e4-1ff8-0310-901f-bddb46175740>
Thu, 8 May 2008 18:39:12 +0000 (18:39 +0000)
20 files changed:
main-cast5-test.c
main-des-test.c
main-entropium-test.c
main-grain-test.c
main-noekeon-test.c
main-rc5-test.c
main-rc6-test.c
main-serpent-test.c
main-shacal1_enc-test.c [new file with mode: 0644]
main-shacal2_enc-test.c [new file with mode: 0644]
main-tdes-test.c
main-trivium-test.c
nessie_bc_test.c
sha1.c
shacal1_enc.c [new file with mode: 0644]
shacal1_enc.h [new file with mode: 0644]
shacal1enc.mk [new file with mode: 0644]
shacal2_enc.c [new file with mode: 0644]
shacal2_enc.h [new file with mode: 0644]
shacal2enc.mk [new file with mode: 0644]

index 514a6359f23eea4687e0147b18926e8f51522a2e..2a3841b8e7e086e23fcc28294959dcba4560e030 100644 (file)
@@ -202,8 +202,6 @@ void test_performance_cast5(void){
  *  main                                                                                                                                        *
  *****************************************************************************/
 
-typedef void(*void_fpt)(void);
-
 int main (void){
        char str[20];
 
index 86b76e1930796d8a9079a8790e806441e10d3223..289f25b6f48aea318eea5fb5550cc380f87d6a86 100644 (file)
@@ -87,8 +87,6 @@ void testrun_performance_des(void){
  *  main                                                                                                                                        *
  *****************************************************************************/
 
-typedef void(*void_fpt)(void);
-
 int main (void){
        char  str[20];
        DEBUG_INIT();
index 82f0c2940f76aa1cd4a0b26b7423665cb418bd57..1268a73cfcd7da632b4b94ef35dfcb36a2011b65 100644 (file)
@@ -80,8 +80,6 @@ void testrun_performance_entropium(void){
  *  main                                                                                                                                        *
  *****************************************************************************/
 
-typedef void(*void_fpt)(void);
-
 int main (void){
        char  str[20];
        DEBUG_INIT();
index d8da7911f826a37d85c25d1470e67733d88145b1..30149f41026ab5a044c18a16c41abd6ab224e53f 100644 (file)
@@ -143,8 +143,6 @@ void testrun_performance_grain(void){
  *  main                                                                                                                                        *
  *****************************************************************************/
 
-typedef void(*void_fpt)(void);
-
 int main (void){
        char  str[20];
        DEBUG_INIT();
index b5965ecc59fd2d782cfa73e968b5c89625e87bc1..ff0d68d051fa8f0a30a8cb218aabee71ef1ed25e 100644 (file)
@@ -195,8 +195,6 @@ void testrun_performance_noekeon(void){
  *  main                                                                                                                                        *
  *****************************************************************************/
 
-typedef void(*void_fpt)(void);
-
 int main (void){
        char  str[20];
        DEBUG_INIT();
index f3258b51f15c0bf174cb02e7e5c0d07cb6d5b34e..2eec747e1d226dc1a950fe4d7010f2ea51e39f21 100644 (file)
@@ -95,8 +95,6 @@ void testrun_performance_rc5(void){
  *  main                                                                                                                                        *
  *****************************************************************************/
 
-typedef void(*void_fpt)(void);
-
 int main (void){
        char  str[20];
        DEBUG_INIT();
index cf00207233e30774849236c9def227a2928bc401..5be9a3ed7679e03ccd1abc121d4c52e281d2f87d 100644 (file)
@@ -102,8 +102,6 @@ void testrun_performance_rc6(void){
  *  main                                                                                                                                        *
  *****************************************************************************/
 
-typedef void(*void_fpt)(void);
-
 int main (void){
        char  str[20];
        DEBUG_INIT();
index 801e2b81b9ba9eac777652b83230987cab074fdb..9f385b1956d3b598515cc144c067ad432d2d8103 100644 (file)
@@ -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 (file)
index 0000000..d49169d
--- /dev/null
@@ -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 <stdlib.h>
+#include <stdint.h>
+#include <string.h>
+
+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 (file)
index 0000000..7c5d1ea
--- /dev/null
@@ -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 <stdlib.h>
+#include <stdint.h>
+#include <string.h>
+
+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");
+       }
+       
+}
index aefcb2f51139517a74fa0ee738265fb126a7bd40..7e99dea48c01e1290d7f97d4f6a4c3d672b69157 100644 (file)
@@ -87,8 +87,6 @@ void testrun_performance_tdes(void){
  *  main                                                                                                                                        *
  *****************************************************************************/
 
-typedef void(*void_fpt)(void);
-
 int main (void){
        char  str[20];
        DEBUG_INIT();
index 7e3faa23f01d90a48c46b90543a53df4b3d2ea9c..feeb52e2d1518f1eb5e77828ff6aad2d36e362b6 100644 (file)
@@ -89,8 +89,6 @@ void testrun_performance_trivium(void){
  *  main                                                                                                                                        *
  *****************************************************************************/
 
-typedef void(*void_fpt)(void);
-
 int main (void){
        char  str[20];
        DEBUG_INIT();
index 11deea73aadf0d18da56a5f811c0fe76190e6c13..a69e9d16c3ea8d168402e36f6a4ccdd668804bc1 100644 (file)
@@ -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 711c51c682b13d85e6de7f829aa80c89cee156c2..d45f7699760cf52bdb2f0913c71206c6a842817d 100644 (file)
--- 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 (file)
index 0000000..82fb722
--- /dev/null
@@ -0,0 +1,36 @@
+/**
+ * \file       shacal1_enc.c
+ * \author     Daniel Otte
+ * \date       2008-05-06
+ * \par License:
+ * GPL
+ * \brief SHACAL1 encryption only implementation.
+ * 
+ */
+
+#include <stdint.h>
+#include <string.h>
+#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 (file)
index 0000000..8c64340
--- /dev/null
@@ -0,0 +1,13 @@
+#ifndef SHACAL1_ENC_H_
+#define SHACAL1_ENC_H_
+
+#include <stdint.h>
+
+#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 (file)
index 0000000..1e19794
--- /dev/null
@@ -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 (file)
index 0000000..50743a9
--- /dev/null
@@ -0,0 +1,39 @@
+/**
+ * \file       shacal2_enc.c
+ * \author     Daniel Otte
+ * \date       2008-05-07
+ * \par License:
+ * GPL
+ * \brief SHACAL2 encryption only implementation.
+ * 
+ */
+
+#include <stdint.h>
+#include <string.h>
+#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<SHACAL2_BLOCKSIZE/32; ++i){
+               ctx.h[i] -= t_ctx.h[i];
+       }
+       sha256_ctx2hash(buffer, &ctx);
+}
+
+
+
diff --git a/shacal2_enc.h b/shacal2_enc.h
new file mode 100644 (file)
index 0000000..4084c0f
--- /dev/null
@@ -0,0 +1,15 @@
+#ifndef SHACAL2_ENC_H_
+#define SHACAL2_ENC_H_
+
+#include <stdint.h>
+#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 (file)
index 0000000..44ba529
--- /dev/null
@@ -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"
+