]> git.cryptolib.org Git - avr-crypto-lib.git/blob - test_src/shavs.c
new hash function abstraction layer + shavs + dump util + ...
[avr-crypto-lib.git] / test_src / shavs.c
1 /* shavs.c */
2 /*
3     This file is part of the AVR-Crypto-Lib.
4     Copyright (C) 2008  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  * \file        shavs.c
21  * \author  Daniel Otte 
22  * \date    2006-05-16
23  * \license     GPLv3 or later
24  * 
25  */
26
27 #include <avr/pgmspace.h>
28 #include <stdint.h>
29 #include <stdlib.h>
30 #include "hashfunction_descriptor.h"
31 #include "shavs.h"
32 #include "string-extras.h"
33 #include "cli.h"
34
35 hfdesc_t*  algo=NULL;
36 hfdesc_t** algolist=NULL;
37
38 void shavs_listalgos(void){
39         char option = 'a';
40         
41         cli_putstr_P(PSTR("\r\nDBG: &algolist: "));
42         cli_hexdump(&algolist, 2);
43         cli_putstr_P(PSTR("\r\nDBG: algolist[0]: "));
44         cli_hexdump(algolist, 8);
45         
46         hfdesc_t* t;
47         uint8_t i=0;
48         cli_putstr_P(PSTR("\r\nthe following algorithms are available:\r\n"));
49         while(option<='z' && (t=(hfdesc_t*)pgm_read_word(&(algolist[i])))){
50                 cli_putc('\t');
51                 cli_putc((t==algo)?'*':' ');
52                 cli_putc(option++);
53                 cli_putstr_P(PSTR(":\t"));
54                 cli_putstr_P((void*)(pgm_read_word(&(t->name))));
55                 cli_putstr_P(PSTR("\r\n"));
56                 i++;
57         }
58 }
59
60 void shavs_setalgo(char* param){
61         param = strstrip(param);
62         if(param[1]=='\0'){ /* single letter specified */
63                 uint8_t i,option = param[0]-'a';
64                 
65                 if(!algolist){
66                         cli_putstr_P(PSTR("\r\nERROR: algolist not set!"));
67                         return;
68                 }
69                 for(i=0; i<=option; ++i){
70                         if((void*)pgm_read_word(&(algolist[i]))==NULL){
71                                 cli_putstr_P(PSTR("\r\nERROR: invalid selection!"));
72                                 return;
73                         }
74                 }
75                 algo=(hfdesc_t*)pgm_read_word(&(algolist[option]));
76         } else { /* name specifyed */ 
77                 hfdesc_t* t=NULL;
78                 uint8_t i=0;
79                 while((t=(hfdesc_t*)pgm_read_word(&(algolist[i]))) &&
80                        strcasecmp_P(param, (void*)pgm_read_word(&(t->name))))
81                         ++i;
82                 if(t){
83                         algo=t;
84                 }else{
85                         cli_putstr_P(PSTR("\r\nERROR: could not find \""));
86                         cli_putstr(param);
87                         cli_putstr_P(PSTR("\"!"));
88                 }       
89         }
90 }
91