3 This file is part of the AVR-Crypto-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() */
33 #include "nessie_common.h"
37 void nessie_send_alive(void){
38 NESSIE_PUTC(NESSIE_ALIVE_CHAR);
41 void nessie_send_alive_a(uint16_t i){
43 NESSIE_PUTC(NESSIE_ALIVE_CHAR);
47 void nessie_print_block(uint8_t* block, uint16_t blocksize_bit){
48 char tab [] = {'0', '1', '2', '3',
53 for(i=0; i<(blocksize_bit+7)/8; ++i){
54 NESSIE_PUTC(tab[(block[i])>>4]);
55 NESSIE_PUTC(tab[(block[i])&0xf]);
60 #define BYTESPERLINE 16
62 void nessie_print_item(char* name, uint8_t* buffer, uint16_t size_B){
65 name_len=strlen(name);
66 if(name_len>SPACES-1){
67 NESSIE_PUTSTR_P(PSTR("\r\n!!! formatting error !!!\r\n"));
70 NESSIE_PUTSTR_P(PSTR("\r\n"));
71 for(i=0; i<SPACES-name_len-1; ++i){
76 /* now the data printing begins */
77 if(size_B<=BYTESPERLINE){
78 /* one line seems sufficient */
79 nessie_print_block(buffer, size_B*8);
81 /* we need more lines */
82 nessie_print_block(buffer, BYTESPERLINE*8); /* first line */
83 int16_t toprint = size_B - BYTESPERLINE;
84 buffer += BYTESPERLINE;
86 NESSIE_PUTSTR_P(PSTR("\r\n"));
87 for(i=0; i<SPACES; ++i){
90 nessie_print_block(buffer, ((toprint>BYTESPERLINE)?BYTESPERLINE:toprint)*8);
91 buffer += BYTESPERLINE;
92 toprint -= BYTESPERLINE;
98 void nessie_print_set_vector(uint8_t set, uint16_t vector){
99 NESSIE_PUTSTR_P(PSTR("\r\n\r\nSet "));
100 NESSIE_PUTC('0'+set%10);
101 NESSIE_PUTSTR_P(PSTR(", vector#"));
102 NESSIE_PUTC((vector<1000)?' ':'0'+vector/1000);
103 NESSIE_PUTC((vector<100)?' ':'0'+(vector/100)%10);
104 NESSIE_PUTC((vector<10 )?' ':'0'+(vector/10)%10);
105 NESSIE_PUTC('0'+vector%10);
110 Test vectors -- set 3
111 =====================
113 void nessie_print_setheader(uint8_t set){
114 NESSIE_PUTSTR_P(PSTR("\r\n\r\nTest vectors -- set "));
115 NESSIE_PUTC('0'+set%10);
116 NESSIE_PUTSTR_P(PSTR("\r\n====================="));
120 ********************************************************************************
121 *Project NESSIE - New European Schemes for Signature, Integrity, and Encryption*
122 ********************************************************************************
124 Primitive Name: Serpent
125 =======================
130 void nessie_print_header(char* name,
132 uint16_t blocksize_b,
137 NESSIE_PUTSTR_P(PSTR("\r\n\r\n"
138 "********************************************************************************\r\n"
139 "* micro-crypt - crypto primitives for microcontrolles by Daniel Otte *\r\n"
140 "********************************************************************************\r\n"
142 NESSIE_PUTSTR_P(PSTR("Primitive Name: "));
144 NESSIE_PUTSTR_P(PSTR("\r\n"));
146 for(i=0; i<16+strlen(name); ++i){
149 char str[6]; /* must catch numbers up to 65535 + terminatin \0 */
151 NESSIE_PUTSTR_P(PSTR("\r\nKey size: "));
152 utoa(keysize_b, str, 10);
154 NESSIE_PUTSTR_P(PSTR(" bits"));
157 NESSIE_PUTSTR_P(PSTR("\r\nBlock size: "));
158 utoa(blocksize_b, str, 10);
160 NESSIE_PUTSTR_P(PSTR(" bits"));
163 NESSIE_PUTSTR_P(PSTR("\r\nHash size: "));
164 utoa(hashsize_b, str, 10);
166 NESSIE_PUTSTR_P(PSTR(" bits"));
169 NESSIE_PUTSTR_P(PSTR("\r\nMac size: "));
170 utoa(macsize_b, str, 10);
172 NESSIE_PUTSTR_P(PSTR(" bits"));
175 if(ivsize_b==(uint16_t)-1){
176 NESSIE_PUTSTR_P(PSTR("\r\nNo initial value (IV) mode"));
179 NESSIE_PUTSTR_P(PSTR("\r\nIV size: "));
180 utoa(ivsize_b, str, 10);
182 NESSIE_PUTSTR_P(PSTR(" bits"));
185 NESSIE_PUTSTR_P(PSTR("\r\n"));
188 void nessie_print_footer(void){
189 NESSIE_PUTSTR_P(PSTR("\r\n\r\n\r\n\r\nEnd of test vectors\r\n\r\n"));