]> git.cryptolib.org Git - avr-crypto-lib.git/commitdiff
switching to BCAL based nessie testing
authorbg <bg@b1d182e4-1ff8-0310-901f-bddb46175740>
Tue, 21 Dec 2010 01:31:02 +0000 (01:31 +0000)
committerbg <bg@b1d182e4-1ff8-0310-901f-bddb46175740>
Tue, 21 Dec 2010 01:31:02 +0000 (01:31 +0000)
bcal/bcal-nessie.c [new file with mode: 0644]
bcal/bcal-nessie.h [new file with mode: 0644]
cscipher/cscipher.h
cscipher/cscipher_small.c
mkfiles/001_bcal_std.mk
mkfiles/cscipher_tiny.mk
mkfiles/des.mk
test_src/main-cscipher-test.c
test_src/main-des-test.c
test_src/main-noekeon-test.c

diff --git a/bcal/bcal-nessie.c b/bcal/bcal-nessie.c
new file mode 100644 (file)
index 0000000..9bc68b8
--- /dev/null
@@ -0,0 +1,82 @@
+/* bcal-nessie.c */
+/*
+    This file is part of the AVR-Crypto-Lib.
+    Copyright (C) 2010 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 <http://www.gnu.org/licenses/>.
+*/
+
+#include "nessie_bc_test.h"
+#include "blockcipher_descriptor.h"
+#include "keysize_descriptor.h"
+#include <stdint.h>
+#include <stdlib.h>
+#include <string.h>
+#include <avr/pgmspace.h>
+
+
+void(*bcal_nessie_dummy_init_fpt)(const void* key, void* ctx)=NULL;
+
+void bcal_nessie_dummy_init(const void* key, uint16_t keysize, void* ctx){
+       if(bcal_nessie_dummy_init_fpt){
+               bcal_nessie_dummy_init_fpt(key, ctx);
+       }else{
+               memcpy(ctx, key, (keysize+7)/8);
+       }
+}
+
+void bcal_nessie(const bcdesc_t* bcd){
+       if(pgm_read_byte(&(bcd->type))!=BCDESC_TYPE_BLOCKCIPHER)
+               return;
+       char name[1+strlen_P((void*)pgm_read_word(&(bcd->name)))];
+       strcpy_P(name, (void*)pgm_read_word(&(bcd->name)));
+       nessie_bc_init();
+
+       nessie_bc_ctx.blocksize_B = (pgm_read_word(&(bcd->blocksize_b))+7)/8;
+       nessie_bc_ctx.name        = name;
+       nessie_bc_ctx.ctx_size_B  = pgm_read_word(&(bcd->ctxsize_B));
+       nessie_bc_ctx.cipher_enc  = (nessie_bc_enc_fpt)pgm_read_word(&(bcd->enc));
+       nessie_bc_ctx.cipher_dec  = (nessie_bc_dec_fpt)pgm_read_word(&(bcd->dec));
+       nessie_bc_ctx.cipher_free = (nessie_bc_free_fpt)pgm_read_word(&(bcd->free));
+       if((pgm_read_byte(&(bcd->flags))&BC_INIT_TYPE)==BC_INIT_TYPE_2){
+               nessie_bc_ctx.cipher_genctx  = (nessie_bc_gen_fpt)pgm_read_word(&(bcd->init));
+       }else{
+               bcal_nessie_dummy_init_fpt = (void(*)(const void*,void*))pgm_read_word(&(bcd->init));
+               nessie_bc_ctx.cipher_genctx  = (nessie_bc_gen_fpt)bcal_nessie_dummy_init;
+       }
+
+       uint16_t *keysize_list=NULL;
+       uint16_t items,i;
+       items = get_keysizes(pgm_read_word(&(bcd->valid_keysize_desc)), &keysize_list);
+       if(items){
+               for(i=0; i<items; ++i){
+                       nessie_bc_ctx.keysize_b   = keysize_list[i];
+                       nessie_bc_run();
+               }
+               free(keysize_list);
+       }
+
+}
+
+void bcal_nessie_multiple(const bcdesc_t** bcd_list){
+       const bcdesc_t* bcd;
+       for(;;){
+               bcd = (void*)pgm_read_word(bcd_list);
+               if(!bcd)
+                       return;
+               bcal_nessie(bcd);
+               bcd_list = (void*)((uint8_t*)bcd_list + 2);
+       }
+}
+
diff --git a/bcal/bcal-nessie.h b/bcal/bcal-nessie.h
new file mode 100644 (file)
index 0000000..5e4285f
--- /dev/null
@@ -0,0 +1,37 @@
+/* bcal-nessie.h */
+/*
+    This file is part of the AVR-Crypto-Lib.
+    Copyright (C) 2010 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 <http://www.gnu.org/licenses/>.
+*/
+/*
+ * \file    bcal-nessie.h
+ * \author  Daniel Otte
+ * \email   daniel.otte@rub.de
+ * \date    2010-12-19
+ * \license GPLv3 or later
+ *
+ */
+
+#ifndef BCALNESSIE_H_
+#define BCALNESSIE_H_
+
+#include "blockcipher_descriptor.h"
+
+void bcal_nessie(const bcdesc_t* bcd);
+void bcal_nessie_multiple(const bcdesc_t** bcd_list);
+
+
+#endif /* BCALNESSIE_H_ */
index 0990b51fb11c615c69b4be5b38046209d718e068..717fc0593c67a2f9a281e6775324ef503aa13f08 100644 (file)
@@ -26,7 +26,7 @@ typedef struct {
 
 void cscipher_enc(void* buffer, const cscipher_ctx_t* ctx);
 void cscipher_dec(void* buffer, const cscipher_ctx_t* ctx);
-void cscipher_init(void* key, cscipher_ctx_t* ctx);
+void cscipher_init(const void* key, cscipher_ctx_t* ctx);
 
 
 #endif /* CSCIPHER_H_ */
index 9cec6e8a4b3ab132823a851dc6b806a791d5cf1b..9e8b297f7598154b7fc778806699b34e20a4dceb 100644 (file)
@@ -146,7 +146,7 @@ void cscipher_dec(void* buffer, const cscipher_ctx_t* ctx){
        }while(i--);
 }
 
