1 /* main-present-test.c */
3 This file is part of the ARM-Crypto-Lib.
4 Copyright (C) 2006-2010 Daniel Otte (daniel.otte@rub.de)
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.
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.
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/>.
29 #include "uart_lowlevel.h"
35 #include "nessie_bc_test.h"
36 #include "performance_test.h"
37 #include "bcal-performance.h"
38 #include "bcal_present.h"
40 const char* algo_name = "Present";
42 void uart0_putc(char byte){
43 uart_putc(UART_0, byte);
46 char uart0_getc(void){
47 return uart_getc(UART_0);
50 const bcdesc_t* algolist[] = {
51 (bcdesc_t*)&present_desc,
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);
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;
74 void testrun_selfenc(uint8_t* key, uint8_t* buffer){
76 cli_putstr("\r\nkey : ");
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);
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");
96 testrun_selfenc(key, buffer);
99 memset(key, 0xFF, 10);
100 testrun_selfenc(key, buffer);
102 memset(buffer, 0xFF, 8);
104 testrun_selfenc(key, buffer);
106 memset(buffer, 0xFF, 8);
107 memset(key, 0xFF, 10);
108 testrun_selfenc(key, buffer);
111 void testrun_performance_present(void){
112 bcal_performance_multiple(algolist);
115 /*****************************************************************************
117 *****************************************************************************/
119 const char nessie_str[] = "nessie";
120 const char test_str[] = "test";
121 const char performance_str[] = "performance";
122 const char echo_str[] = "echo";
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},
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);
142 cli_putstr("\r\n\r\nARM-Crypto-Lib VS (");
143 cli_putstr(algo_name);
145 cli_putstr(__DATE__);
147 cli_putstr(__TIME__);
148 cli_putstr(")\r\nloaded and running\r\n");
149 cmd_interface(cmdlist);