]> git.cryptolib.org Git - arm-crypto-lib.git/blob - test_src/main-present-test.c
Adding Present
[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
112 void testrun_performance_present(void){
113         bcal_performance_multiple(algolist);
114 }
115
116 /*****************************************************************************
117  *  main                                                                                                                                         *
118  *****************************************************************************/
119
120 const char nessie_str[]      = "nessie";
121 const char test_str[]        = "test";
122 const char performance_str[] = "performance";
123 const char echo_str[]        = "echo";
124
125 const cmdlist_entry_t cmdlist[] = {
126         { nessie_str,      NULL, testrun_nessie_present},
127         { test_str,        NULL, testrun_self_present},
128         { performance_str, NULL, testrun_performance_present},
129         { echo_str,    (void*)1, (void_fpt)echo_ctrl},
130         { NULL,            NULL, NULL}
131 };
132
133 int main (void){
134         sysclk_set_freq(SYS_FREQ);
135         sysclk_mosc_verify_enable();
136         uart_init(UART_0, 115200, 8, UART_PARATY_NONE, UART_STOPBITS_ONE);
137         gptm_set_timer_32periodic(TIMER0);
138
139         cli_rx = uart0_getc;
140         cli_tx = uart0_putc;
141         
142         for(;;){
143                 cli_putstr("\r\n\r\nARM-Crypto-Lib VS (");
144                 cli_putstr(algo_name);
145                 cli_putstr("; ");
146                 cli_putstr(__DATE__);
147                 cli_putc(' ');
148                 cli_putstr(__TIME__);
149                 cli_putstr(")\r\nloaded and running\r\n");
150                 cmd_interface(cmdlist);
151         }
152 }