X-Git-Url: https://git.cryptolib.org/?a=blobdiff_plain;f=test_src%2Fshavs.c;fp=test_src%2Fshavs.c;h=bde453b710a430678d3d942ef145d162a49966c5;hb=e5a49deb52521f019e37779d6e9d81ec4f02aba4;hp=0000000000000000000000000000000000000000;hpb=e9d58dce0a1eca2c78aec260406e1605ae29fff7;p=avr-crypto-lib.git diff --git a/test_src/shavs.c b/test_src/shavs.c new file mode 100644 index 0000000..bde453b --- /dev/null +++ b/test_src/shavs.c @@ -0,0 +1,91 @@ +/* shavs.c */ +/* + This file is part of the AVR-Crypto-Lib. + Copyright (C) 2008 Daniel Otte (daniel.otte@rub.de) + + This program is free software: you can redistribute it and/or modify + it under the terms of the GNU General Public License as published by + the Free Software Foundation, either version 3 of the License, or + (at your option) any later version. + + This program is distributed in the hope that it will be useful, + but WITHOUT ANY WARRANTY; without even the implied warranty of + MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + GNU General Public License for more details. + + You should have received a copy of the GNU General Public License + along with this program. If not, see . +*/ +/** + * \file shavs.c + * \author Daniel Otte + * \date 2006-05-16 + * \license GPLv3 or later + * + */ + +#include +#include +#include +#include "hashfunction_descriptor.h" +#include "shavs.h" +#include "string-extras.h" +#include "cli.h" + +hfdesc_t* algo=NULL; +hfdesc_t** algolist=NULL; + +void shavs_listalgos(void){ + char option = 'a'; + + cli_putstr_P(PSTR("\r\nDBG: &algolist: ")); + cli_hexdump(&algolist, 2); + cli_putstr_P(PSTR("\r\nDBG: algolist[0]: ")); + cli_hexdump(algolist, 8); + + hfdesc_t* t; + uint8_t i=0; + cli_putstr_P(PSTR("\r\nthe following algorithms are available:\r\n")); + while(option<='z' && (t=(hfdesc_t*)pgm_read_word(&(algolist[i])))){ + cli_putc('\t'); + cli_putc((t==algo)?'*':' '); + cli_putc(option++); + cli_putstr_P(PSTR(":\t")); + cli_putstr_P((void*)(pgm_read_word(&(t->name)))); + cli_putstr_P(PSTR("\r\n")); + i++; + } +} + +void shavs_setalgo(char* param){ + param = strstrip(param); + if(param[1]=='\0'){ /* single letter specified */ + uint8_t i,option = param[0]-'a'; + + if(!algolist){ + cli_putstr_P(PSTR("\r\nERROR: algolist not set!")); + return; + } + for(i=0; i<=option; ++i){ + if((void*)pgm_read_word(&(algolist[i]))==NULL){ + cli_putstr_P(PSTR("\r\nERROR: invalid selection!")); + return; + } + } + algo=(hfdesc_t*)pgm_read_word(&(algolist[option])); + } else { /* name specifyed */ + hfdesc_t* t=NULL; + uint8_t i=0; + while((t=(hfdesc_t*)pgm_read_word(&(algolist[i]))) && + strcasecmp_P(param, (void*)pgm_read_word(&(t->name)))) + ++i; + if(t){ + algo=t; + }else{ + cli_putstr_P(PSTR("\r\nERROR: could not find \"")); + cli_putstr(param); + cli_putstr_P(PSTR("\"!")); + } + } +} +