3 This file is part of the Crypto-avr-lib/microcrypt-lib.
4 Copyright (C) 2008 Daniel Otte (daniel.otte@rub.de)
6 This program is free software: you can redistribute it and/or modify
7 it under the terms of the GNU General Public License as published by
8 the Free Software Foundation, either version 3 of the License, or
9 (at your option) any later version.
11 This program is distributed in the hope that it will be useful,
12 but WITHOUT ANY WARRANTY; without even the implied warranty of
13 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
14 GNU General Public License for more details.
16 You should have received a copy of the GNU General Public License
17 along with this program. If not, see <http://www.gnu.org/licenses/>.
22 * email: daniel.otte@rub.de
25 * common function for nessie-tests
31 #include <avr/pgmspace.h>
32 #include <stdlib.h> /* utoa() */
35 void nessie_print_block(uint8_t* block, uint16_t blocksize_bit){
36 char tab [] = {'0', '1', '2', '3',
41 for(i=0; i<(blocksize_bit+7)/8; ++i){
42 uart_putc(tab[(block[i])>>4]);
43 uart_putc(tab[(block[i])&0xf]);
48 #define BYTESPERLINE 16
50 void nessie_print_item(char* name, uint8_t* buffer, uint16_t size_B){
53 name_len=strlen(name);
54 if(name_len>SPACES-1){
55 uart_putstr_P(PSTR("\r\n!!! formatting error !!!\r\n"));
58 uart_putstr_P(PSTR("\r\n"));
59 for(i=0; i<SPACES-name_len-1; ++i){
64 /* now the data printing begins */
65 if(size_B<=BYTESPERLINE){
66 /* one line seems sufficient */
67 nessie_print_block(buffer, size_B*8);
69 /* we need more lines */
70 nessie_print_block(buffer, BYTESPERLINE*8); /* first line */
71 int16_t toprint = size_B - BYTESPERLINE;
72 buffer += BYTESPERLINE;
74 uart_putstr_P(PSTR("\r\n"));
75 for(i=0; i<SPACES; ++i){
78 nessie_print_block(buffer, ((toprint>BYTESPERLINE)?BYTESPERLINE:toprint)*8);
79 buffer += BYTESPERLINE;
80 toprint -= BYTESPERLINE;
86 void nessie_print_set_vector(uint8_t set, uint16_t vector){
87 uart_putstr_P(PSTR("\r\n\r\nSet "));
88 uart_putc('0'+set%10);
89 uart_putstr_P(PSTR(", vector#"));
90 uart_putc((vector<1000)?' ':'0'+vector/1000);
91 uart_putc((vector<100)?' ':'0'+(vector/100)%10);
92 uart_putc((vector<10 )?' ':'0'+(vector/10)%10);
93 uart_putc('0'+vector%10);
101 void nessie_print_setheader(uint8_t set){
102 uart_putstr_P(PSTR("\r\n\r\nTest vectors -- set "));
103 uart_putc('0'+set%10);
104 uart_putstr_P(PSTR("\r\n====================="));
108 ********************************************************************************
109 *Project NESSIE - New European Schemes for Signature, Integrity, and Encryption*
110 ********************************************************************************
112 Primitive Name: Serpent
113 =======================
118 void nessie_print_header(char* name,
120 uint16_t blocksize_b,
125 uart_putstr_P(PSTR("\r\n\r\n"
126 "********************************************************************************\r\n"
127 "* micro-crypt - crypto primitives for microcontrolles by Daniel Otte *\r\n"
128 "********************************************************************************\r\n"
130 uart_putstr_P(PSTR("Primitive Name: "));
132 uart_putstr_P(PSTR("\r\n"));
134 for(i=0; i<16+strlen(name); ++i){
137 char str[6]; /* must catch numbers up to 65535 + terminatin \0 */
139 uart_putstr_P(PSTR("\r\nKey size: "));
140 utoa(keysize_b, str, 10);
142 uart_putstr_P(PSTR(" bits"));
145 uart_putstr_P(PSTR("\r\nBlock size: "));
146 utoa(blocksize_b, str, 10);
148 uart_putstr_P(PSTR(" bits"));
151 uart_putstr_P(PSTR("\r\nHash size: "));
152 utoa(hashsize_b, str, 10);
154 uart_putstr_P(PSTR(" bits"));
157 uart_putstr_P(PSTR("\r\nMac size: "));
158 utoa(macsize_b, str, 10);
160 uart_putstr_P(PSTR(" bits"));
163 if(ivsize_b==(uint16_t)-1){
164 uart_putstr_P(PSTR("\r\nNo initial value (IV) mode"));
167 uart_putstr_P(PSTR("\r\nIV size: "));
168 utoa(ivsize_b, str, 10);
170 uart_putstr_P(PSTR(" bits"));
173 uart_putstr_P(PSTR("\r\n"));
176 void nessie_print_footer(void){
177 uart_putstr_P(PSTR("\r\n\r\n\r\n\r\nEnd of test vectors\r\n\r\n"));