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
32 #include <avr/pgmspace.h>
33 #include "nessie_common.h"
34 #include "hexdigit_tab.h"
36 #define nessie_out_file stdout
38 void nessie_set_output_stream(FILE *out_stream){
39 nessie_out_file = out_stream;
44 void nessie_send_alive(void){
45 putc(NESSIE_ALIVE_CHAR, nessie_out_file);
48 void nessie_send_alive_a(uint16_t i){
50 putc(NESSIE_ALIVE_CHAR, nessie_out_file);
54 void nessie_print_block(uint8_t *block, uint16_t blocksize_bit){
56 for(i=0; i<(blocksize_bit+7)/8; ++i){
57 putc(pgm_read_byte(hexdigit_tab_uc_P + ((block[i]) >> 4)), nessie_out_file);
58 putc(pgm_read_byte(hexdigit_tab_uc_P + ((block[i]) & 0xf)), nessie_out_file);
63 #define BYTESPERLINE 16
65 void nessie_print_item(const char *name, uint8_t *buffer, uint16_t size_B){
68 name_len = strlen(name);
69 if(name_len > SPACES - 1){
70 fputs_P(PSTR("\n!!! formatting error !!!\n"), nessie_out_file);
73 putc('\n', nessie_out_file);
74 for(i = 0; i < SPACES-name_len - 1; ++i){
75 putc(' ', nessie_out_file);
78 putc('=', nessie_out_file);
79 /* now the data printing begins */
80 if(size_B <= BYTESPERLINE){
81 /* one line seems sufficient */
82 nessie_print_block(buffer, size_B * 8);
84 /* we need more lines */
85 nessie_print_block(buffer, BYTESPERLINE * 8); /* first line */
86 int16_t toprint = size_B - BYTESPERLINE;
87 buffer += BYTESPERLINE;
89 putc('\n', nessie_out_file);
90 for(i = 0; i < SPACES; ++i){
91 putc(' ', nessie_out_file);
93 nessie_print_block(buffer, ((toprint > BYTESPERLINE) ? BYTESPERLINE : toprint) * 8);
94 buffer += BYTESPERLINE;
95 toprint -= BYTESPERLINE;
101 void nessie_print_set_vector(uint8_t set, uint16_t vector){
102 fprintf_P(nessie_out_file, PSTR("\n\nSet %"PRIu8", vector#%4"PRIu16":"), set, vector);
106 Test vectors -- set 3
107 =====================
109 void nessie_print_setheader(uint8_t set){
110 fprintf_P(nessie_out_file, PSTR("\r\n\r\nTest vectors -- set %"PRIu8"\n====================="), set);
114 ********************************************************************************
115 *Project NESSIE - New European Schemes for Signature, Integrity, and Encryption*
116 ********************************************************************************
118 Primitive Name: Serpent
119 =======================
124 void nessie_print_header(const char *name,
126 uint16_t blocksize_b,
132 "********************************************************************************\n"
133 "* AVR-Crypto-Lib - crypto primitives for AVR microcontrollers by Daniel Otte *\n"
134 "********************************************************************************\n\n"),
136 fprintf_P(nessie_out_file, PSTR("Primitive Name: %s\n"), name);
138 for(i=0; i<16+strlen(name); ++i){
139 putc('=', nessie_out_file);
142 fprintf_P(nessie_out_file, PSTR("\nKey size: %"PRIu16" bits"), keysize_b);
145 fprintf_P(nessie_out_file, PSTR("\nBlock size: %"PRIu16" bits"), blocksize_b);
148 fprintf_P(nessie_out_file, PSTR("\nHash size: %"PRIu16" bits"), hashsize_b);
152 fprintf_P(nessie_out_file, PSTR("\nMac size: %"PRIu16" bits"), macsize_b);
155 if(ivsize_b==(uint16_t)-1){
156 fputs_P(PSTR("\nNo initial value (IV) mode"), stdout);
158 fprintf_P(nessie_out_file, PSTR("\nIV size: %"PRIu16" bits"), ivsize_b);
161 putc('\n', nessie_out_file);
164 void nessie_print_footer(void){
165 puts_P(PSTR("\n\n\n\nEnd of test vectors\n\n"));