1 /* main-sha256-test.c */
3 This file is part of the AVR-Crypto-Lib.
4 Copyright (C) 2008 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/>.
25 #include "serial-tools.h"
30 #include "nessie_hash_test.h"
31 #include "performance_test.h"
38 #include "hfal_sha256.h"
41 char* algo_name = "SHA-256";
43 /*****************************************************************************
44 * additional validation-functions *
45 *****************************************************************************/
46 void sha256_next_dummy(void* buffer, void* ctx){
47 sha256_nextBlock(ctx, buffer);
50 void sha256_last_dummy(void* buffer, uint16_t size_b, void* ctx){
51 sha256_lastBlock(ctx, buffer, size_b);
54 void testrun_nessie_sha256(void){
55 nessie_hash_ctx.hashsize_b = 256;
56 nessie_hash_ctx.blocksize_B = 512/8;
57 nessie_hash_ctx.ctx_size_B = sizeof(sha256_ctx_t);
58 nessie_hash_ctx.name = algo_name;
59 nessie_hash_ctx.hash_init = (nessie_hash_init_fpt)sha256_init;
60 nessie_hash_ctx.hash_next = (nessie_hash_next_fpt)sha256_next_dummy;
61 nessie_hash_ctx.hash_last = (nessie_hash_last_fpt)sha256_last_dummy;
62 nessie_hash_ctx.hash_conv = (nessie_hash_conv_fpt)sha256_ctx2hash;
67 void testrun_performance_sha256(void){
81 cli_putstr_P(PSTR("\r\n\tctx-gen time: "));
82 ultoa((unsigned long)t, str, 10);
87 sha256_nextBlock(&ctx, data);
89 cli_putstr_P(PSTR("\r\n\tone-block time: "));
90 ultoa((unsigned long)t, str, 10);
95 sha256_lastBlock(&ctx, data, 0);
97 cli_putstr_P(PSTR("\r\n\tlast block time: "));
98 ultoa((unsigned long)t, str, 10);
101 cli_putstr_P(PSTR("\r\n"));
104 /*****************************************************************************
106 *****************************************************************************/
108 const char nessie_str[] PROGMEM = "nessie";
109 const char test_str[] PROGMEM = "test";
110 const char performance_str[] PROGMEM = "performance";
111 const char echo_str[] PROGMEM = "echo";
112 const char shavs_list_str[] PROGMEM = "shavs_list";
113 const char shavs_set_str[] PROGMEM = "shavs_set";
114 const char shavs_test1_str[] PROGMEM = "shavs_test1";
115 const char dump_str[] PROGMEM = "dump";
117 const hfdesc_t* algolist[] PROGMEM = {
118 (hfdesc_t*)&sha256_desc,
122 cmdlist_entry_t cmdlist[] PROGMEM = {
123 { nessie_str, NULL, testrun_nessie_sha256},
124 { test_str, NULL, testrun_nessie_sha256},
125 { performance_str, NULL, testrun_performance_sha256},
126 { echo_str, (void*)1, (void_fpt)echo_ctrl},
127 { shavs_list_str, NULL, shavs_listalgos},
128 { shavs_set_str, (void*)1, (void_fpt)shavs_setalgo},
129 { shavs_test1_str, NULL, shavs_test1},
130 { dump_str, (void*)1, (void_fpt)dump},
139 shavs_algolist=(hfdesc_t**)algolist;
140 shavs_algo=(hfdesc_t*)&sha256_desc;
142 cli_putstr_P(PSTR("\r\n\r\nCrypto-VS ("));
143 cli_putstr(algo_name);
144 cli_putstr_P(PSTR(")\r\nloaded and running\r\n"));
145 cmd_interface(cmdlist);