small bug in twister (C) fixed asm version needs fixing

This commit is contained in:
bg 2009-05-14 09:38:02 +00:00
parent dca8c6894a
commit ed07adb6f2
7 changed files with 182 additions and 107 deletions

View File

@ -28,7 +28,7 @@
#include <avr/pgmspace.h>
#include <stdlib.h>
#include "hashfunction_descriptor.h"
#include "twister384.h"
#include "twister-big.h"
static const char twister384_str[] PROGMEM = "Twister-384";

13
mkfiles/twister.mk Normal file
View File

@ -0,0 +1,13 @@
# Makefile for TWISTER
ALGO_NAME := TWISTER
# comment out the following line for removement of TWISTER from the build process
HASHES += $(ALGO_NAME)
$(ALGO_NAME)_OBJ := twister-small-asm.o twister-big-asm.o twister-asm.o \
twister224.o twister256.o twister384.o twister512.o
$(ALGO_NAME)_TEST_BIN := main-twister-test.o hfal_twister224.o hfal_twister256.o \
hfal_twister384.o hfal_twister512.o $(CLI_STD) $(HFAL_STD)
$(ALGO_NAME)_NESSIE_TEST := "nessie"
$(ALGO_NAME)_PERFORMANCE_TEST := "performance"

12
mkfiles/twister_c.mk Normal file
View File

@ -0,0 +1,12 @@
# Makefile for TWISTER
ALGO_NAME := TWISTER_C
# comment out the following line for removement of TWISTER from the build process
HASHES += $(ALGO_NAME)
$(ALGO_NAME)_OBJ := twister.o twister-small.o twister-big.o memxor.o gf256mul.o
$(ALGO_NAME)_TEST_BIN := main-twister-test.o hfal_twister224.o hfal_twister256.o \
hfal_twister384.o hfal_twister512.o $(CLI_STD) $(HFAL_STD)
$(ALGO_NAME)_NESSIE_TEST := "nessie"
$(ALGO_NAME)_PERFORMANCE_TEST := "performance"

View File

