]> git.cryptolib.org Git - avr-crypto-lib.git/blob - main-entropium-test.c
1268a73cfcd7da632b4b94ef35dfcb36a2011b65
[avr-crypto-lib.git] / main-entropium-test.c
1 /*
2  * entropium test-suit
3  * 
4 */
5
6 #include "config.h"
7 #include "serial-tools.h"
8 #include "uart.h"
9 #include "debug.h"
10
11 #include "entropium.h"
12 #include "nessie_bc_test.h"
13 #include "cli.h"
14 #include "performance_test.h"
15
16 #include <stdint.h>
17 #include <string.h>
18 #include <stdlib.h>
19
20 char* cipher_name = "Entropium";
21
22 /*****************************************************************************
23  *  additional validation-functions                                                                                      *
24  *****************************************************************************/
25
26 void testrun_entropium(void){
27         char c, str[16];
28         uint8_t data[32];
29         uint32_t i=0;
30         while(!uart_getc_nb(&c)){
31                 entropium_getRandomBlock(data);
32                 uart_putstr_P(PSTR("\r\n "));
33                 ultoa(i, str, 10);
34                 for(c=strlen(str); c<11; ++c){
35                         uart_putc(' ');
36                 }
37                 uart_putstr(str);
38                 ++i;
39                 uart_putstr_P(PSTR(" : "));
40                 uart_hexdump(data, 32);
41         }
42         uart_putstr_P(PSTR("\r\n\r\n"));
43 }
44
45
46 void testrun_performance_entropium(void){
47         uint16_t i,c;
48         uint64_t t;
49         char str[16];
50         uint8_t data[32];
51         
52         calibrateTimer();
53         getOverhead(&c, &i);
54         uart_putstr_P(PSTR("\r\n\r\n=== benchmark ==="));
55         utoa(c, str, 10);
56         uart_putstr_P(PSTR("\r\n\tconst overhead:     "));
57         uart_putstr(str);
58         utoa(i, str, 10);
59         uart_putstr_P(PSTR("\r\n\tinterrupt overhead: "));
60         uart_putstr(str);
61         
62         startTimer(1);
63         entropium_addEntropy(128, data);
64         t = stopTimer();
65         uart_putstr_P(PSTR("\r\n\tadd entropy time: "));
66         ultoa((unsigned long)t, str, 10);
67         uart_putstr(str);
68         
69         
70         startTimer(1);
71         entropium_getRandomBlock(data);
72         t = stopTimer();
73         uart_putstr_P(PSTR("\r\n\tget random time:  "));
74         ultoa((unsigned long)t, str, 10);
75         uart_putstr(str);
76         
77         uart_putstr_P(PSTR("\r\n"));
78 }
79 /*****************************************************************************
80  *  main                                                                                                                                         *
81  *****************************************************************************/
82
83 int main (void){
84         char  str[20];
85         DEBUG_INIT();
86         uart_putstr("\r\n");
87
88         uart_putstr_P(PSTR("\r\n\r\nCrypto-VS ("));
89         uart_putstr(cipher_name);
90         uart_putstr_P(PSTR(")\r\nloaded and running\r\n"));
91
92         PGM_P    u   = PSTR("nessie\0test\0performance\0");
93         void_fpt v[] = {testrun_entropium, testrun_entropium, testrun_performance_entropium};
94
95         while(1){ 
96                 if (!getnextwordn(str,20)){DEBUG_S("DBG: W1\r\n"); goto error;}
97                 if(execcommand_d0_P(str, u, v)<0){
98                         uart_putstr_P(PSTR("\r\nunknown command\r\n"));
99                 }
100                 continue;
101         error:
102                 uart_putstr("ERROR\r\n");
103         }
104         
105 }
106