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"
34 #include "hexdigit_tab.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){
49 for(i=0; i<(blocksize_bit+7)/8; ++i){
50 NESSIE_PUTC(pgm_read_byte(hexdigit_tab_uc_P+((block[i])>>4)));
51 NESSIE_PUTC(pgm_read_byte(hexdigit_tab_uc_P+((block[i])&0xf)));
56 #define BYTESPERLINE 16
58 void nessie_print_item(char* name, uint8_t* buffer, uint16_t size_B){
61 name_len=strlen(name);
62 if(name_len>SPACES-1){
63 NESSIE_PUTSTR_P(PSTR("\r\n!!! formatting error !!!\r\n"));
66 NESSIE_PUTSTR_P(PSTR("\r\n"));
67 for(i=0; i<SPACES-name_len-1; ++i){
72 /* now the data printing begins */
73 if(size_B<=BYTESPERLINE){
74 /* one line seems sufficient */
75 nessie_print_block(buffer, size_B*8);
77 /* we need more lines */
78 nessie_print_block(buffer, BYTESPERLINE*8); /* first line */
79 int16_t toprint = size_B - BYTESPERLINE;
80 buffer += BYTESPERLINE;
82 NESSIE_PUTSTR_P(PSTR("\r\n"));
83 for(i=0; i<SPACES; ++i){
86 nessie_print_block(buffer, ((toprint>BYTESPERLINE)?BYTESPERLINE:toprint)*8);
87 buffer += BYTESPERLINE;
88 toprint -= BYTESPERLINE;
94 void nessie_print_set_vector(uint8_t set, uint16_t vector){
95 NESSIE_PUTSTR_P(PSTR("\r\n\r\nSet "));
96 NESSIE_PUTC('0'+set%10);
97 NESSIE_PUTSTR_P(PSTR(", vector#"));
98 NESSIE_PUTC((vector<1000)?' ':'0'+vector/1000);
99 NESSIE_PUTC((vector<100)?' ':'0'+(vector/100)%10);
100 NESSIE_PUTC((vector<10 )?' ':'0'+(vector/10)%10);
101 NESSIE_PUTC('0'+vector%10);
106 Test vectors -- set 3
107 =====================
109 void nessie_print_setheader(uint8_t set){
110 NESSIE_PUTSTR_P(PSTR("\r\n\r\nTest vectors -- set "));
111 NESSIE_PUTC('0'+set%10);
112 NESSIE_PUTSTR_P(PSTR("\r\n====================="));
116 ********************************************************************************
117 *Project NESSIE - New European Schemes for Signature, Integrity, and Encryption*
118 ********************************************************************************
120 Primitive Name: Serpent
121 =======================
126 void nessie_print_header(char* name,
128 uint16_t blocksize_b,
133 NESSIE_PUTSTR_P(PSTR("\r\n\r\n"
134 "********************************************************************************\r\n"
135 "* AVR-Crypto-Lib - crypto primitives for AVR microcontrolles by Daniel Otte *\r\n"
136 "********************************************************************************\r\n"
138 NESSIE_PUTSTR_P(PSTR("Primitive Name: "));
140 NESSIE_PUTSTR_P(PSTR("\r\n"));
142 for(i=0; i<16+strlen(name); ++i){
145 char str[6]; /* must catch numbers up to 65535 + terminatin \0 */
147 NESSIE_PUTSTR_P(PSTR("\r\nKey size: "));
148 utoa(keysize_b, str, 10);
150 NESSIE_PUTSTR_P(PSTR(" bits"));
153 NESSIE_PUTSTR_P(PSTR("\r\nBlock size: "));
154 utoa(blocksize_b, str, 10);
156 NESSIE_PUTSTR_P(PSTR(" bits"));
159 NESSIE_PUTSTR_P(PSTR("\r\nHash size: "));
160 utoa(hashsize_b, str, 10);
162 NESSIE_PUTSTR_P(PSTR(" bits"));
165 NESSIE_PUTSTR_P(PSTR("\r\nMac size: "));
166 utoa(macsize_b, str, 10);
168 NESSIE_PUTSTR_P(PSTR(" bits"));
171 if(ivsize_b==(uint16_t)-1){
172 NESSIE_PUTSTR_P(PSTR("\r\nNo initial value (IV) mode"));
175 NESSIE_PUTSTR_P(PSTR("\r\nIV size: "));
176 utoa(ivsize_b, str, 10);
178 NESSIE_PUTSTR_P(PSTR(" bits"));
181 NESSIE_PUTSTR_P(PSTR("\r\n"));
184 void nessie_print_footer(void){
185 NESSIE_PUTSTR_P(PSTR("\r\n\r\n\r\n\r\nEnd of test vectors\r\n\r\n"));