]> git.cryptolib.org Git - avr-crypto-lib.git/blob - test_src/main-twister-test.c
small bug in twister (C) fixed asm version needs fixing
[avr-crypto-lib.git] / test_src / main-twister-test.c
1 /* main-twister-test.c */
2 /*
3     This file is part of the AVR-Crypto-Lib.
4     Copyright (C) 2008, 2009  Daniel Otte (daniel.otte@rub.de)
5
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.
10
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.
15
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/>.
18 */
19 /*
20  * twister test suit
21  * 
22 */
23
24 #include "config.h"
25 #include "serial-tools.h"
26 #include "uart.h"
27 #include "debug.h"
28
29 #include "twister-small.h"
30 #include "nessie_hash_test.h"
31 #include "performance_test.h"
32 #include "hfal_twister224.h"
33 #include "hfal_twister256.h"
34 #include "hfal_twister384.h"
35 #include "hfal_twister512.h"
36 #include "hfal-nessie.h"
37 #include "hfal-performance.h"
38 #include "hfal-test.h"
39 #include "shavs.h"
40
41
42 #include <stdint.h>
43 #include <string.h>
44 #include <stdlib.h>
45 #include "cli.h"
46
47 char* algo_name = "TWISTER";
48
49 const hfdesc_t* algolist[] PROGMEM = {
50         (hfdesc_t*)&twister224_desc,
51         (hfdesc_t*)&twister256_desc,
52         (hfdesc_t*)&twister384_desc,
53         (hfdesc_t*)&twister512_desc,
54         NULL
55 };
56
57 /*****************************************************************************
58  *  additional validation-functions                                                                                      *
59  *****************************************************************************/
60
61 void testrun_nessie_twister(void){
62         hfal_nessie_multiple(algolist);
63 }
64
65 /*****************************************************************************
66  * selftests
67  *
68  *****************************************************************************/
69
70 void test_twister224( void* msg, uint32_t length_b){
71         hfal_test(&twister224_desc, msg, length_b);
72 }
73
74 void test_twister256( void* msg, uint32_t length_b){
75         hfal_test(&twister256_desc, msg, length_b);
76 }
77
78 void test_twister384( void* msg, uint32_t length_b){
79         hfal_test(&twister384_desc, msg, length_b);
80 }
81
82 void test_twister512( void* msg, uint32_t length_b){
83         hfal_test(&twister512_desc, msg, length_b);
84 }
85
86 void testrun_twister(void){
87         const hfdesc_t* desc[4] = { &twister224_desc, &twister256_desc,
88                                     &twister384_desc, &twister512_desc };
89         uint8_t i,j; 
90         char* testv[]={
91                 "", 
92                 "a", 
93                 "abc", 
94                 "message digest", 
95                 "abcdefghijklmnopqrstuvwxyz", 
96                 "ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789", 
97                 "12345678901234567890123456789012345678901234567890123456789012345678901234567890"};
98         uint8_t stestv[]= {0x00, 0x00, 0xC0, 0xC0, 0x80, 0x48, 0x50};
99         uint8_t stestl[]= {   0,    1,    2,    3,    4,    5,    6};   
100         
101         for(i=0; i<4; ++i){
102                 for(j=0; j<7; ++j){
103                         hfal_test(desc[i], testv[j], strlen(testv[j])*8);
104                 }
105                 hfal_test(desc[i], stestv, 7*8);
106                 hfal_test(desc[i], stestl, 7*8);
107                 
108         }
109 }
110
111
112 void testrun_performance_twister(void){
113         hfal_performance_multiple(algolist);
114 }
115
116
117 /*****************************************************************************
118  * main                                                                                                                                  *
119  *****************************************************************************/
120
121 const char nessie_str[]      PROGMEM = "nessie";
122 const char test_str[]        PROGMEM = "test";
123 const char performance_str[] PROGMEM = "performance";
124 const char echo_str[]        PROGMEM = "echo";
125 const char shavs_list_str[]  PROGMEM = "shavs_list";
126 const char shavs_set_str[]   PROGMEM = "shavs_set";
127 const char shavs_test1_str[] PROGMEM = "shavs_test1";
128
129 cmdlist_entry_t cmdlist[] PROGMEM = {
130         { nessie_str,          NULL, testrun_nessie_twister},
131         { test_str,            NULL, testrun_twister},
132         { performance_str,     NULL, testrun_performance_twister},
133         { echo_str,        (void*)1, (void_fpt)echo_ctrl},
134         { shavs_list_str,      NULL, shavs_listalgos},
135         { shavs_set_str,   (void*)1, (void_fpt)shavs_setalgo},
136         { shavs_test1_str,     NULL, shavs_test1},
137         { NULL,                NULL, NULL}
138 };
139
140 int main (void){
141         DEBUG_INIT();
142         
143         cli_rx = uart_getc;
144         cli_tx = uart_putc;             
145         shavs_algolist=(hfdesc_t**)algolist;
146         shavs_algo=(hfdesc_t*)&twister256_desc;
147         for(;;){
148                 cli_putstr_P(PSTR("\r\n\r\nCrypto-VS ("));
149                 cli_putstr(algo_name);
150                 cli_putstr_P(PSTR(")\r\nloaded and running\r\n"));
151                 cmd_interface(cmdlist);
152         }
153 }