some style adjustments

This commit is contained in:
bg 2013-09-20 02:10:15 +02:00
parent b3cf9d2f35
commit 6e767be64b
3 changed files with 44 additions and 52 deletions

View File

@ -80,7 +80,7 @@ endef
define TargetSourceList_Template define TargetSourceList_Template
$(1): $(2) $(1): $(2)
@mkdir -p $(dir $(1)) $(DEP_DIR) @mkdir -p $(dir $(1)) $(DEP_DIR)
@echo "[cc]: $(1) <-- $(2)" @echo "[lst]: $(1) <-- $(2)"
@$(CC) $(CFLAGS_A) $(addprefix -I./,$(3)) $(addprefix -D, $(4)) $(LIST_OPT) -c -o /dev/null $(2) > $(1) @$(CC) $(CFLAGS_A) $(addprefix -I./,$(3)) $(addprefix -D, $(4)) $(LIST_OPT) -c -o /dev/null $(2) > $(1)
endef endef

View File

@ -119,7 +119,7 @@ arcfour_gen:
st Z+, r19 /* i,j loaded&saved; X->S[i]; Z->S[0]; r20=S[i] */ st Z+, r19 /* i,j loaded&saved; X->S[i]; Z->S[0]; r20=S[i] */
add r30, r19 add r30, r19
adc r31, r1 adc r31, r1
ld r21, Z /* X->S[i]; Z->S[j]; r20=S[i]; r21=S[j]*/ ld r21, Z /* X->S[i]; Z->S[j]; r20=S[i]; r21=S[j] */
st Z, r20 st Z, r20
st X, r21 st X, r21
add r20, r21 add r20, r21

View File

