fixing a bug in sha1-C and sha256-C (only C-Versions are affected) in setting the padding bit for non-byte messages
This commit is contained in:
parent
572b35bb74
commit
e9d58dce0a
|
@ -2,24 +2,6 @@
|
||||||
|
|
||||||
require 'serialport'
|
require 'serialport'
|
||||||
|
|
||||||
if ARGV.size < 5
|
|
||||||
STDERR.print <<EOF
|
|
||||||
Usage: ruby #{$0} port bps nbits stopb command [target_dir] [additional specifier]
|
|
||||||
EOF
|
|
||||||
exit(1)
|
|
||||||
end
|
|
||||||
|
|
||||||
command=ARGV[4]+" ";
|
|
||||||
$dir=(ARGV.size>=6)?ARGV[5]:"";
|
|
||||||
param=(ARGV.size>=7)?ARGV[6]:"";
|
|
||||||
|
|
||||||
puts("\nPort: "+ARGV[0]+ "@"+ARGV[1]+" "+ARGV[2]+"N"+ARGV[3]+"\n");
|
|
||||||
$linewidth = 16
|
|
||||||
$sp = SerialPort.new(ARGV[0], ARGV[1].to_i, ARGV[2].to_i, ARGV[3].to_i, SerialPort::NONE);
|
|
||||||
$sp.read_timeout=1*60*1000; # 5 minutes
|
|
||||||
$extended_wait=10;
|
|
||||||
$sp.write(command);
|
|
||||||
|
|
||||||
def readTestVector(param)
|
def readTestVector(param)
|
||||||
fname=$dir;
|
fname=$dir;
|
||||||
lb="";
|
lb="";
|
||||||
|
@ -98,6 +80,25 @@ def readTestVector(param)
|
||||||
return true
|
return true
|
||||||
end
|
end
|
||||||
|
|
||||||
|
|
||||||
|
if ARGV.size < 5
|
||||||
|
STDERR.print <<EOF
|
||||||
|
Usage: ruby #{$0} port bps nbits stopb command [target_dir] [additional specifier]
|
||||||
|
EOF
|
||||||
|
exit(1)
|
||||||
|
end
|
||||||
|
|
||||||
|
command=ARGV[4]+"\r";
|
||||||
|
$dir=(ARGV.size>=6)?ARGV[5]:"";
|
||||||
|
param=(ARGV.size>=7)?ARGV[6]:"";
|
||||||
|
|
||||||
|
puts("\nPort: "+ARGV[0]+ "@"+ARGV[1]+" "+ARGV[2]+"N"+ARGV[3]+"\n");
|
||||||
|
$linewidth = 16
|
||||||
|
$sp = SerialPort.new(ARGV[0], ARGV[1].to_i, ARGV[2].to_i, ARGV[3].to_i, SerialPort::NONE);
|
||||||
|
$sp.read_timeout=1*60*1000; # 5 minutes
|
||||||
|
$extended_wait=100;
|
||||||
|
$sp.write(command);
|
||||||
|
|
||||||
if(readTestVector(param)==false)
|
if(readTestVector(param)==false)
|
||||||
puts("ERROR: test seems not to be implemented");
|
puts("ERROR: test seems not to be implemented");
|
||||||
exit(3);
|
exit(3);
|
||||||
|
|
4
sha1.c
4
sha1.c
|
@ -170,13 +170,13 @@ void sha1_lastBlock(sha1_ctx_t *state, void* block, uint16_t length){
|
||||||
memcpy (&(lb[0]), block, length/8);
|
memcpy (&(lb[0]), block, length/8);
|
||||||
|
|
||||||
/* set the final one bit */
|
/* set the final one bit */
|
||||||
if (length & 0x3){ /* if we have single bits at the end */
|
if (length & 0x7){ /* if we have single bits at the end */
|
||||||
lb[length/8] = ((uint8_t*)(block))[length/8];
|
lb[length/8] = ((uint8_t*)(block))[length/8];
|
||||||
} else {
|
} else {
|
||||||
lb[length/8] = 0;
|
lb[length/8] = 0;
|
||||||
}
|
}
|
||||||
lb[length/8] |= 0x80>>(length & 0x3);
|
lb[length/8] |= 0x80>>(length & 0x3);
|
||||||
length =(length >> 3) + 1; /* from now on length contains the number of BYTES in lb*/
|
length =(length >> 7) + 1; /* from now on length contains the number of BYTES in lb*/
|
||||||
/* pad with zeros */
|
/* pad with zeros */
|
||||||
if (length>64-8){ /* not enouth space for 64bit length value */
|
if (length>64-8){ /* not enouth space for 64bit length value */
|
||||||
memset((void*)(&(lb[length])), 0, 64-length);
|
memset((void*)(&(lb[length])), 0, 64-length);
|
||||||
|
|
4
sha256.c
4
sha256.c
|
@ -164,12 +164,12 @@ void sha256_lastBlock(sha256_ctx_t *state, const void* block, uint16_t length){
|
||||||
memcpy (&(lb[0]), block, length/8);
|
memcpy (&(lb[0]), block, length/8);
|
||||||
|
|
||||||
/* set the final one bit */
|
/* set the final one bit */
|
||||||
if (length & 0x3){ // if we have single bits at the end
|
if (length & 0x7){ // if we have single bits at the end
|
||||||
lb[length/8] = ((uint8_t*)(block))[length/8];
|
lb[length/8] = ((uint8_t*)(block))[length/8];
|
||||||
} else {
|
} else {
|
||||||
lb[length/8] = 0;
|
lb[length/8] = 0;
|
||||||
}
|
}
|
||||||
lb[length/8] |= 0x80>>(length & 0x3);
|
lb[length/8] |= 0x80>>(length & 0x7);
|
||||||
length =(length >> 3) + 1; /* from now on length contains the number of BYTES in lb*/
|
length =(length >> 3) + 1; /* from now on length contains the number of BYTES in lb*/
|
||||||
/* pad with zeros */
|
/* pad with zeros */
|
||||||
if (length>64-8){ /* not enouth space for 64bit length value */
|
if (length>64-8){ /* not enouth space for 64bit length value */
|
||||||
|
|
|
@ -34,66 +34,6 @@
|
||||||
#include "cli.h"
|
#include "cli.h"
|
||||||
#include "config.h"
|
#include "config.h"
|
||||||
|
|
||||||
int16_t findstring_d0(const char* str, const char* v){
|
|
||||||
uint8_t i=0;
|
|
||||||
while(*v){
|
|
||||||
if(!strcmp(str, v)){
|
|
||||||
return i;
|
|
||||||
}
|
|
||||||
while(*v++) /* go to the next string */
|
|
||||||
;
|
|
||||||
++i;
|
|
||||||
}
|
|
||||||
return -1;
|
|
||||||
}
|
|
||||||
|
|
||||||
#ifdef CLI_OLD
|
|
||||||
|
|
||||||
int16_t findstring_d0_P(const char* str, PGM_P v){
|
|
||||||
uint8_t i=0;
|
|
||||||
while(pgm_read_byte(v)){
|
|
||||||
if(!strcmp_P(str, v)){
|
|
||||||
return i;
|
|
||||||
}
|
|
||||||
while(pgm_read_byte(v++)) /* go to the next string */
|
|
||||||
;
|
|
||||||
++i;
|
|
||||||
}
|
|
||||||
return -1;
|
|
||||||
}
|
|
||||||
|
|
||||||
#ifdef CLI_AUTO_HELP
|
|
||||||
#include "uart.h"
|
|
||||||
|
|
||||||
void cli_auto_help_P(PGM_P dbzstr){
|
|
||||||
char c;
|
|
||||||
uart_putstr_P(PSTR("\r\n[auto help] available commands are:\r\n\t"));
|
|
||||||
do{
|
|
||||||
while((c=pgm_read_byte(dbzstr++))!=0){
|
|
||||||
uart_putc(c);
|
|
||||||
}
|
|
||||||
uart_putstr_P(PSTR("\r\n\t"));
|
|
||||||
}while((c=pgm_read_byte(dbzstr))!=0);
|
|
||||||
uart_putstr_P(PSTR("\r\n"));
|
|
||||||
}
|
|
||||||
|
|
||||||
int16_t execcommand_d0_P(const char* str, PGM_P v, void(*fpt[])(void) ){
|
|
||||||
int16_t i=0;
|
|
||||||
i=findstring_d0_P(str, v);
|
|
||||||
if(i!=-1){
|
|
||||||
if(fpt[i])
|
|
||||||
fpt[i]();
|
|
||||||
return i;
|
|
||||||
}else{
|
|
||||||
cli_auto_help_P(v);
|
|
||||||
return -1;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
#endif
|
|
||||||
|
|
||||||
#else /* CLI_OLD */
|
|
||||||
|
|
||||||
cli_rx_fpt cli_rx = NULL;
|
cli_rx_fpt cli_rx = NULL;
|
||||||
cli_tx_fpt cli_tx = NULL;
|
cli_tx_fpt cli_tx = NULL;
|
||||||
uint8_t cli_echo=1;
|
uint8_t cli_echo=1;
|
||||||
|
@ -131,6 +71,7 @@ void cli_hexdump(void* data, uint16_t length){
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
static
|
||||||
void cli_auto_help(uint16_t maxcmdlength, PGM_VOID_P cmdlist){
|
void cli_auto_help(uint16_t maxcmdlength, PGM_VOID_P cmdlist){
|
||||||
cmdlist_entry_t item;
|
cmdlist_entry_t item;
|
||||||
uint16_t i;
|
uint16_t i;
|
||||||
|
@ -168,6 +109,7 @@ void cli_auto_help(uint16_t maxcmdlength, PGM_VOID_P cmdlist){
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
static
|
||||||
uint16_t firstword_length(char* s){
|
uint16_t firstword_length(char* s){
|
||||||
uint16_t ret=0;
|
uint16_t ret=0;
|
||||||
while(isalnum(*s++))
|
while(isalnum(*s++))
|
||||||
|
@ -383,6 +325,3 @@ int8_t cmd_interface(PGM_VOID_P cmd_desc){
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
#endif
|
|
||||||
|
|
||||||
|
|
|
@ -23,16 +23,6 @@
|
||||||
#include <avr/pgmspace.h>
|
#include <avr/pgmspace.h>
|
||||||
|
|
||||||
typedef void(*void_fpt)(void);
|
typedef void(*void_fpt)(void);
|
||||||
|
|
||||||
#ifdef CLI_OLD
|
|
||||||
|
|
||||||
int16_t findstring_d0(const char* str, const char* v);
|
|
||||||
int16_t findstring_d0_P(const char* str, PGM_P v);
|
|
||||||
|
|
||||||
int16_t execcommand_d0_P(const char* str, PGM_P v, void(*fpt[])(void) );
|
|
||||||
|
|
||||||
#else
|
|
||||||
|
|
||||||
typedef char (*cli_rx_fpt)(void);
|
typedef char (*cli_rx_fpt)(void);
|
||||||
typedef void (*cli_tx_fpt)(char);
|
typedef void (*cli_tx_fpt)(char);
|
||||||
|
|
||||||
|
@ -48,11 +38,11 @@ extern cli_rx_fpt cli_rx;
|
||||||
extern cli_tx_fpt cli_tx;
|
extern cli_tx_fpt cli_tx;
|
||||||
extern uint8_t cli_echo;
|
extern uint8_t cli_echo;
|
||||||
|
|
||||||
|
void cli_putstr(char* s);
|
||||||
|
void cli_putstr_P(PGM_P s);
|
||||||
|
void cli_hexdump(void* data, uint16_t length);
|
||||||
void echo_ctrl(char* s);
|
void echo_ctrl(char* s);
|
||||||
int8_t cmd_interface(PGM_VOID_P cmd_desc);
|
int8_t cmd_interface(PGM_VOID_P cmd_desc);
|
||||||
|
|
||||||
#endif
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
#endif /*CLI_H_*/
|
#endif /*CLI_H_*/
|
||||||
|
|
Loading…
Reference in New Issue