X-Git-Url: https://git.cryptolib.org/?a=blobdiff_plain;ds=sidebyside;f=nessie_mac_test.c;h=12863dfdf0ce95cb90f5365cdf44f43fcb53d75e;hb=dd02da3bd4b9c9a84f68150b5cba987b73fd29af;hp=c5a851fbd00e759502ff42df049f2474eb42d9fe;hpb=cc0d247149bad70179dff52f544381545054da44;p=avr-crypto-lib.git
diff --git a/nessie_mac_test.c b/nessie_mac_test.c
index c5a851f..12863df 100644
--- a/nessie_mac_test.c
+++ b/nessie_mac_test.c
@@ -1,3 +1,21 @@
+/* nessie_mac_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,6 +28,7 @@
#include
#include
#include "nessie_mac_test.h"
+#include "nessie_common.h"
#include "uart.h"
nessie_mac_ctx_t nessie_mac_ctx;
@@ -17,117 +36,8 @@ nessie_mac_ctx_t nessie_mac_ctx;
#define KEYSIZE_B ((nessie_mac_ctx.keysize_b+7)/8)
#define MACSIZE_B ((nessie_mac_ctx.macsize_b+7)/8)
-#define PRINTKEY printitem("key", key, KEYSIZE_B)
-#define PRINTMAC printitem("MAC", mac, MACSIZE_B)
-
-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_mac_ctx.name);
- uart_putstr_P(PSTR("\r\n"));
- for(i=0; i<16+strlen(nessie_mac_ctx.name); ++i){
- uart_putc('=');
- }
- uart_putstr_P(PSTR("\r\nHash size: "));
- if(nessie_mac_ctx.macsize_b >100){
- uart_putc('0'+nessie_mac_ctx.macsize_b/100);
- }
- if(nessie_mac_ctx.macsize_b>10){
- uart_putc('0'+(nessie_mac_ctx.macsize_b/10)%10);
- }
- uart_putc('0'+nessie_mac_ctx.macsize_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"));
-}
+#define PRINTKEY nessie_print_item("key", key, KEYSIZE_B)
+#define PRINTMAC nessie_print_item("MAC", mac, MACSIZE_B)
static
void ascii_mac(char* data, char* desc, uint8_t* key){
@@ -273,7 +183,7 @@ void tv4_mac(uint8_t* key){
nessie_mac_ctx.mac_last(mac, nessie_mac_ctx.macsize_b, key, nessie_mac_ctx.keysize_b, ctx);
nessie_mac_ctx.mac_conv(mac, ctx);
}
- printitem("iterated 100000 times", mac, MACSIZE_B);
+ nessie_print_item("iterated 100000 times", mac, MACSIZE_B);
}
@@ -285,7 +195,8 @@ void nessie_mac_run(void){
0x01, 0x23, 0x45, 0x67, 0x89, 0xab, 0xcd, 0xef };
uint8_t key[KEYSIZE_B];
- print_header();
+ nessie_print_header(nessie_mac_ctx.name, nessie_mac_ctx.keysize_b, 0, 0,
+ nessie_mac_ctx.macsize_b, 0);
/* test set 1 */
char* challange[10][2]= {
{"", "\"\" (empty string)"},
@@ -305,55 +216,55 @@ void nessie_mac_run(void){
{"Now is the time for it", "\"Now is the time for it\""}
};
set=1;
- print_setheader(set);
+ nessie_print_setheader(set);
for(i=0; i>3]=0x80>>(i&0x7);
ascii_mac("ABC", "\"ABC\"", key);
}
- print_footer();
+ nessie_print_footer();
}