]> git.cryptolib.org Git - avr-crypto-lib.git/blob - main-present-test.c
+RC5 +size-statistics tool +small modification to nessie_bc_test (optional free(...
[avr-crypto-lib.git] / main-present-test.c
1 /*
2  * present 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 "present.h"
12 #include "nessie_bc_test.h"
13 #include "cli.h"
14
15 #include <stdint.h>
16 #include <string.h>
17
18 char* cipher_name = "Present";
19
20 /*****************************************************************************
21  *  additional validation-functions                                                                                      *
22  *****************************************************************************/
23 void present_genctx_dummy(uint8_t* key, uint16_t keysize_b, present_ctx_t* ctx){
24         present_init(key, keysize_b, ctx);
25 }
26
27 void testrun_nessie_present(void){
28         nessie_bc_ctx.blocksize_B =   8;
29         nessie_bc_ctx.keysize_b   =  80;
30         nessie_bc_ctx.name        = cipher_name;
31         nessie_bc_ctx.ctx_size_B  = sizeof(present_ctx_t);
32         nessie_bc_ctx.cipher_enc  = (nessie_bc_enc_fpt)present_enc;
33         nessie_bc_ctx.cipher_dec  = (nessie_bc_dec_fpt)present_dec;
34         nessie_bc_ctx.cipher_genctx  = (nessie_bc_gen_fpt)present_genctx_dummy;
35         
36         nessie_bc_run();        
37 }
38
39 void testrun_selfenc(uint8_t* key, uint8_t* buffer){
40         present_ctx_t ctx;
41         uart_putstr_P(PSTR("\r\nkey   : "));
42         uart_hexdump(key, 10);
43         uart_putstr_P(PSTR("\r\nplain : "));
44         uart_hexdump(buffer, 8);
45         present_init(key, 80, &ctx);
46         present_enc(buffer, &ctx);
47         uart_putstr_P(PSTR("\r\ncipher: "));
48         uart_hexdump(buffer, 8);
49         present_dec(buffer, &ctx);
50         uart_putstr_P(PSTR("\r\nplain : "));
51         uart_hexdump(buffer, 8);
52         uart_putstr_P(PSTR("\r\n"));
53 }
54
55 void testrun_self_present(void){
56         uint8_t buffer[8], key[10];
57         uart_putstr_P(PSTR("\r\n\r\n=== Testvectors from the paper ===\r\n"));
58         
59         memset(buffer, 0, 8);
60         memset(key, 0, 10);
61         testrun_selfenc(key, buffer);
62         
63         memset(buffer, 0, 8);
64         memset(key, 0xFF, 10);
65         testrun_selfenc(key, buffer);
66         
67         memset(buffer, 0xFF, 8);
68         memset(key, 0, 10);
69         testrun_selfenc(key, buffer);
70         
71         memset(buffer, 0xFF, 8);
72         memset(key, 0xFF, 10);
73         testrun_selfenc(key, buffer);
74         
75 }
76
77 /*****************************************************************************
78  *  main                                                                                                                                         *
79  *****************************************************************************/
80
81 typedef void(*void_fpt)(void);
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\0");
93         void_fpt v[] = {testrun_nessie_present, testrun_self_present};
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 }