-void cscipher_init(void* key, cscipher_ctx_t* ctx){
+void cscipher_init(const void* key, cscipher_ctx_t* ctx){
        uint8_t tmp_key[16], tmp[8];
        uint8_t i,j,k,t;
        memcpy(tmp_key, key, 16);
index f47dc770c5b2fe0f319084b9fa91981a738f188c..6e977d1f79c9c3a57c337971d65d80ccbdfdb6ab 100644 (file)
@@ -1,3 +1,3 @@
 BCAL_STD = nessie_common.o nessie_bc_test.o performance_test.o \
-           bcal-basic.o bcal-performance.o keysize_descriptor.o \
+           bcal-basic.o bcal-performance.o bcal-nessie.o keysize_descriptor.o \
            stack_measuring.o 
index dfe5b4b39721a5c20b5e9840bbfba3097204f668..eecaf9a8a4361f307259b788b5b840703067b857 100644 (file)
@@ -6,7 +6,7 @@ BLOCK_CIPHERS += $(ALGO_NAME)
 
 $(ALGO_NAME)_DIR      := cscipher/
 $(ALGO_NAME)_INCDIR   := bcal/ memxor/
-$(ALGO_NAME)_OBJ      := cscipher_tiny_asm.o cscipher_tiny_stub.o  memxor.o memxor_p.o
+$(ALGO_NAME)_OBJ      := cscipher_tiny_asm.o  memxor.o memxor_p.o
 $(ALGO_NAME)_TEST_BIN := main-cscipher-test.o bcal_cscipher.o $(CLI_STD) $(BCAL_STD) 
 $(ALGO_NAME)_NESSIE_TEST      := test nessie
 $(ALGO_NAME)_PERFORMANCE_TEST := performance
index 9476bded46d8b4d66063f95f25ffc97cbb9be967..09edad8a25fa2627c092b8ce4102a66b5e88c02a 100644 (file)
@@ -7,7 +7,7 @@ BLOCK_CIPHERS += $(ALGO_NAME)
 $(ALGO_NAME)_DIR      := des/
 $(ALGO_NAME)_INCDIR   := bcal/
 $(ALGO_NAME)_OBJ      := des.o
-$(ALGO_NAME)_TEST_BIN := main-des-test.o bcal_des.o $(CLI_STD) $(BCAL_STD)
+$(ALGO_NAME)_TEST_BIN := main-des-test.o bcal_des.o bcal_tdes.o bcal_tdes2.o $(CLI_STD) $(BCAL_STD)
 $(ALGO_NAME)_NESSIE_TEST      := "nessie"
 $(ALGO_NAME)_PERFORMANCE_TEST := "performance"
 
index 4501c35cc749acbea9d42d08bcb7026c5fc011b5..4de929a03ceacba8626ae91e563b23f91dc38536 100644 (file)
@@ -27,7 +27,7 @@
 #include "debug.h"
 
 #include "cscipher.h"
-#include "nessie_bc_test.h"
+#include "bcal-nessie.h"
 #include "cli.h"
 #include "performance_test.h"
 #include "bcal-performance.h"
@@ -53,17 +53,7 @@ void cscipher_init_dummy(const uint8_t* key, uint16_t keysize_b, void* ctx){
 }
 
 void testrun_nessie_cscipher(void){
-       nessie_bc_init();
-       nessie_bc_ctx.blocksize_B =   8;
-       nessie_bc_ctx.keysize_b   = 128;
-       nessie_bc_ctx.name        = algo_name;
-       nessie_bc_ctx.ctx_size_B  = sizeof(cscipher_ctx_t);
-       nessie_bc_ctx.cipher_enc  = (nessie_bc_enc_fpt)cscipher_enc;
-       nessie_bc_ctx.cipher_dec  = (nessie_bc_dec_fpt)cscipher_dec;
-       nessie_bc_ctx.cipher_free = (nessie_bc_free_fpt)NULL;
-       nessie_bc_ctx.cipher_genctx  = (nessie_bc_gen_fpt)cscipher_init_dummy;
-       
-       nessie_bc_run();
+       bcal_nessie(&cscipher_desc);
 }
 
 void testrun_cscipher(void){
index f6d237c7e58e270894049714c21b9a07311a731b..63d5f00c892fc8ec34d1862d710b6f70c63a28cc 100644 (file)
 #include "cli.h"
 #include "performance_test.h"
 #include "bcal-performance.h"
+#include "bcal-nessie.h"
 #include "bcal_des.h"
+#include "bcal_tdes.h"
+#include "bcal_tdes2.h"
 
 #include <stdint.h>
 #include <string.h>
@@ -41,37 +44,18 @@ char* algo_name = "DES";
 
 const bcdesc_t* algolist[] PROGMEM = {
        (bcdesc_t*)&des_desc,
+       (bcdesc_t*)&tdes2_desc,
+       (bcdesc_t*)&tdes_desc,
        NULL
 };
 /*****************************************************************************
  *  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        = algo_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();
+       bcal_nessie_multiple(algolist);
 }
 
-
 void testrun_performance_des(void){
        bcal_performance_multiple(algolist);
 }
index f7dbfb411138307d48e7a4cef03f0d2b8230bd32..ad60d7acc24116a5103aa00cb8a02f5b605e3d43 100644 (file)
 #include "uart_i.h"
 #include "debug.h"
 
-#include <noekeon/noekeon.h>
+#include "noekeon.h"
 #include "nessie_bc_test.h"
-#include "cli.h"
+#include "bcal-nessie.h"
 #include "performance_test.h"
 #include "bcal-performance.h"
 #include "bcal_noekeon.h"
+#include "cli.h"
 
 #include <stdint.h>
 #include <string.h>
@@ -47,49 +48,9 @@ const bcdesc_t* algolist[] PROGMEM = {
 /*****************************************************************************
  *  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(algo_name)+10];
-       strcpy(str, algo_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(algo_name)+10];
-       strcpy(str, algo_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();
+       bcal_nessie_multiple(&algolist);
 }
 
 
@@ -97,7 +58,7 @@ void testrun_stdtest_rundirect(void* data, void* key){
        cli_putstr_P(PSTR("\r\n                     "));
        cli_putstr_P(PSTR("k = "));
        cli_hexdump(key,16);
-       
+
        cli_putstr_P(PSTR("\r\n                     "));
        cli_putstr_P(PSTR("a = "));
        cli_hexdump(data,16);
@@ -196,8 +157,8 @@ const char echo_str[]        PROGMEM = "echo";
 cmdlist_entry_t cmdlist[] PROGMEM = {
        { nessie_str,      NULL, testrun_nessie_noekeon},
        { test_str,        NULL, testrun_stdtest_noekeon},
-       { direct_str,      NULL, testrun_nessie_noekeon_direct},
-       { indirect_str,    NULL, testrun_nessie_noekeon_indirect},
+//     { direct_str,      NULL, testrun_nessie_noekeon_direct},
+//     { indirect_str,    NULL, testrun_nessie_noekeon_indirect},
        { performance_str, NULL, testrun_performance_noekeon},
        { echo_str,    (void*)1, (void_fpt)echo_ctrl},
        { NULL,            NULL, NULL}