switching to BCAL based nessie testing

This commit is contained in:
bg 2010-12-21 01:31:02 +00:00
parent 0542221a3e
commit 548902530e
10 changed files with 139 additions and 85 deletions

82
bcal/bcal-nessie.c Normal file
View File

@ -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);
}
}

37
bcal/bcal-nessie.h Normal file
View File

@ -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_ */

View 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_ */

View 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);

View 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

View 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

View 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"

View 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){

View File

@ -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 <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);
}

View File

@ -26,12 +26,13 @@
#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}