X-Git-Url: https://git.cryptolib.org/?a=blobdiff_plain;ds=sidebyside;f=nessie_hash_test.c;h=a870b8283ca58dc09ce69b76bee89f8ee4d30cd2;hb=4d76909e4282baf1420ee309e270384246b241b8;hp=598abc08ae9af13c93f1de40076e2f9c9633f7fb;hpb=b74ffe54a472b5eab2511b835568044c39486858;p=avr-crypto-lib.git
diff --git a/nessie_hash_test.c b/nessie_hash_test.c
index 598abc0..a870b82 100644
--- a/nessie_hash_test.c
+++ b/nessie_hash_test.c
@@ -1,3 +1,21 @@
+/* nessie_hash_test.c */
+/*
+ This file is part of the Crypto-avr-lib/microcrypt-lib.
+ Copyright (C) 2008 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 .
+*/
/**
*
* author: Daniel Otte
@@ -10,119 +28,11 @@
#include
#include
#include "nessie_hash_test.h"
+#include "nessie_common.h"
#include "uart.h"
nessie_hash_ctx_t nessie_hash_ctx;
-static void printblock(uint8_t* block, uint16_t blocksize_bit){
- char tab [] = {'0', '1', '2', '3',
- '4', '5', '6', '7',
- '8', '9', 'A', 'B',
- 'C', 'D', 'E', 'F'};
- uint16_t i;
- for(i=0; i<(blocksize_bit+7)/8; ++i){
- uart_putc(tab[(block[i])>>4]);
- uart_putc(tab[(block[i])&0xf]);
- }
-}
-
-#define SPACES 31
-#define BYTESPERLINE 16
-
-static void printitem(char* name, uint8_t* buffer, uint16_t size_B){
- uint8_t name_len;
- uint8_t i;
- name_len=strlen(name);
- if(name_len>SPACES-1){
- uart_putstr_P(PSTR("\r\n!!! formatting error !!!\r\n"));
- return;
- }
- uart_putstr_P(PSTR("\r\n"));
- for(i=0; i 0){
- uart_putstr_P(PSTR("\r\n"));
- for(i=0; iBYTESPERLINE)?BYTESPERLINE:toprint)*8);
- buffer += BYTESPERLINE;
- toprint -= BYTESPERLINE;
- }
- }
-}
-
-static void print_set_vector(uint8_t set, uint16_t vector){
- uart_putstr_P(PSTR("\r\n\r\nSet "));
- uart_putc('0'+set%10);
- uart_putstr_P(PSTR(", vector#"));
- uart_putc((vector<100)?' ':'0'+vector/100);
- uart_putc((vector<10 )?' ':'0'+(vector/10)%10);
- uart_putc('0'+vector%10);
- uart_putc(':');
-}
-
-/* example:
-Test vectors -- set 3
-=====================
- */
-static void print_setheader(uint8_t set){
- uart_putstr_P(PSTR("\r\n\r\nTest vectors -- set "));
- uart_putc('0'+set%10);
- uart_putstr_P(PSTR("\r\n====================="));
-}
-
-/* example:
-********************************************************************************
-*Project NESSIE - New European Schemes for Signature, Integrity, and Encryption*
-********************************************************************************
-
-Primitive Name: Serpent
-=======================
-Key size: 256 bits
-Block size: 128 bits
-*/
-
-static void print_header(void){
- uint16_t i;
- uart_putstr_P(PSTR("\r\n\r\n"
- "********************************************************************************\r\n"
- "* micro-cryt - crypto primitives for microcontrolles by Daniel Otte *\r\n"
- "********************************************************************************\r\n"
- "\r\n"));
- uart_putstr_P(PSTR("Primitive Name: "));
- uart_putstr(nessie_hash_ctx.name);
- uart_putstr_P(PSTR("\r\n"));
- for(i=0; i<16+strlen(nessie_hash_ctx.name); ++i){
- uart_putc('=');
- }
- uart_putstr_P(PSTR("\r\nHash size: "));
- if(nessie_hash_ctx.hashsize_b >100){
- uart_putc('0'+nessie_hash_ctx.hashsize_b/100);
- }
- if(nessie_hash_ctx.hashsize_b>10){
- uart_putc('0'+(nessie_hash_ctx.hashsize_b/10)%10);
- }
- uart_putc('0'+nessie_hash_ctx.hashsize_b%10);
- uart_putstr_P(PSTR(" bits\r\n"));
-}
-
-static void print_footer(void){
- uart_putstr_P(PSTR("\r\n\r\n\r\n\r\nEnd of test vectors\r\n\r\n"));
-}
-
static
void ascii_hash(char* data, char* desc){
uint8_t ctx[nessie_hash_ctx.ctx_size_B];
@@ -140,7 +50,7 @@ void ascii_hash(char* data, char* desc){
}
nessie_hash_ctx.hash_last(data, sl*8, ctx);
nessie_hash_ctx.hash_conv(hash, ctx);
- printitem("hash", hash, (nessie_hash_ctx.hashsize_b+7)/8);
+ nessie_print_item("hash", hash, (nessie_hash_ctx.hashsize_b+7)/8);
}
// message=1 million times "a"
@@ -162,7 +72,7 @@ void amillion_hash(void){
}
nessie_hash_ctx.hash_last(block, n*8, ctx);
nessie_hash_ctx.hash_conv(hash, ctx);
- printitem("hash", hash, (nessie_hash_ctx.hashsize_b+7)/8);
+ nessie_print_item("hash", hash, (nessie_hash_ctx.hashsize_b+7)/8);
}
@@ -192,7 +102,7 @@ void zero_hash(uint16_t n){
}
nessie_hash_ctx.hash_last(block, n, ctx);
nessie_hash_ctx.hash_conv(hash, ctx);
- printitem("hash", hash, (nessie_hash_ctx.hashsize_b+7)/8);
+ nessie_print_item("hash", hash, (nessie_hash_ctx.hashsize_b+7)/8);
}
static
@@ -234,7 +144,7 @@ void one_in512_hash(uint16_t pos){
}
nessie_hash_ctx.hash_last(block, n, ctx);
nessie_hash_ctx.hash_conv(hash, ctx);
- printitem("hash", hash, (nessie_hash_ctx.hashsize_b+7)/8);
+ nessie_print_item("hash", hash, (nessie_hash_ctx.hashsize_b+7)/8);
}
static
@@ -256,13 +166,13 @@ void tv4_hash(void){
}
nessie_hash_ctx.hash_last(block, n, ctx);
nessie_hash_ctx.hash_conv(hash, ctx);
- printitem("hash", hash, (nessie_hash_ctx.hashsize_b+7)/8);
+ nessie_print_item("hash", hash, (nessie_hash_ctx.hashsize_b+7)/8);
for(i=1; i<100000L; ++i){ /* this assumes BLOCKSIZE >= HASHSIZE */
nessie_hash_ctx.hash_init(ctx);
nessie_hash_ctx.hash_last(hash, nessie_hash_ctx.hashsize_b, ctx);
nessie_hash_ctx.hash_conv(hash, ctx);
}
- printitem("iterated 100000 times", hash, (nessie_hash_ctx.hashsize_b+7)/8);
+ nessie_print_item("iterated 100000 times", hash, (nessie_hash_ctx.hashsize_b+7)/8);
}
/*
@@ -281,7 +191,7 @@ void nessie_hash_run(void){
uint16_t i;
uint8_t set;
- print_header();
+ nessie_print_header(nessie_hash_ctx.name, 0, 0, nessie_hash_ctx.hashsize_b, 0, 0);
/* test set 1 */
char* challange[8][2]= {
{"", "\"\" (empty string)"},
@@ -299,32 +209,32 @@ void nessie_hash_run(void){
"8 times \"1234567890\""}
};
set=1;
- print_setheader(set);
+ nessie_print_setheader(set);
for(i=0; i<8; ++i){
- print_set_vector(set, i);
+ nessie_print_set_vector(set, i);
ascii_hash(challange[i][0], challange[i][1]);
}
- print_set_vector(set, i);
+ nessie_print_set_vector(set, i);
amillion_hash();
/* test set 2 */
set=2;
- print_setheader(set);
+ nessie_print_setheader(set);
for(i=0; i<1024; ++i){
- print_set_vector(set, i);
+ nessie_print_set_vector(set, i);
zero_hash(i);
}
/* test set 3 */
set=3;
- print_setheader(set);
+ nessie_print_setheader(set);
for(i=0; i<512; ++i){
- print_set_vector(set, i);
+ nessie_print_set_vector(set, i);
one_in512_hash(i);
}
/* test set 4 */
set=4;
- print_setheader(set);
- print_set_vector(set, 0);
+ nessie_print_setheader(set);
+ nessie_print_set_vector(set, 0);
tv4_hash();
- print_footer();
+ nessie_print_footer();
}