@ -23,39 +23,31 @@
#include <stdlib.h> #include <stdlib.h>
#include <string.h> #include <string.h>
void bigint_print_hex(const bigint_t *a){ void bigint_print_hex(const bigint_t *a) {
if(a->length_W==0){ if (a->length_W == 0) {
cli_putc('0'); cli_putc('0');
return; return;
} }
if(a->info&BIGINT_NEG_MASK){ if (a->info&BIGINT_NEG_MASK) {
cli_putc('-'); cli_putc('-');
} }
// cli_putc((a->info&BIGINT_NEG_MASK)?'-':'+'); /* print sign */ size_t idx;
/* if(a->wordv[a->length_W-1]<0x10){ uint8_t print_zero = 0;
cli_putc(hexdigit_tab_uc[a->wordv[a->length_W-1]]); uint8_t *p, x, y;
cli_hexdump_rev(a->wordv, a->length_W-1); p = (uint8_t*)&(a->wordv[a->length_W - 1]) + sizeof(bigint_word_t) - 1;
} else { for (idx = a->length_W * sizeof(bigint_word_t); idx > 0; --idx) {
*/
// cli_hexdump_rev(a->wordv, a->length_W*sizeof(bigint_word_t));
// }
uint32_t idx;
uint8_t print_zero=0;
uint8_t *p,x,y;
p = (uint8_t*)&(a->wordv[a->length_W-1])+sizeof(bigint_word_t)-1;
for(idx = a->length_W * sizeof(bigint_word_t); idx > 0; --idx){
x = *p >> 4; x = *p >> 4;
y = *p & 0xf; y = *p & 0xf;
if(x!=0 || print_zero!=0){ if (x != 0 || print_zero != 0) {
cli_putc(pgm_read_byte(&hexdigit_tab_lc_P[x])); cli_putc(pgm_read_byte(&hexdigit_tab_lc_P[x]));
} }
if(x){ if (x) {
print_zero = 1; print_zero = 1;
} }
if(y!=0 || print_zero!=0){ if (y != 0 || print_zero != 0) {
cli_putc(pgm_read_byte(&hexdigit_tab_lc_P[y])); cli_putc(pgm_read_byte(&hexdigit_tab_lc_P[y]));
} }
if(y){ if (y) {
print_zero = 1; print_zero = 1;
} }
--p; --p;
@ -64,75 +56,75 @@ void bigint_print_hex(const bigint_t *a){
#define BLOCKSIZE 32 #define BLOCKSIZE 32
static uint8_t char2nibble(char c){ static uint8_t char2nibble(char c) {
if(c>='0' && c <='9'){ if (c >= '0' && c <= '9') {
return c-'0'; return c - '0';
} }
c |= 'A'^'a'; /* to lower case */ c |= 'A' ^ 'a'; /* to lower case */
if(c>='a' && c <='f'){ if ( c>= 'a' && c <= 'f') {
return c-'a'+10; return c - 'a' + 10;
} }
return 0xff; return 0xff;
} }
static uint16_t read_byte(void){ static uint16_t read_byte(void) {
uint8_t t1, t2; uint8_t t1, t2;
char c; char c;
c = cli_getc_cecho(); c = cli_getc_cecho();
if(c=='-'){ if (c == '-') {
return 0x0500; return 0x0500;
} }
t1 = char2nibble(c); t1 = char2nibble(c);
if(t1 == 0xff){ if (t1 == 0xff) {
return 0x0100; return 0x0100;
} }
c = cli_getc_cecho(); c = cli_getc_cecho();
t2 = char2nibble(c); t2 = char2nibble(c);
if(t2 == 0xff){ if (t2 == 0xff) {
return 0x0200|t1; return 0x0200|t1;
} }
return (t1<<4)|t2; return (t1 << 4)|t2;
} }
uint8_t bigint_read_hex_echo(bigint_t *a){ uint8_t bigint_read_hex_echo(bigint_t *a) {
uint16_t allocated=0; uint16_t allocated = 0;
uint8_t shift4=0; uint8_t shift4 = 0;
uint16_t t, idx = 0; uint16_t t, idx = 0;
a->length_W = 0; a->length_W = 0;
a->wordv = NULL; a->wordv = NULL;
a->info = 0; a->info = 0;
for(;;){ for (;;) {
if(allocated - idx < 1){ if (allocated - idx < 1) {
bigint_word_t *p; bigint_word_t *p;
p = realloc(a->wordv, allocated += BLOCKSIZE); p = realloc(a->wordv, allocated += BLOCKSIZE);
if(p==NULL){ if (p == NULL) {
cli_putstr("\r\nERROR: Out of memory!"); cli_putstr("\r\nERROR: Out of memory!");
free(a->wordv); free(a->wordv);
return 0xff; return 0xff;
} }
memset((uint8_t*)p + allocated - BLOCKSIZE, 0, BLOCKSIZE); memset((uint8_t*)p + allocated - BLOCKSIZE, 0, BLOCKSIZE);
a->wordv=p; a->wordv = p;
} }
t = read_byte(); t = read_byte();
if(idx==0){ if (idx == 0) {
if(t&0x0400){ if (t & 0x0400) {
/* got minus */ /* got minus */
a->info |= BIGINT_NEG_MASK; a->info |= BIGINT_NEG_MASK;
continue; continue;
}else{ } else {
if(t==0x0100){ if (t == 0x0100) {
free(a->wordv); free(a->wordv);
a->wordv=NULL; a->wordv = NULL;
return 1; return 1;
} }
} }
} }
if(t<=0x00ff){ if (t <= 0x00ff) {
((uint8_t*)(a->wordv))[idx++] = (uint8_t)t; ((uint8_t*)(a->wordv))[idx++] = (uint8_t)t;
}else{ } else {
if(t&0x0200){ if (t & 0x0200) {
shift4 = 1; shift4 = 1;
((uint8_t*)(a->wordv))[idx++] = (uint8_t)((t&0x0f)<<4); ((uint8_t*)(a->wordv))[idx++] = (uint8_t)((t & 0x0f) << 4);
} }
break; break;
} }
@ -140,17 +132,17 @@ uint8_t bigint_read_hex_echo(bigint_t *a){
/* we have to reverse the byte array */ /* we have to reverse the byte array */
uint8_t tmp; uint8_t tmp;
uint8_t *p, *q; uint8_t *p, *q;
a->length_W = (idx + sizeof(bigint_word_t)-1)/sizeof(bigint_word_t); a->length_W = (idx + sizeof(bigint_word_t) - 1) / sizeof(bigint_word_t);
p = (uint8_t*)(a->wordv); p = (uint8_t*)(a->wordv);
q = (uint8_t*)a->wordv + a->length_W * sizeof(bigint_word_t) - 1; q = (uint8_t*)a->wordv + a->length_W * sizeof(bigint_word_t) - 1;
while(q>p){ while (q > p) {
tmp = *p; tmp = *p;
*p = *q; *p = *q;
*q = tmp; *q = tmp;
p++; q--; p++; q--;
} }
bigint_adjust(a); bigint_adjust(a);
if(shift4){ if (shift4) {
bigint_shiftright(a, 4); bigint_shiftright(a, 4);
} }
if(a->length_W == 1 && a->wordv[0] == 0){ if(a->length_W == 1 && a->wordv[0] == 0){