'hardening' infrastucture against toolchain bugs

This commit is contained in:
bg 2011-10-07 21:38:22 +02:00
parent a5fa5eb95b
commit a0b23b3327
8 changed files with 46 additions and 8 deletions

View File

@ -34,7 +34,7 @@ void hfal_nessie(const hfdesc_t* hd){
return;
nessie_hash_ctx.hashsize_b = hd->hashsize_b;
nessie_hash_ctx.name = (char*)(hd->name); /* needs a nicer fix */
nessie_hash_ctx.name = hd->name;
nessie_hash_ctx.blocksize_B = hd->blocksize_b/8;
nessie_hash_ctx.ctx_size_B = hd->ctxsize_B;
nessie_hash_ctx.hash_init = (nessie_hash_init_fpt)(hd->init);

View File

@ -102,7 +102,8 @@ uint8_t cli_getsn(char* s, uint32_t n){
char c;
if(n==0)
return 2;
while((c=cli_getc_cecho())!='\0' && c!='\r' && n--){
while((c=cli_getc_cecho())!='\0' && c!='\r' && n){
--n;
*s++=c;
}
*s='\0';

View File

@ -196,6 +196,9 @@ const cmdlist_entry_t cmdlist[] = {
int main(void) {
main_setup();
shavs_algolist=(hfdesc_t**)algolist;
shavs_algo=(hfdesc_t*)&sha512_desc;
for(;;){
welcome_msg(algo_name);
cmd_interface(cmdlist);

View File

@ -34,6 +34,7 @@
#include "cli.h"
#include "string-extras.h"
#ifdef NESSIE_ALIVE
void nessie_send_alive(void){
cli_putc(NESSIE_ALIVE_CHAR);
@ -129,9 +130,10 @@ void nessie_print_header(const char* name,
uint16_t i;
cli_putstr("\r\n\r\n"
"********************************************************************************\r\n"
"* ARM-Crypto-Lib - crypto primitives for ARM microcontrolles by Daniel Otte *\r\n"
"* ARM-Crypto-Lib - crypto primitives for ARM microcontrollers by Daniel Otte *\r\n"
"********************************************************************************\r\n"
"\r\n");
cli_putstr("Primitive Name: ");
cli_putstr(name);
cli_putstr("\r\n");
@ -139,7 +141,7 @@ void nessie_print_header(const char* name,
for(i=0; i<16+strlen(name); ++i){
cli_putc('=');
}
char str[6]; /* must catch numbers up to 65535 + terminatin \0 */
char str[6]; /* must catch numbers up to 65535 + terminating \0 */
if(keysize_b){
cli_putstr("\r\nKey size: ");
ustoa(keysize_b, str, 10);
@ -158,6 +160,7 @@ void nessie_print_header(const char* name,
cli_putstr(str);
cli_putstr(" bits");
}
if(macsize_b){
cli_putstr("\r\nMac size: ");
ustoa(macsize_b, str, 10);

View File

@ -31,7 +31,7 @@ typedef struct nessie_hash_ctx_st{
uint16_t hashsize_b;
uint16_t blocksize_B;
uint16_t ctx_size_B;
char* name;
const char* name;
nessie_hash_init_fpt hash_init;
nessie_hash_next_fpt hash_next;
nessie_hash_last_fpt hash_last;

View File

@ -42,6 +42,7 @@
#define DEBUG 0
#if DEBUG
#include "uart_lowlevel.h"
//# include "config.h"
//# include <util/delay.h>
#endif
@ -143,9 +144,26 @@ uint8_t buffer_add(char c){
return 0;
}
static
uint32_t my_strtoul(const char* str){
uint32_t r=0;
while(*str && (*str<'0' || *str>'9')){
str++;
}
if(!*str){
return 0;
}
while(*str && (*str>='0' && *str<='9')){
r *= 10;
r += *str-'0';
str++;
}
return r;
}
int32_t getLength(void){
uint32_t len=0;
char lenstr[21];
char lenstr[25];
char* len2;
for(;;){
memset(lenstr, 0, 21);
@ -158,7 +176,8 @@ int32_t getLength(void){
do{
len2++;
}while(*len2 && !isdigit((uint8_t)*len2));
len=(uint32_t)strtoul(len2, NULL, 10);
len = my_strtoul(len2);
//len=(uint32_t)strtoul(len2, NULL, 10);
return len;
}
} else {
@ -189,13 +208,19 @@ void shavs_test1(void){ /* KAT tests */
shavs_ctx.blocks = 0;
memset(buffer, 0, shavs_ctx.buffersize_B);
length = getLength();
if(length<0){
if((int32_t)length<0){
#if DEBUG
cli_putstr("\r\n(x) Len == ");
cli_hexdump_rev(&length, 4);
uart_flush(0);
#endif
return;
}
#if DEBUG
cli_putstr("\r\nLen == ");
cli_hexdump_rev(&length, 4);
uart_flush(0);
#endif
if(length==0){
expect_input=2;

View File

@ -96,7 +96,11 @@ char* ultoa(unsigned long a, char* buffer, uint8_t radix){
return buffer;
}
while(a){
/* toolchain bug??
result = div(a, radix);
*/
result.quot = a/radix;
result.rem = a%radix;
*ptr = result.rem;
if(result.rem<10){
*ptr += '0';

View File

@ -272,6 +272,8 @@ void uart_flush(uint8_t uartno){
if(uartno>UART_MAX){
return;
}
while(circularbytebuffer_cnt(&(uart_tx_buffer[uartno])))
;
while((HW_REG(uart_base[uartno]+UARTCTL_OFFSET)&_BV(UART_EOT)) == 0)
;
}