]> git.cryptolib.org Git - avr-crypto-lib.git/blob - test_src/main-twister-test.c
optimizing norx32
[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
25 #include "main-test-common.h"
26
27 #include "twister-small.h"
28 #include "twister-large.h"
29 #include "nessie_hash_test.h"
30 #include "performance_test.h"
31 #include "hfal_twister224.h"
32 #include "hfal_twister256.h"
33 #include "hfal_twister384.h"
34 #include "hfal_twister512.h"
35 #include "hfal-nessie.h"
36 #include "hfal-performance.h"
37 #include "hfal-test.h"
38 #include "shavs.h"
39
40 char *algo_name = "TWISTER";
41
42 const hfdesc_t *const algolist[] PROGMEM = {
43         (hfdesc_t*)&twister224_desc,
44         (hfdesc_t*)&twister256_desc,
45         (hfdesc_t*)&twister384_desc,
46         (hfdesc_t*)&twister512_desc,
47         NULL
48 };
49
50 /*****************************************************************************
51  *  additional validation-functions                                                                                      *
52  *****************************************************************************/
53
54 void testrun_nessie_twister(void){
55         hfal_nessie_multiple(algolist);
56 }
57
58 /*****************************************************************************
59  * selftests
60  *
61  *****************************************************************************/
62
63 void test_twister224( void *msg, uint32_t length_b){
64         hfal_test(&twister224_desc, msg, length_b);
65 }
66
67 void test_twister256( void *msg, uint32_t length_b){
68         hfal_test(&twister256_desc, msg, length_b);
69 }
70
71 void test_twister384( void *msg, uint32_t length_b){
72         hfal_test(&twister384_desc, msg, length_b);
73 }
74
75 void test_twister512( void *msg, uint32_t length_b){
76         hfal_test(&twister512_desc, msg, length_b);
77 }
78
79 void testrun_twister(void){
80         const hfdesc_t *desc[4] = { &twister224_desc, &twister256_desc,
81                                     &twister384_desc, &twister512_desc };
82         uint8_t i,j; 
83         char *testv[]={
84                 "", 
85                 "a", 
86                 "abc", 
87                 "message digest", 
88                 "abcdefghijklmnopqrstuvwxyz", 
89                 "ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789", 
90                 "12345678901234567890123456789012345678901234567890123456789012345678901234567890"};
91         uint8_t stestv[]= {0x00, 0x00, 0xC0, 0xC0, 0x80, 0x48, 0x50};
92         uint8_t stestl[]= {   0,    1,    2,    3,    4,    5,    6};   
93         
94         for(i=0; i<4; ++i){
95                 for(j=0; j<7; ++j){
96                         hfal_test(desc[i], testv[j], strlen(testv[j])*8);
97                 }
98                 hfal_test(desc[i], stestv, 7*8);
99                 hfal_test(desc[i], stestl, 7*8);
100                 
101         }
102 }
103
104
105 void testrun_performance_twister(void){
106         hfal_performance_multiple(algolist);
107 }
108
109
110 /*****************************************************************************
111  * main                                                                                                                                  *
112  *****************************************************************************/
113
114 const char nessie_str[]      PROGMEM = "nessie";
115 const char test_str[]        PROGMEM = "test";
116 const char performance_str[] PROGMEM = "performance";
117 const char echo_str[]        PROGMEM = "echo";
118 const char shavs_list_str[]  PROGMEM = "shavs_list";
119 const char shavs_set_str[]   PROGMEM = "shavs_set";
120 const char shavs_test1_str[] PROGMEM = "shavs_test1";
121
122 const cmdlist_entry_t cmdlist[] PROGMEM = {
123         { nessie_str,          NULL, testrun_nessie_twister},
124         { test_str,            NULL, testrun_twister},
125         { performance_str,     NULL, testrun_performance_twister},
126         { echo_str,        (void*)1, (void_fpt)echo_ctrl},
127         { shavs_list_str,      NULL, shavs_listalgos},
128         { shavs_set_str,   (void*)1, (void_fpt)shavs_setalgo},
129         { shavs_test1_str,     NULL, shavs_test1},
130         { NULL,                NULL, NULL}
131 };
132
133 int main (void){
134     main_setup();
135
136     shavs_algolist=(hfdesc_t**)algolist;
137         shavs_algo=(hfdesc_t*)&twister256_desc;
138         
139         for(;;){
140             welcome_msg(algo_name);
141             cmd_interface(cmdlist);
142         }
143 }