3 This file is part of the AVR-Crypto-Lib.
4 Copyright (C) 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/>.
24 #include "main-test-common.h"
27 #include "noekeon_prng.h"
29 #include "bigint_io.h"
30 #include "nist_p192.h"
32 #include "performance_test.h"
33 #include "hfal_sha1.h"
34 #include "base64_enc.h"
35 #include "base64_dec.h"
37 char* algo_name = "ECDSA";
39 /*****************************************************************************
40 * additional validation-functions *
41 *****************************************************************************/
43 void testrun_performance_bigint(void){
44 printf_P(PSTR("\n=== performance measurement ===\n"));
47 bigint_word_t v_w[192 * 2 / BIGINT_WORD_SIZE];
48 bigint_word_t a_w[192 * 2 / BIGINT_WORD_SIZE];
49 bigint_word_t b_w[192 * 2 / BIGINT_WORD_SIZE];
50 uint32_t time_a, time_b;
52 int16_t faster_percent;
54 for(j = 0; j < 32; ++j){
56 for(i = 0; i < 192 * 2 / BIGINT_WORD_SIZE; ++i){
57 ((uint8_t*)v_w)[i] = random();
59 v.length_W = 192 * 2 / BIGINT_WORD_SIZE;
64 // printf_P(PSTR("candidate:\n"));
65 // bigint_print_hex(&v);
70 // printf_P(PSTR("\n going to test optimized version: ...\n"));
73 for(i = 0; i < 16; ++i){
77 bigint_reduce_p192(&a);
79 time_a += stopTimer();
81 // printf_P(PSTR(" took: %"PRIu32" cycles\nresult:"), time);
82 // bigint_print_hex(&a);
85 // printf_P(PSTR("\n going to test not-optimized version: ...\n"));
88 for(i = 0; i < 16; ++i){
92 bigint_reduce(&b, &nist_curve_p192_p);
94 time_b += stopTimer();
96 // printf_P(PSTR(" took: %"PRIu32" cycles\nresult:"), time);
97 // bigint_print_hex(&b);
99 time_diff = time_b - time_a;
100 faster_percent = (time_diff * 100) / time_b;
102 printf_P(PSTR(" delta: %7"PRId32" (%3"PRId16"%%) :-"), time_diff, faster_percent);
103 if(bigint_cmp_u(&a, &b)){
104 printf_P(PSTR("(\n"));
106 printf_P(PSTR(")\n"));
112 /*****************************************************************************
114 *****************************************************************************/
116 const char echo_test_str[] PROGMEM = "echo-test";
117 const char reset_prng_str[] PROGMEM = "reset-prng";
118 const char quick_test_str[] PROGMEM = "quick-test";
119 const char performance_str[] PROGMEM = "performance";
120 const char echo_str[] PROGMEM = "echo";
122 const const cmdlist_entry_t cmdlist[] PROGMEM = {
123 // { reset_prng_str, NULL, reset_prng },
124 // { quick_test_str, NULL, quick_test },
125 { performance_str, NULL, testrun_performance_bigint },
126 { echo_str, (void*)1, (void_fpt)echo_ctrl },
135 welcome_msg(algo_name);
136 r = cmd_interface(cmdlist);
137 printf("r = %"PRId8"\n", r);
138 cli_putstr_P(PSTR("\r\nHello!\r\n"));