]> git.cryptolib.org Git - arm-crypto-lib.git/blob - test_src/main-echo-test.c
more files
[arm-crypto-lib.git] / test_src / main-echo-test.c
1 /* main-echo-test.c */
2 /*
3     This file is part of the ARM-Crypto-Lib.
4     Copyright (C) 2006-2010  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  * Echo test-suit
21  *
22 */
23 #include <stdint.h>
24 #include <stdlib.h>
25 #include <string.h>
26 #include "cli.h"
27 #include "dump.h"
28 #include "uart_lowlevel.h"
29 #include "sysclock.h"
30 #include "hw_gptm.h"
31
32 #include "shavs.h"
33 #include "nessie_hash_test.h"
34 #include "performance_test.h"
35 #include "hfal-nessie.h"
36 #include "hfal-performance.h"
37 #include "hfal-test.h"
38
39 #include "echo.h"
40 #include "hfal_echo.h"
41
42 char* algo_name = "Echo";
43
44
45 const hfdesc_t* algolist[] = {
46         (hfdesc_t*)&echo224_desc,
47         (hfdesc_t*)&echo256_desc,
48         (hfdesc_t*)&echo384_desc,
49         (hfdesc_t*)&echo512_desc,
50         NULL
51 };
52
53 void uart0_putc(char byte){
54         uart_putc(UART_0, byte);
55 }
56
57 char uart0_getc(void){
58         return uart_getc(UART_0);
59 }
60
61 /*****************************************************************************
62  *  additional validation-functions                                                                                      *
63  *****************************************************************************/
64 /* IntermediateKAT1_256.txt */
65 static const
66 uint8_t intermediate_data[] = {
67         0xDB, 0x11, 0xF6, 0x09, 0xBA, 0xBA, 0x7B, 0x0C,
68         0xA6, 0x34, 0x92, 0x6B, 0x1D, 0xD5, 0x39, 0xC8,
69         0xCB, 0xAD, 0xA2, 0x49, 0x67, 0xD7, 0xAD, 0xD4,
70         0xD9, 0x87, 0x6F, 0x77, 0xC2, 0xD8, 0x0C, 0x0F,
71         0x4D, 0xCE, 0xFB, 0xD7, 0x12, 0x15, 0x48, 0x37,
72         0x35, 0x82, 0x70, 0x5C, 0xCA, 0x24, 0x95, 0xBD,
73         0x2A, 0x43, 0x71, 0x6F, 0xE6, 0x4E, 0xD2, 0x6D,
74         0x05, 0x9C, 0xFB, 0x56, 0x6B, 0x33, 0x64, 0xBD,
75         0x49, 0xEE, 0x07, 0x17, 0xBD, 0xD9, 0x81, 0x0D,
76         0xD1, 0x4D, 0x8F, 0xAD, 0x80, 0xDB, 0xBD, 0xC4,
77         0xCA, 0xFB, 0x37, 0xCC, 0x60, 0xFB, 0x0F, 0xE2,
78         0xA8, 0x0F, 0xB4, 0x54, 0x1B, 0x8C, 0xA9, 0xD5,
79         0x9D, 0xCE, 0x45, 0x77, 0x38, 0xA9, 0xD3, 0xD8,
80         0xF6, 0x41, 0xAF, 0x8C, 0x3F, 0xD6, 0xDA, 0x16,
81         0x2D, 0xC1, 0x6F, 0xC0, 0x1A, 0xAC, 0x52, 0x7A,
82         0x4A, 0x02, 0x55, 0xB4, 0xD2, 0x31, 0xC0, 0xBE,
83         0x50, 0xF4, 0x4F, 0x0D, 0xB0, 0xB7, 0x13, 0xAF,
84         0x03, 0xD9, 0x68, 0xFE, 0x7F, 0x0F, 0x61, 0xED,
85         0x08, 0x24, 0xC5, 0x5C, 0x4B, 0x52, 0x65, 0x54,
86         0x8F, 0xEB, 0xD6, 0xAA, 0xD5, 0xC5, 0xEE, 0xDF,
87         0x63, 0xEF, 0xE7, 0x93, 0x48, 0x9C, 0x39, 0xB8,
88         0xFD, 0x29, 0xD1, 0x04, 0xCE
89         };
90
91 static const
92 uint8_t intermediate_data2[] = {
93         0x75, 0x8E, 0xA3, 0xFE, 0xA7, 0x38, 0x97, 0x3D,
94         0xB0, 0xB8, 0xBE, 0x7E, 0x59, 0x9B, 0xBE, 0xF4,
95         0x51, 0x93, 0x73, 0xD6, 0xE6, 0xDC, 0xD7, 0x19,
96         0x5E, 0xA8, 0x85, 0xFC, 0x99, 0x1D, 0x89, 0x67,
97         0x62, 0x99, 0x27, 0x59, 0xC2, 0xA0, 0x90, 0x02,
98         0x91, 0x2F, 0xB0, 0x8E, 0x0C, 0xB5, 0xB7, 0x6F,
99         0x49, 0x16, 0x2A, 0xEB, 0x8C, 0xF8, 0x7B, 0x17,
100         0x2C, 0xF3, 0xAD, 0x19, 0x02, 0x53, 0xDF, 0x61,
101         0x2F, 0x77, 0xB1, 0xF0, 0xC5, 0x32, 0xE3, 0xB5,
102         0xFC, 0x99, 0xC2, 0xD3, 0x1F, 0x8F, 0x65, 0x01,
103         0x16, 0x95, 0xA0, 0x87, 0xA3, 0x5E, 0xE4, 0xEE,
104         0xE5, 0xE3, 0x34, 0xC3, 0x69, 0xD8, 0xEE, 0x5D,
105         0x29, 0xF6, 0x95, 0x81, 0x5D, 0x86, 0x6D, 0xA9,
106         0x9D, 0xF3, 0xF7, 0x94, 0x03
107 };
108
109 void echo256_interm(void){
110         echo_small_ctx_t ctx;
111         uint8_t data[1384/8];
112         uint8_t hash[32];
113         echo256_init(&ctx);
114         memcpy(data, intermediate_data, 173);
115         cli_putstr("\r\ninit done ");
116         echo_small_lastBlock(&ctx, data, 1384);
117         cli_putstr("\r\nlastblock done ");
118         echo256_ctx2hash(hash, &ctx);
119         cli_putstr("\r\nhash = ");
120         cli_hexdump(hash, 32);
121 }
122
123 void echo512_interm(void){
124         echo_large_ctx_t ctx;
125         uint8_t data[872/8];
126         uint8_t hash[64];
127         echo512_init(&ctx);
128         memcpy(data, intermediate_data2, 872/8);
129         cli_putstr("\r\ninit done ");
130         echo_large_lastBlock(&ctx, data, 872);
131         cli_putstr("\r\nlastblock done ");
132         echo512_ctx2hash(hash, &ctx);
133         cli_putstr("\r\nhash = ");
134         cli_hexdump(hash, 64);
135 }
136
137 void echo256_test0(void){
138         echo_small_ctx_t ctx;
139         uint8_t hash[32];
140         echo256_init(&ctx);
141         cli_putstr("\r\ninit done ");
142         echo_small_lastBlock(&ctx, NULL, 0);
143         cli_putstr("\r\nlastblock done ");
144         echo256_ctx2hash(hash, &ctx);
145         cli_putstr("\r\nhash = ");
146         cli_hexdump(hash, 32);
147 }
148
149 void performance_echo(void){
150         hfal_performance_multiple(algolist);
151 }
152
153 void testrun_nessie_echo(void){
154         hfal_nessie_multiple(algolist);
155 }
156 /*****************************************************************************
157  *  main                                                                                                                                         *
158  *****************************************************************************/
159
160 const char nessie_str[]       = "nessie";
161 const char test256_str[]      = "test256";
162 const char interm_str[]       = "interm";
163 const char interm2_str[]      = "interm2";
164 const char performance_str[]  = "performance";
165 const char echo_str[]         = "echo";
166 const char shavs_list_str[]   = "shavs_list";
167 const char shavs_set_str[]    = "shavs_set";
168 const char shavs_test1_str[]  = "shavs_test1";
169 const char shavs_test3_str[]  = "shavs_test3";
170
171 cmdlist_entry_t cmdlist[]  = {
172         { nessie_str,                NULL, testrun_nessie_echo         },
173         { interm_str,                NULL, echo256_interm              },
174         { interm2_str,               NULL, echo512_interm              },
175         { test256_str,               NULL, echo256_test0               },
176         { performance_str,           NULL, performance_echo            },
177         { shavs_list_str,            NULL, shavs_listalgos             },
178         { shavs_set_str,         (void*)1, (void_fpt)shavs_setalgo     },
179         { shavs_test1_str,           NULL, shavs_test1                 },
180         { shavs_test3_str,           NULL, shavs_test3                 },
181         { echo_str,              (void*)1, (void_fpt)echo_ctrl         },
182         { NULL,                      NULL, NULL                        }
183 };
184
185 int main(void) {
186         sysclk_set_80MHz();
187         sysclk_mosc_verify_enable();
188     uart_init(UART_0, 115200, 8, UART_PARATY_NONE, UART_STOPBITS_ONE);
189     gptm_set_timer_32periodic(TIMER0);
190
191         cli_rx = uart0_getc;
192     cli_tx = uart0_putc;
193
194         shavs_algolist=(hfdesc_t**)algolist;
195         shavs_algo=(hfdesc_t*)&echo256_desc;
196
197         for(;;){
198                 cli_putstr("\r\n\r\nARM-Crypto-Lib VS (");
199                 cli_putstr(algo_name);
200                 cli_putstr("; ");
201                 cli_putstr(__DATE__);
202                 cli_putc(' ');
203                 cli_putstr(__TIME__);
204                 cli_putstr(")\r\nloaded and running\r\n");
205         cmd_interface(cmdlist);
206     }
207
208 }