From: bg Date: Tue, 21 Dec 2010 01:31:02 +0000 (+0000) Subject: switching to BCAL based nessie testing X-Git-Url: https://git.cryptolib.org/?a=commitdiff_plain;h=548902530e99ffda615113aee335956ea92aab7c;p=avr-crypto-lib.git switching to BCAL based nessie testing --- diff --git a/bcal/bcal-nessie.c b/bcal/bcal-nessie.c new file mode 100644 index 0000000..9bc68b8 --- /dev/null +++ b/bcal/bcal-nessie.c @@ -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 . +*/ + +#include "nessie_bc_test.h" +#include "blockcipher_descriptor.h" +#include "keysize_descriptor.h" +#include +#include +#include +#include + + +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. +*/ +/* + * \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_ */ diff --git a/cscipher/cscipher.h b/cscipher/cscipher.h index 0990b51..717fc05 100644 --- a/cscipher/cscipher.h +++ b/cscipher/cscipher.h @@ -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_ */ diff --git a/cscipher/cscipher_small.c b/cscipher/cscipher_small.c index 9cec6e8..9e8b297 100644 --- a/cscipher/cscipher_small.c +++ b/cscipher/cscipher_small.c @@ -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); diff --git a/mkfiles/001_bcal_std.mk b/mkfiles/001_bcal_std.mk index f47dc77..6e977d1 100644 --- a/mkfiles/001_bcal_std.mk +++ b/mkfiles/001_bcal_std.mk @@ -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 diff --git a/mkfiles/cscipher_tiny.mk b/mkfiles/cscipher_tiny.mk index dfe5b4b..eecaf9a 100644 --- a/mkfiles/cscipher_tiny.mk +++ b/mkfiles/cscipher_tiny.mk @@ -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 diff --git a/mkfiles/des.mk b/mkfiles/des.mk index 9476bde..09edad8 100644 --- a/mkfiles/des.mk +++ b/mkfiles/des.mk @@ -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" diff --git a/test_src/main-cscipher-test.c b/test_src/main-cscipher-test.c index 4501c35..4de929a 100644 --- a/test_src/main-cscipher-test.c +++ b/test_src/main-cscipher-test.c @@ -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){ diff --git a/test_src/main-des-test.c b/test_src/main-des-test.c index f6d237c..63d5f00 100644 --- a/test_src/main-des-test.c +++ b/test_src/main-des-test.c @@ -31,7 +31,10 @@ #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 #include @@ -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); } diff --git a/test_src/main-noekeon-test.c b/test_src/main-noekeon-test.c index f7dbfb4..ad60d7a 100644 --- a/test_src/main-noekeon-test.c +++ b/test_src/main-noekeon-test.c @@ -26,12 +26,13 @@ #include "uart_i.h" #include "debug.h" -#include +#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 #include @@ -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}