'hardening' infrastucture against toolchain bugs
This commit is contained in:
parent
a5fa5eb95b
commit
a0b23b3327
|
@ -34,7 +34,7 @@ void hfal_nessie(const hfdesc_t* hd){
|
||||||
return;
|
return;
|
||||||
|
|
||||||
nessie_hash_ctx.hashsize_b = hd->hashsize_b;
|
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.blocksize_B = hd->blocksize_b/8;
|
||||||
nessie_hash_ctx.ctx_size_B = hd->ctxsize_B;
|
nessie_hash_ctx.ctx_size_B = hd->ctxsize_B;
|
||||||
nessie_hash_ctx.hash_init = (nessie_hash_init_fpt)(hd->init);
|
nessie_hash_ctx.hash_init = (nessie_hash_init_fpt)(hd->init);
|
||||||
|
|
|
@ -102,7 +102,8 @@ uint8_t cli_getsn(char* s, uint32_t n){
|
||||||
char c;
|
char c;
|
||||||
if(n==0)
|
if(n==0)
|
||||||
return 2;
|
return 2;
|
||||||
while((c=cli_getc_cecho())!='\0' && c!='\r' && n--){
|
while((c=cli_getc_cecho())!='\0' && c!='\r' && n){
|
||||||
|
--n;
|
||||||
*s++=c;
|
*s++=c;
|
||||||
}
|
}
|
||||||
*s='\0';
|
*s='\0';
|
||||||
|
|
|
@ -196,6 +196,9 @@ const cmdlist_entry_t cmdlist[] = {
|
||||||
int main(void) {
|
int main(void) {
|
||||||
main_setup();
|
main_setup();
|
||||||
|
|
||||||
|
shavs_algolist=(hfdesc_t**)algolist;
|
||||||
|
shavs_algo=(hfdesc_t*)&sha512_desc;
|
||||||
|
|
||||||
for(;;){
|
for(;;){
|
||||||
welcome_msg(algo_name);
|
welcome_msg(algo_name);
|
||||||
cmd_interface(cmdlist);
|
cmd_interface(cmdlist);
|
||||||
|
|
|
@ -34,6 +34,7 @@
|
||||||
#include "cli.h"
|
#include "cli.h"
|
||||||
#include "string-extras.h"
|
#include "string-extras.h"
|
||||||
|
|
||||||
|
|
||||||
#ifdef NESSIE_ALIVE
|
#ifdef NESSIE_ALIVE
|
||||||
void nessie_send_alive(void){
|
void nessie_send_alive(void){
|
||||||
cli_putc(NESSIE_ALIVE_CHAR);
|
cli_putc(NESSIE_ALIVE_CHAR);
|
||||||
|
@ -129,9 +130,10 @@ void nessie_print_header(const char* name,
|
||||||
uint16_t i;
|
uint16_t i;
|
||||||
cli_putstr("\r\n\r\n"
|
cli_putstr("\r\n\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"
|
||||||
"\r\n");
|
"\r\n");
|
||||||
|
|
||||||
cli_putstr("Primitive Name: ");
|
cli_putstr("Primitive Name: ");
|
||||||
cli_putstr(name);
|
cli_putstr(name);
|
||||||
cli_putstr("\r\n");
|
cli_putstr("\r\n");
|
||||||
|
@ -139,7 +141,7 @@ void nessie_print_header(const char* name,
|
||||||
for(i=0; i<16+strlen(name); ++i){
|
for(i=0; i<16+strlen(name); ++i){
|
||||||
cli_putc('=');
|
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){
|
if(keysize_b){
|
||||||
cli_putstr("\r\nKey size: ");
|
cli_putstr("\r\nKey size: ");
|
||||||
ustoa(keysize_b, str, 10);
|
ustoa(keysize_b, str, 10);
|
||||||
|
@ -158,6 +160,7 @@ void nessie_print_header(const char* name,
|
||||||
cli_putstr(str);
|
cli_putstr(str);
|
||||||
cli_putstr(" bits");
|
cli_putstr(" bits");
|
||||||
}
|
}
|
||||||
|
|
||||||
if(macsize_b){
|
if(macsize_b){
|
||||||
cli_putstr("\r\nMac size: ");
|
cli_putstr("\r\nMac size: ");
|
||||||
ustoa(macsize_b, str, 10);
|
ustoa(macsize_b, str, 10);
|
||||||
|
|
|
@ -31,7 +31,7 @@ typedef struct nessie_hash_ctx_st{
|
||||||
uint16_t hashsize_b;
|
uint16_t hashsize_b;
|
||||||
uint16_t blocksize_B;
|
uint16_t blocksize_B;
|
||||||
uint16_t ctx_size_B;
|
uint16_t ctx_size_B;
|
||||||
char* name;
|
const char* name;
|
||||||
nessie_hash_init_fpt hash_init;
|
nessie_hash_init_fpt hash_init;
|
||||||
nessie_hash_next_fpt hash_next;
|
nessie_hash_next_fpt hash_next;
|
||||||
nessie_hash_last_fpt hash_last;
|
nessie_hash_last_fpt hash_last;
|
||||||
|
|
|
@ -42,6 +42,7 @@
|
||||||
#define DEBUG 0
|
#define DEBUG 0
|
||||||
|
|
||||||
#if DEBUG
|
#if DEBUG
|
||||||
|
#include "uart_lowlevel.h"
|
||||||
//# include "config.h"
|
//# include "config.h"
|
||||||
//# include <util/delay.h>
|
//# include <util/delay.h>
|
||||||
#endif
|
#endif
|
||||||
|
@ -143,9 +144,26 @@ uint8_t buffer_add(char c){
|
||||||
return 0;
|
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){
|
int32_t getLength(void){
|
||||||
uint32_t len=0;
|
uint32_t len=0;
|
||||||
char lenstr[21];
|
char lenstr[25];
|
||||||
char* len2;
|
char* len2;
|
||||||
for(;;){
|
for(;;){
|
||||||
memset(lenstr, 0, 21);
|
memset(lenstr, 0, 21);
|
||||||
|
@ -158,7 +176,8 @@ int32_t getLength(void){
|
||||||
do{
|
do{
|
||||||
len2++;
|
len2++;
|
||||||
}while(*len2 && !isdigit((uint8_t)*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;
|
return len;
|
||||||
}
|
}
|
||||||
} else {
|
} else {
|
||||||
|
@ -189,13 +208,19 @@ void shavs_test1(void){ /* KAT tests */
|
||||||
shavs_ctx.blocks = 0;
|
shavs_ctx.blocks = 0;
|
||||||
memset(buffer, 0, shavs_ctx.buffersize_B);
|
memset(buffer, 0, shavs_ctx.buffersize_B);
|
||||||
length = getLength();
|
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;
|
return;
|
||||||
}
|
}
|
||||||
|
|
||||||
#if DEBUG
|
#if DEBUG
|
||||||
cli_putstr("\r\nLen == ");
|
cli_putstr("\r\nLen == ");
|
||||||
cli_hexdump_rev(&length, 4);
|
cli_hexdump_rev(&length, 4);
|
||||||
|
uart_flush(0);
|
||||||
#endif
|
#endif
|
||||||
if(length==0){
|
if(length==0){
|
||||||
expect_input=2;
|
expect_input=2;
|
||||||
|
|
|
@ -96,7 +96,11 @@ char* ultoa(unsigned long a, char* buffer, uint8_t radix){
|
||||||
return buffer;
|
return buffer;
|
||||||
}
|
}
|
||||||
while(a){
|
while(a){
|
||||||
|
/* toolchain bug??
|
||||||
result = div(a, radix);
|
result = div(a, radix);
|
||||||
|
*/
|
||||||
|
result.quot = a/radix;
|
||||||
|
result.rem = a%radix;
|
||||||
*ptr = result.rem;
|
*ptr = result.rem;
|
||||||
if(result.rem<10){
|
if(result.rem<10){
|
||||||
*ptr += '0';
|
*ptr += '0';
|
||||||
|
|
|
@ -272,6 +272,8 @@ void uart_flush(uint8_t uartno){
|
||||||
if(uartno>UART_MAX){
|
if(uartno>UART_MAX){
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
while(circularbytebuffer_cnt(&(uart_tx_buffer[uartno])))
|
||||||
|
;
|
||||||
while((HW_REG(uart_base[uartno]+UARTCTL_OFFSET)&_BV(UART_EOT)) == 0)
|
while((HW_REG(uart_base[uartno]+UARTCTL_OFFSET)&_BV(UART_EOT)) == 0)
|
||||||
;
|
;
|
||||||
}
|
}
|
||||||
|
|
Loading…
Reference in New Issue