4 * email: daniel.otte@rub.de
7 * common function for nessie-tests
13 #include <avr/pgmspace.h>
14 #include <stdlib.h> /* utoa() */
17 void nessie_print_block(uint8_t* block, uint16_t blocksize_bit){
18 char tab [] = {'0', '1', '2', '3',
23 for(i=0; i<(blocksize_bit+7)/8; ++i){
24 uart_putc(tab[(block[i])>>4]);
25 uart_putc(tab[(block[i])&0xf]);
30 #define BYTESPERLINE 16
32 void nessie_print_item(char* name, uint8_t* buffer, uint16_t size_B){
35 name_len=strlen(name);
36 if(name_len>SPACES-1){
37 uart_putstr_P(PSTR("\r\n!!! formatting error !!!\r\n"));
40 uart_putstr_P(PSTR("\r\n"));
41 for(i=0; i<SPACES-name_len-1; ++i){
46 /* now the data printing begins */
47 if(size_B<=BYTESPERLINE){
48 /* one line seems sufficient */
49 nessie_print_block(buffer, size_B*8);
51 /* we need more lines */
52 nessie_print_block(buffer, BYTESPERLINE*8); /* first line */
53 int16_t toprint = size_B - BYTESPERLINE;
54 buffer += BYTESPERLINE;
56 uart_putstr_P(PSTR("\r\n"));
57 for(i=0; i<SPACES; ++i){
60 nessie_print_block(buffer, ((toprint>BYTESPERLINE)?BYTESPERLINE:toprint)*8);
61 buffer += BYTESPERLINE;
62 toprint -= BYTESPERLINE;
68 void nessie_print_set_vector(uint8_t set, uint16_t vector){
69 uart_putstr_P(PSTR("\r\n\r\nSet "));
70 uart_putc('0'+set%10);
71 uart_putstr_P(PSTR(", vector#"));
72 uart_putc((vector<100)?' ':'0'+vector/100);
73 uart_putc((vector<10 )?' ':'0'+(vector/10)%10);
74 uart_putc('0'+vector%10);
82 void nessie_print_setheader(uint8_t set){
83 uart_putstr_P(PSTR("\r\n\r\nTest vectors -- set "));
84 uart_putc('0'+set%10);
85 uart_putstr_P(PSTR("\r\n====================="));
89 ********************************************************************************
90 *Project NESSIE - New European Schemes for Signature, Integrity, and Encryption*
91 ********************************************************************************
93 Primitive Name: Serpent
94 =======================
99 void nessie_print_header(char* name,
101 uint16_t blocksize_b,
106 uart_putstr_P(PSTR("\r\n\r\n"
107 "********************************************************************************\r\n"
108 "* micro-cryt - crypto primitives for microcontrolles by Daniel Otte *\r\n"
109 "********************************************************************************\r\n"
111 uart_putstr_P(PSTR("Primitive Name: "));
113 uart_putstr_P(PSTR("\r\n"));
115 for(i=0; i<16+strlen(name); ++i){
118 char str[6]; /* must catch numbers up to 65535 + terminatin \0 */
120 uart_putstr_P(PSTR("\r\nKey size: "));
121 utoa(keysize_b, str, 10);
123 uart_putstr_P(PSTR(" bits"));
126 uart_putstr_P(PSTR("\r\nBlock size: "));
127 utoa(blocksize_b, str, 10);
129 uart_putstr_P(PSTR(" bits"));
132 uart_putstr_P(PSTR("\r\nHash size: "));
133 utoa(hashsize_b, str, 10);
135 uart_putstr_P(PSTR(" bits"));
138 uart_putstr_P(PSTR("\r\nMac size: "));
139 utoa(macsize_b, str, 10);
141 uart_putstr_P(PSTR(" bits"));
144 uart_putstr_P(PSTR("\r\nIV size: "));
145 utoa(ivsize_b, str, 10);
147 uart_putstr_P(PSTR(" bits"));
149 uart_putstr_P(PSTR(" bits"));
152 void nessie_print_footer(void){
153 uart_putstr_P(PSTR("\r\n\r\n\r\n\r\nEnd of test vectors\r\n\r\n"));