]> git.cryptolib.org Git - arm-crypto-lib.git/blob - test_src/main-present-test.c
bigint looks good but needs more testing
[arm-crypto-lib.git] / test_src / main-present-test.c
1 /* main-present-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  * present test-suit
21  * 
22 */
23 #include <stdint.h>
24 #include <stdlib.h>
25 #include <string.h>
26 #include "config.h"
27 #include "cli.h"
28 #include "dump.h"
29 #include "uart_lowlevel.h"
30 #include "sysclock.h"
31 #include "hw_gptm.h"
32 #include "config.h"
33
34 #include <present.h>
35 #include "nessie_bc_test.h"
36 #include "performance_test.h"
37 #include "bcal-performance.h"
38 #include "bcal_present.h"
39
40 const char* algo_name = "Present";
41
42 void uart0_putc(char byte){
43         uart_putc(UART_0, byte);
44 }
45
46 char uart0_getc(void){
47         return uart_getc(UART_0);
48 }
49
50 const bcdesc_t* algolist[] = {
51         (bcdesc_t*)&present_desc,
52         NULL
53 };
54
55 /*****************************************************************************
56  *  additional validation-functions                                                                                      *
57  *****************************************************************************/
58 void present_genctx_dummy(uint8_t* key, uint16_t keysize_b, present_ctx_t* ctx){
59         present_init(key, keysize_b, ctx);
60 }
61
62 void testrun_nessie_present(void){
63         nessie_bc_ctx.blocksize_B =   8;
64         nessie_bc_ctx.keysize_b   =  80;
65         nessie_bc_ctx.name        = algo_name;
66         nessie_bc_ctx.ctx_size_B  = sizeof(present_ctx_t);
67         nessie_bc_ctx.cipher_enc  = (nessie_bc_enc_fpt)present_enc;
68         nessie_bc_ctx.cipher_dec  = (nessie_bc_dec_fpt)present_dec;
69         nessie_bc_ctx.cipher_genctx  = (nessie_bc_gen_fpt)present_genctx_dummy;
70         
71         nessie_bc_run();        
72 }
73
74 void testrun_selfenc(uint8_t* key, uint8_t* buffer){
75         present_ctx_t ctx;
76         cli_putstr("\r\nkey   : ");
77         cli_hexdump(key, 10);
78         cli_putstr("\r\nplain : ");
79         cli_hexdump(buffer, 8);
80         present_init(key, 80, &ctx);
81         present_enc(buffer, &ctx);
82         cli_putstr("\r\ncipher: ");
83         cli_hexdump(buffer, 8);
84         present_dec(buffer, &ctx);
85         cli_putstr("\r\nplain : ");
86         cli_hexdump(buffer, 8);
87         cli_putstr("\r\n");
88 }
89
90 void testrun_self_present(void){
91         uint8_t buffer[8], key[10];
92         cli_putstr("\r\n\r\n=== Testvectors from the paper ===\r\n");
93         
94         memset(buffer, 0, 8);
95         memset(key, 0, 10);
96         testrun_selfenc(key, buffer);
97         
98         memset(buffer, 0, 8);
99         memset(key, 0xFF, 10);
100         testrun_selfenc(key, buffer);
101         
102         memset(buffer, 0xFF, 8);
103         memset(key, 0, 10);
104         testrun_selfenc(key, buffer);
105         
106         memset(buffer, 0xFF, 8);
107         memset(key, 0xFF, 10);
108         testrun_selfenc(key, buffer);
109 }
110
111 void testrun_performance_present(void){
112         bcal_performance_multiple(algolist);
113 }
114
115 /*****************************************************************************
116  *  main                                                                                                                                         *
117  *****************************************************************************/
118
119 const char nessie_str[]      = "nessie";
120 const char test_str[]        = "test";
121 const char performance_str[] = "performance";
122 const char echo_str[]        = "echo";
123
124 const cmdlist_entry_t cmdlist[] = {
125         { nessie_str,      NULL, testrun_nessie_present},
126         { test_str,        NULL, testrun_self_present},
127         { performance_str, NULL, testrun_performance_present},
128         { echo_str,    (void*)1, (void_fpt)echo_ctrl},
129         { NULL,            NULL, NULL}
130 };
131
132 int main (void){
133         sysclk_set_freq(SYS_FREQ);
134         sysclk_mosc_verify_enable();
135         uart_init(UART_0, 115200, 8, UART_PARATY_NONE, UART_STOPBITS_ONE);
136         gptm_set_timer_32periodic(TIMER0);
137
138         cli_rx = uart0_getc;
139         cli_tx = uart0_putc;
140         
141         for(;;){
142                 cli_putstr("\r\n\r\nARM-Crypto-Lib VS (");
143                 cli_putstr(algo_name);
144                 cli_putstr("; ");
145                 cli_putstr(__DATE__);
146                 cli_putc(' ');
147                 cli_putstr(__TIME__);
148                 cli_putstr(")\r\nloaded and running\r\n");
149                 cmd_interface(cmdlist);
150         }
151 }