@ -96,109 +96,8 @@ void testlshort(void){
blake64_test("", 8);
}
void performance_blake(void){
uint64_t t;
char str[16];
uint8_t data[64];
uint8_t hash[512/8];
blake_small_ctx_t ctx;
blake_large_ctx_t ctx2;
calibrateTimer();
print_overhead();
memset(data, 0, 64);
startTimer(1);
blake28_init(&ctx);
t = stopTimer();
cli_putstr_P(PSTR("\r\n\tctx-gen time (224): "));
ultoa((unsigned long)t, str, 10);
cli_putstr(str);
startTimer(1);
blake32_init(&ctx);
t = stopTimer();
cli_putstr_P(PSTR("\r\n\tctx-gen time (256): "));
ultoa((unsigned long)t, str, 10);
cli_putstr(str);
startTimer(1);
blake48_init(&ctx2);
t = stopTimer();
cli_putstr_P(PSTR("\r\n\tctx-gen time (384): "));
ultoa((unsigned long)t, str, 10);
cli_putstr(str);
startTimer(1);
blake64_init(&ctx2);
t = stopTimer();
cli_putstr_P(PSTR("\r\n\tctx-gen time (512): "));
ultoa((unsigned long)t, str, 10);
cli_putstr(str);
startTimer(1);
blake_small_nextBlock(&ctx, data);
t = stopTimer();
cli_putstr_P(PSTR("\r\n\tone-block (small) time: "));
ultoa((unsigned long)t, str, 10);
cli_putstr(str);
startTimer(1);
blake_large_nextBlock(&ctx2, data);
t = stopTimer();
cli_putstr_P(PSTR("\r\n\tone-block (large) time: "));
ultoa((unsigned long)t, str, 10);
cli_putstr(str);
startTimer(1);
blake_small_lastBlock(&ctx, data, 0);
t = stopTimer();
cli_putstr_P(PSTR("\r\n\tlast block (small) time: "));
ultoa((unsigned long)t, str, 10);
cli_putstr(str);
startTimer(1);
blake_large_lastBlock(&ctx2, data, 0);
t = stopTimer();
cli_putstr_P(PSTR("\r\n\tlast block (large) time: "));
ultoa((unsigned long)t, str, 10);
cli_putstr(str);
startTimer(1);
blake28_ctx2hash(hash, &ctx);
t = stopTimer();
cli_putstr_P(PSTR("\r\n\tctx2hash time (224): "));
ultoa((unsigned long)t, str, 10);
cli_putstr(str);
startTimer(1);
blake32_ctx2hash(hash, &ctx);
t = stopTimer();
cli_putstr_P(PSTR("\r\n\tctx2hash time (256): "));
ultoa((unsigned long)t, str, 10);
cli_putstr(str);
startTimer(1);
blake48_ctx2hash(hash, &ctx2);
t = stopTimer();
cli_putstr_P(PSTR("\r\n\tctx2hash time (384): "));
ultoa((unsigned long)t, str, 10);
cli_putstr(str);
startTimer(1);
blake64_ctx2hash(hash, &ctx2);
t = stopTimer();
cli_putstr_P(PSTR("\r\n\tctx2hash time (512): "));
ultoa((unsigned long)t, str, 10);
cli_putstr(str);
cli_putstr_P(PSTR("\r\n"));
}
void autoperformance_blake(void){
hfal_performance_multiple(algolist);
}
@ -212,7 +111,6 @@ const char test_str[] PROGMEM = "test";
const char testshort_str[] PROGMEM = "short";
const char testlshort_str[] PROGMEM = "lshort";
const char performance_str[] PROGMEM = "performance";
const char aperformance_str[] PROGMEM = "autoperformance";
const char echo_str[] PROGMEM = "echo";
const char shavs_list_str[] PROGMEM = "shavs_list";
const char shavs_set_str[] PROGMEM = "shavs_set";
@ -224,7 +122,6 @@ cmdlist_entry_t cmdlist[] PROGMEM = {
{ testshort_str, NULL, testshort},
{ testlshort_str, NULL, testlshort},
{ performance_str, NULL, performance_blake},
{ aperformance_str, NULL, autoperformance_blake},
{ shavs_list_str, NULL, shavs_listalgos},
{ shavs_set_str, (void*)1, (void_fpt)shavs_setalgo},
{ shavs_test1_str, NULL, shavs_test1},

View File

@ -0,0 +1,153 @@
/* main-twister-test.c */
/*
This file is part of the AVR-Crypto-Lib.
Copyright (C) 2008, 2009 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/>.
*/
/*
* twister test suit
*
*/
#include "config.h"
#include "serial-tools.h"
#include "uart.h"
#include "debug.h"
#include "twister-small.h"
#include "nessie_hash_test.h"
#include "performance_test.h"
#include "hfal_twister224.h"
#include "hfal_twister256.h"
#include "hfal_twister384.h"
#include "hfal_twister512.h"
#include "hfal-nessie.h"
#include "hfal-performance.h"
#include "hfal-test.h"
#include "shavs.h"
#include <stdint.h>
#include <string.h>
#include <stdlib.h>
#include "cli.h"
char* algo_name = "TWISTER";
const hfdesc_t* algolist[] PROGMEM = {
(hfdesc_t*)&twister224_desc,
(hfdesc_t*)&twister256_desc,
(hfdesc_t*)&twister384_desc,
(hfdesc_t*)&twister512_desc,
NULL
};
/*****************************************************************************
* additional validation-functions *
*****************************************************************************/
void testrun_nessie_twister(void){
hfal_nessie_multiple(algolist);
}
/*****************************************************************************
* selftests
*
*****************************************************************************/
void test_twister224( void* msg, uint32_t length_b){
hfal_test(&twister224_desc, msg, length_b);
}
void test_twister256( void* msg, uint32_t length_b){
hfal_test(&twister256_desc, msg, length_b);
}
void test_twister384( void* msg, uint32_t length_b){
hfal_test(&twister384_desc, msg, length_b);
}
void test_twister512( void* msg, uint32_t length_b){
hfal_test(&twister512_desc, msg, length_b);
}
void testrun_twister(void){
const hfdesc_t* desc[4] = { &twister224_desc, &twister256_desc,
&twister384_desc, &twister512_desc };
uint8_t i,j;
char* testv[]={
"",
"a",
"abc",
"message digest",
"abcdefghijklmnopqrstuvwxyz",
"ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789",
"12345678901234567890123456789012345678901234567890123456789012345678901234567890"};
uint8_t stestv[]= {0x00, 0x00, 0xC0, 0xC0, 0x80, 0x48, 0x50};
uint8_t stestl[]= { 0, 1, 2, 3, 4, 5, 6};
for(i=0; i<4; ++i){
for(j=0; j<7; ++j){
hfal_test(desc[i], testv[j], strlen(testv[j])*8);
}
hfal_test(desc[i], stestv, 7*8);
hfal_test(desc[i], stestl, 7*8);
}
}
void testrun_performance_twister(void){
hfal_performance_multiple(algolist);
}
/*****************************************************************************
* main *
*****************************************************************************/
const char nessie_str[] PROGMEM = "nessie";
const char test_str[] PROGMEM = "test";
const char performance_str[] PROGMEM = "performance";
const char echo_str[] PROGMEM = "echo";
const char shavs_list_str[] PROGMEM = "shavs_list";
const char shavs_set_str[] PROGMEM = "shavs_set";
const char shavs_test1_str[] PROGMEM = "shavs_test1";
cmdlist_entry_t cmdlist[] PROGMEM = {
{ nessie_str, NULL, testrun_nessie_twister},
{ test_str, NULL, testrun_twister},
{ performance_str, NULL, testrun_performance_twister},
{ echo_str, (void*)1, (void_fpt)echo_ctrl},
{ shavs_list_str, NULL, shavs_listalgos},
{ shavs_set_str, (void*)1, (void_fpt)shavs_setalgo},
{ shavs_test1_str, NULL, shavs_test1},
{ NULL, NULL, NULL}
};
int main (void){
DEBUG_INIT();
cli_rx = uart_getc;
cli_tx = uart_putc;
shavs_algolist=(hfdesc_t**)algolist;
shavs_algo=(hfdesc_t*)&twister256_desc;
for(;;){
cli_putstr_P(PSTR("\r\n\r\nCrypto-VS ("));
cli_putstr(algo_name);
cli_putstr_P(PSTR(")\r\nloaded and running\r\n"));
cmd_interface(cmdlist);
}
}

View File

@ -117,7 +117,7 @@ void twister_inject_chksum(twister_big_ctx_t* ctx, uint8_t col){
void twister_big_lastBlock(twister_big_ctx_t* ctx, const void* msg, uint16_t length_b){
uint8_t tmp[64];
while(length_b>512){
while(length_b>=512){
twister_big_nextBlock(ctx, msg);
msg = ((uint8_t*)msg)+64;
length_b -= 512;

View File

@ -53,7 +53,7 @@ void twister_small_nextBlock(twister_state_t* ctx, const void* msg){
void twister_small_lastBlock(twister_state_t* ctx, const void* msg, uint16_t length_b){
uint8_t tmp[64];
while(length_b>512){
while(length_b>=512){
twister_small_nextBlock(ctx, msg);
msg = ((uint8_t*)msg)+64;
length_b -= 512;