EXTRALINK = xram.o
DEFS = -D$(call uc, $(MCU_TARGET)) -DF_CPU=$(F_CPU)
BOARD_NAME = ethernut2.1
+FLASHCMD = /bin/bash openocd_flash.sh #
+RESETCMD =
override CFLAGS_A = -MMD -MF$(DEP_DIR)$(patsubst %.o,%.d,$(notdir $(1))) $(DEBUG) $(WARNING) -std=$(CSTD) $(OPTIMIZE) -mmcu=$(MCU_TARGET) $(DEFS)
override CFLAGS = -MMD -MF$(DEP_DIR)$(patsubst %.o,%.d,$(notdir $@)) $(DEBUG) $(WARNING) -std=$(CSTD) $(OPTIMIZE) -mmcu=$(MCU_TARGET) $(DEFS)
#define SET_NEG(a) (a)->info |= BIGINT_NEG_MASK
#define SET_POS(a) (a)->info &= ~BIGINT_NEG_MASK
#define XCHG(a,b) do{(a)^=(b); (b)^=(a); (a)^=(b);}while(0)
-#define XCHG_PTR(a,b) do{ a = (void*)(((bigint_ptr_int_t)(a)) ^ ((bigint_ptr_int_t)(b))); \
- b = (void*)(((bigint_ptr_int_t)(a)) ^ ((bigint_ptr_int_t)(b))); \
- a = (void*)(((bigint_ptr_int_t)(a)) ^ ((bigint_ptr_int_t)(b)));}while(0)
+#define XCHG_PTR(a,b) do{ a = (void*)(((intptr_t)(a)) ^ ((intptr_t)(b))); \
+ b = (void*)(((intptr_t)(a)) ^ ((intptr_t)(b))); \
+ a = (void*)(((intptr_t)(a)) ^ ((intptr_t)(b)));}while(0)
#define GET_SIGN(a) ((a)->info&BIGINT_NEG_MASK)
/******************************************************************************/
-uint16_t bigint_length_b(bigint_t* a){
+uint16_t bigint_length_b(const bigint_t* a){
if(!a->length_B || a->length_B==0){
return 0;
}
/******************************************************************************/
-uint16_t bigint_length_B(bigint_t* a){
+uint16_t bigint_length_B(const bigint_t* a){
return a->length_B * sizeof(bigint_word_t);
}
/******************************************************************************/
-uint32_t bigint_get_first_set_bit(bigint_t* a){
+uint32_t bigint_get_first_set_bit(const bigint_t* a){
if(a->length_B==0){
return (uint32_t)(-1);
}
/******************************************************************************/
-uint32_t bigint_get_last_set_bit(bigint_t* a){
+uint32_t bigint_get_last_set_bit(const bigint_t* a){
uint32_t r=0;
uint8_t b=0;
bigint_word_t x=1;
/* this should be implemented in assembly */
void bigint_add_u(bigint_t* dest, const bigint_t* a, const bigint_t* b){
uint16_t i;
- bigint_wordplus_t t=0LL;
+ bigint_wordplus_t t = 0LL;
if(a->length_B < b->length_B){
XCHG_PTR(a,b);
}
- for(i=0; i<b->length_B; ++i){
-// t = (bigint_wordplus_t)(a->wordv[i]) + (bigint_wordplus_t)(b->wordv[i]) + t;
+ for(i = 0; i < b->length_B; ++i){
t += a->wordv[i];
t += b->wordv[i];
dest->wordv[i] = (bigint_word_t)t;
- t>>=BIGINT_WORD_SIZE;
+ t >>= BIGINT_WORD_SIZE;
}
- for(; i<a->length_B; ++i){
+ for(; i < a->length_B; ++i){
t += a->wordv[i];
dest->wordv[i] = (bigint_word_t)t;
- t>>=BIGINT_WORD_SIZE;
+ t >>= BIGINT_WORD_SIZE;
+ }
+ if(t){
+ dest->wordv[i++] = (bigint_word_t)t;
}
- dest->wordv[i++] = (bigint_word_t)t;
dest->length_B = i;
bigint_adjust(dest);
}
/* this should be implemented in assembly */
void bigint_add_scale_u(bigint_t* dest, const bigint_t* a, uint16_t scale){
- bigint_t x;
+ if(a->length_B == 0){
+ return;
+ }
+ if(scale == 0){
+ bigint_add_u(dest, dest, a);
+ return;
+ }
+#if DEBUG_ADD_SCALE
+ cli_putstr_P(PSTR("\r\nDBG: bigint_add_scale("));
+ bigint_print_hex(dest);
+ cli_putc(',');
+ bigint_print_hex(dest);
+ cli_putc(',');
+ cli_hexdump_rev(&scale, 2);
+ cli_putc(')');
+#endif
#if BIGINT_WORD_SIZE == 8
- memset(dest->wordv + dest->length_B, 0, MAX(dest->length_B, a->length_B + scale) - dest->length_B);
- x.wordv = dest->wordv + scale;
+ if(scale >= dest->length_B){
+#if DEBUG_ADD_SCALE
+ cli_putstr_P(PSTR("\r\n\tpath one"));
+#endif
+ memset(dest->wordv + dest->length_B, 0, scale - dest->length_B);
+ memcpy(dest->wordv + scale, a->wordv, a->length_B);
+ dest->info = a->info;
+ dest->length_B = a->length_B + scale;
+ return;
+ }
+ bigint_t x;
+#if DEBUG_ADD_SCALE
+ cli_putstr_P(PSTR("\r\n\tpath two"));
+#endif
x.length_B = dest->length_B - scale;
- if((int16_t)x.length_B < 0)
- x.length_B = 0;
x.info = dest->info;
+ x.wordv = dest->wordv + scale;
bigint_add_u(&x, &x, a);
dest->length_B = x.length_B + scale;
dest->info = 0;
bigint_adjust(dest);
#else
-#error unimplemented!
+ bigint_t s;
+ uint16_t word_shift = scale / sizeof(bigint_word_t), byte_shift = scale % sizeof(bigint_word_t);
+ bigint_word_t bv[a->length_B + 1];
+ s.wordv = bv;
+ bv[0] = bv[a->length_B] = 0;
+ memcpy((uint8_t*)bv + byte_shift, a->wordv, a->length_B * sizeof(bigint_word_t));
+ s.length_B = a->length_B + 1;
+ bigint_adjust(&s);
+ memset(dest->wordv + dest->length_B, 0, (MAX(dest->length_B, s.length_B + word_shift) - dest->length_B) * sizeof(bigint_word_t));
+ x.wordv = dest->wordv + word_shift;
+ x.length_B = dest->length_B - word_shift;
+ if((int16_t)x.length_B < 0){
+ x.length_B = 0;
+ x.info = 0;
+ }else{
+ x.info = dest->info;
+ }
+ bigint_add_u(&x, &x, &s);
+ dest->length_B = x.length_B + word_shift;
+ dest->info = 0;
+ bigint_adjust(dest);
#endif
int8_t borrow=0;
int8_t r;
bigint_wordplus_signed_t t=0LL;
- uint16_t i, min, max;
- min = MIN(a->length_B, b->length_B);
- max = MAX(a->length_B, b->length_B);
+ uint16_t i;
r = bigint_cmp_u(a,b);
if(r==0){
bigint_set_zero(dest);
SET_NEG(dest);
return;
}
- for(i=0; i<max; ++i){
+ for(i=0; i < a->length_B; ++i){
t = a->wordv[i];
- if(i<min){
+ if(i < b->length_B){
t -= b->wordv[i];
}
t -= borrow;
void bigint_add_s(bigint_t* dest, const bigint_t* a, const bigint_t* b){
uint8_t s;
- int8_t d = 0;
s = GET_SIGN(a)?2:0;
s |= GET_SIGN(b)?1:0;
switch(s){
case 0: /* both positive */
- d = 1;
bigint_add_u(dest, a,b);
+ SET_POS(dest);
break;
case 1: /* a positive, b negative */
- d = bigint_cmp_u(a,b);
bigint_sub_u(dest, a, b);
break;
case 2: /* a negative, b positive */
- d = bigint_cmp_u(b,a);
bigint_sub_u(dest, b, a);
break;
case 3: /* both negative */
- d = -1;
bigint_add_u(dest, a, b);
+ SET_NEG(dest);
break;
default: /* how can this happen?*/
break;
}
- if(d<0){
- SET_NEG(dest);
- }else{
- SET_POS(dest);
- }
}
/******************************************************************************/
/******************************************************************************/
void bigint_shiftleft(bigint_t* a, uint16_t shift){
- uint16_t byteshift, word_alloc;
+ uint16_t byteshift, words_to_shift;
int16_t i;
uint8_t bitshift;
bigint_word_t *p;
bigint_wordplus_t t=0;
- if(shift==0){
+ if(shift == 0){
return;
}
- byteshift = shift/8;
- bitshift = shift&7;
- for(i=0;i<=byteshift/sizeof(bigint_word_t); ++i){
- a->wordv[a->length_B+i] = 0;
- }
+ byteshift = shift / 8;
+ bitshift = shift & 7;
+ memset(&a->wordv[a->length_B], 0x00, byteshift);
if(byteshift){
- memmove(((uint8_t*)a->wordv)+byteshift, a->wordv, a->length_B*sizeof(bigint_word_t));
+ memmove(((uint8_t*)a->wordv)+byteshift, a->wordv, a->length_B * sizeof(bigint_word_t));
memset(a->wordv, 0, byteshift);
}
- p = (bigint_word_t*)(((uint8_t*)a->wordv)+byteshift);
- word_alloc = a->length_B+(byteshift+sizeof(bigint_word_t)-1)/sizeof(bigint_word_t)+1;
- a->wordv[word_alloc-1]=0;
- if(bitshift!=0){
- for(i=0; i<a->length_B; ++i){
- t |= ((bigint_wordplus_t)p[i])<<bitshift;
+ if(bitshift != 0){
+ p = (bigint_word_t*)((uint8_t*)a->wordv + byteshift / sizeof(bigint_word_t));
+ words_to_shift = a->length_B + ((byteshift % sizeof(bigint_word_t))?1:0);
+ /* XXX */
+ for(i = 0; i < words_to_shift; ++i){
+ t |= ((bigint_wordplus_t)p[i]) << bitshift;
p[i] = (bigint_word_t)t;
t >>= BIGINT_WORD_SIZE;
}
p[i] = (bigint_word_t)t;
}
- a->length_B = word_alloc;
+ a->length_B += (shift + BIGINT_WORD_SIZE - 1) / BIGINT_WORD_SIZE;
bigint_adjust(a);
}
bigint_wordplus_t t=0;
byteshift = shift/8;
bitshift = shift&7;
- if(byteshift >= a->length_B*sizeof(bigint_word_t)){ /* we would shift out more than we have */
+ if(byteshift >= a->length_B * sizeof(bigint_word_t)){ /* we would shift out more than we have */
bigint_set_zero(a);
return;
}
- if(byteshift == a->length_B*sizeof(bigint_word_t)-1 && bitshift>GET_FBS(a)){
+ if(byteshift == a->length_B * sizeof(bigint_word_t) - 1 && bitshift > GET_FBS(a)){
bigint_set_zero(a);
return;
}
if(byteshift){
- memmove(a->wordv, (uint8_t*)a->wordv+byteshift, a->length_B-byteshift);
- memset((uint8_t*)a->wordv+a->length_B-byteshift, 0, byteshift);
+ memmove(a->wordv, (uint8_t*)a->wordv + byteshift, a->length_B * sizeof(bigint_word_t) - byteshift);
+ memset((uint8_t*)a->wordv + a->length_B * sizeof(bigint_word_t) - byteshift, 0, byteshift);
}
byteshift /= sizeof(bigint_word_t);
- if(bitshift!=0){
+ a->length_B -= (byteshift + sizeof(bigint_word_t) - 1) / sizeof(bigint_word_t);
+ if(bitshift != 0 && a->length_B){
/* shift to the right */
- for(i=a->length_B-byteshift-1; i>0; --i){
- t |= ((bigint_wordplus_t)(a->wordv[i]))<<(BIGINT_WORD_SIZE-bitshift);
- a->wordv[i] = (bigint_word_t)(t>>BIGINT_WORD_SIZE);
+ i = a->length_B - 1;
+ do{
+ t |= ((bigint_wordplus_t)(a->wordv[i])) << (BIGINT_WORD_SIZE - bitshift);
+ a->wordv[i] = (bigint_word_t)(t >> BIGINT_WORD_SIZE);
t <<= BIGINT_WORD_SIZE;
- }
- t |= ((bigint_wordplus_t)(a->wordv[0]))<<(BIGINT_WORD_SIZE-bitshift);
- a->wordv[0] = (bigint_word_t)(t>>BIGINT_WORD_SIZE);
+ }while(i--);
}
- a->length_B -= ((shift/8)+sizeof(bigint_word_t)-1)/sizeof(bigint_word_t);
bigint_adjust(a);
}
}
if(dest==a || dest==b){
bigint_t d;
- bigint_word_t d_b[a->length_B+b->length_B];
+ bigint_word_t d_b[a->length_B + b->length_B];
d.wordv = d_b;
bigint_mul_u(&d, a, b);
bigint_copy(dest, &d);
return;
}
if(a->length_B==1 || b->length_B==1){
- if(a->length_B!=1){
+ if(a->length_B != 1){
XCHG_PTR(a,b);
}
bigint_wordplus_t t=0;
uint16_t i;
bigint_word_t x = a->wordv[0];
for(i=0; i < b->length_B; ++i){
- t += ((bigint_wordplus_t)b->wordv[i])*((bigint_wordplus_t)x);
+ t += ((bigint_wordplus_t)b->wordv[i]) * ((bigint_wordplus_t)x);
dest->wordv[i] = (bigint_word_t)t;
t>>=BIGINT_WORD_SIZE;
}
bigint_adjust(dest);
return;
}
- bigint_set_zero(dest);
+#if BIGINT_WORD_SIZE == 8
+ if(a->length_B <= 4 || b->length_B <= 4){
+ if(a->length_B > 4){
+ XCHG_PTR(a,b);
+ }
+ uint32_t x = 0, y = 0;
+ uint16_t j = b->length_B / 4, idx = 0;
+ uint64_t r = 0;
+ memcpy(&x, a->wordv, a->length_B);
+ while(j){
+ r += (uint64_t)((uint32_t*)b->wordv)[idx] * (uint64_t)x;
+ ((uint32_t*)dest->wordv)[idx] = (uint32_t)r;
+ r >>= 32;
+ ++idx;
+ --j;
+ }
+ idx *= 4;
+ memcpy(&y, b->wordv + idx, b->length_B - idx);
+ r += (uint64_t)y * (uint64_t)x;
+ while(r){
+ dest->wordv[idx++] = (uint8_t)r;
+ r >>= 8;
+ }
+ dest->length_B = idx;
+ bigint_adjust(dest);
+ return;
+ }
+#endif
/* split a in xh & xl; split b in yh & yl */
const uint16_t n = (MAX(a->length_B, b->length_B)+1)/2;
bigint_t xl, xh, yl, yh;
xl.wordv = a->wordv;
yl.wordv = b->wordv;
- if(a->length_B<=n){
+ if(a->length_B <= n){
bigint_set_zero(&xh);
xl.length_B = a->length_B;
xl.info = a->info;
}else{
- xl.length_B=n;
+ xl.length_B = n;
xl.info = 0;
bigint_adjust(&xl);
xh.wordv = &(a->wordv[n]);
xh.length_B = a->length_B-n;
xh.info = a->info;
}
- if(b->length_B<=n){
+ if(b->length_B <= n){
bigint_set_zero(&yh);
yl.length_B = b->length_B;
yl.info = b->info;
}else{
- yl.length_B=n;
+ yl.length_B = n;
yl.info = 0;
bigint_adjust(&yl);
yh.wordv = &(b->wordv[n]);
}
/* now we have split up a and b */
/* remember we want to do:
- * x*y = (xh*yh)*b**2n + ((xh+xl)*(yh+yl) - xh*yh - xl*yl)*b**n + yh*yl
+ * x*y = (xh * b ** n + xl) * (yh * b ** n + yl)
+ * x*y = (xh*yh)*b**2n + ((xh+xl)*(yh+yl) - xh*yh - xl*yl)*b**n + xl*yl
* 5 9 2 4 3 7 5 6 1 8 1
*/
- bigint_word_t tmp_b[2*n+2], m_b[2*(n+1)];
- bigint_t tmp, tmp2, m;
- tmp.wordv = tmp_b;
- tmp2.wordv = &(tmp_b[n+1]);
- m.wordv = m_b;
-
- bigint_mul_u(dest, &xl, &yl); /* 1: dest <= xl*yl */
- bigint_add_u(&tmp2, &xh, &xl); /* 2: tmp2 <= xh+xl */
- bigint_add_u(&tmp, &yh, &yl); /* 3: tmp <= yh+yl */
- bigint_mul_u(&m, &tmp2, &tmp); /* 4: m <= tmp2*tmp */
- bigint_mul_u(&tmp, &xh, &yh); /* 5: h <= xh*yh */
- bigint_sub_u(&m, &m, dest); /* 6: m <= m-dest */
- bigint_sub_u(&m, &m, &tmp); /* 7: m <= m-h */
- bigint_add_scale_u(dest, &m, n*sizeof(bigint_word_t)); /* 8: dest <= dest+m**n*/
- bigint_add_scale_u(dest, &tmp, 2*n*sizeof(bigint_word_t)); /* 9: dest <= dest+tmp**(2*n) */
+ bigint_word_t tmp1_b[n*2+2];
+ bigint_t tmp1, tmp2;
+ tmp1.wordv = tmp1_b;
+ tmp2.wordv = &tmp1_b[n+1];
+
+ bigint_add_u(&tmp2, &xh, &xl); /* 2: tmp2 <= xh + xl */
+ bigint_add_u(&tmp1, &yh, &yl); /* 3: tmp1 <= yh + yl */
+ bigint_mul_u(dest, &tmp2, &tmp1); /* 4: dest <= tmp2 * tmp1 */
+ bigint_mul_u(&tmp1, &xh, &yh); /* 5: tmp1 <= xh * yh */
+ bigint_sub_u(dest, dest, &tmp1); /* 7: dest <= dest - tmp1 */
+ bigint_word_t tmp3_b[2*n];
+ tmp2.wordv = tmp3_b;
+ bigint_mul_u(&tmp2, &xl, &yl); /* 1: tmp3 <= xl * yl */
+ bigint_sub_u(dest, dest, &tmp2); /* 6: dest <= dest - tmp3 */
+ bigint_shiftleft(dest, n * sizeof(bigint_word_t) * 8);
+ bigint_add_u(dest, dest, &tmp2); /* 8: dest <= tmp3 + dest ** n */
+ bigint_add_scale_u(dest, &tmp1, 2*n*sizeof(bigint_word_t)); /* 9: dest <= dest + tmp1 ** (2 * n) */
+
+#if 0
+ bigint_mul_u(dest, &xl, &yl); /* 1: dest <= xl * yl */
+ bigint_add_u(&tmp2, &xh, &xl); /* 2: tmp2 <= xh + xl */
+ bigint_add_u(&tmp1, &yh, &yl); /* 3: tmp1 <= yh + yl */
+ bigint_mul_u(&tmp3, &tmp2, &tmp1); /* 4: tmp3 <= tmp2 * tmp1 */
+ bigint_mul_u(&tmp1, &xh, &yh); /* 5: h <= xh * yh */
+ bigint_sub_u(&tmp3, &tmp3, dest); /* 6: tmp3 <= tmp3 - dest */
+ bigint_sub_u(&tmp3, &tmp3, &tmp1); /* 7: tmp3 <= tmp3 - h */
+ bigint_add_scale_u(dest, &tmp3, n*sizeof(bigint_word_t)); /* 8: dest <= dest + tmp3 ** n */
+ bigint_add_scale_u(dest, &tmp1, 2*n*sizeof(bigint_word_t)); /* 9: dest <= dest + tmp1 ** (2 * n) */
+#endif
}
/******************************************************************************/
/* square */
/* (xh*b^n+xl)^2 = xh^2*b^2n + 2*xh*xl*b^n + xl^2 */
void bigint_square(bigint_t* dest, const bigint_t* a){
- if(a->length_B*sizeof(bigint_word_t)<=4){
- uint64_t r=0;
- memcpy(&r, a->wordv, a->length_B*sizeof(bigint_word_t));
- r = r*r;
- memcpy(dest->wordv, &r, 2*a->length_B*sizeof(bigint_word_t));
+ if(a->length_B * sizeof(bigint_word_t) <= 4){
+ uint64_t r = 0;
+ memcpy(&r, a->wordv, a->length_B * sizeof(bigint_word_t));
+ r = r * r;
+ memcpy(dest->wordv, &r, 2 * a->length_B*sizeof(bigint_word_t));
SET_POS(dest);
- dest->length_B=2*a->length_B;
+ dest->length_B = 2 * a->length_B;
bigint_adjust(dest);
return;
}
if(dest==a){
bigint_t d;
- bigint_word_t d_b[a->length_B*2];
+ bigint_word_t d_b[a->length_B * 2];
d.wordv = d_b;
bigint_square(&d, a);
bigint_copy(dest, &d);
return;
}
uint16_t n;
- n=(a->length_B+1)/2;
+ n = (a->length_B + 1) / 2;
bigint_t xh, xl, tmp; /* x-high, x-low, temp */
- bigint_word_t buffer[2*n+1];
+ bigint_word_t buffer[2 * n + 1];
xl.wordv = a->wordv;
xl.length_B = n;
xl.info = 0;
xh.wordv = &(a->wordv[n]);
- xh.length_B = a->length_B-n;
- xh.info = 0;
+ xh.length_B = a->length_B - n;
+ xh.info = a->info;
bigint_adjust(&xl);
- bigint_adjust(&xh);
tmp.wordv = buffer;
/* (xh * b**n + xl)**2 = xh**2 * b**2n + 2 * xh * xl * b**n + xl**2 */
// cli_putstr("\r\nDBG (1): xl**2: "); bigint_print_hex(dest);
bigint_square(&tmp, &xh);
// cli_putstr("\r\nDBG (2): xh**2: "); bigint_print_hex(&tmp);
- bigint_add_scale_u(dest, &tmp, 2*n*sizeof(bigint_word_t));
+ bigint_add_scale_u(dest, &tmp, 2 * n * sizeof(bigint_word_t));
// cli_putstr("\r\nDBG (3): xl**2 + xh**2*n**2: "); bigint_print_hex(dest);
bigint_mul_u(&tmp, &xl, &xh);
// cli_putstr("\r\nDBG (4): xl*xh: "); bigint_print_hex(&tmp);
bigint_copy(&tmp, b);
bigint_shiftleft(&tmp, bitscale % BIGINT_WORD_SIZE);
+// cli_putstr_P(PSTR("\r\nDBG: shifted value: ")); bigint_print_hex(&tmp);
+
x.info = a->info;
x.wordv = &(a->wordv[word_shift]);
x.length_B = a->length_B - word_shift;
bigint_sub_u(&x, &x, &tmp);
+ a->length_B = x.length_B + word_shift;
bigint_adjust(a);
return;
}
}
while((GET_FBS(a) > rfbs) && (a->length_B == r->length_B)){
shift = GET_FBS(a)-rfbs-1;
+// cli_putstr("\r\nDBG: (2a) = "); bigint_print_hex(a);
// cli_putstr("\r\nDBG: (q) shift = "); cli_hexdump_rev(&shift, 2);
bigint_sub_u_bitscale(a, r, shift);
-// cli_putstr("\r\nDBG: (2) = "); bigint_print_hex(a);
+// cli_putstr("\r\nDBG: (2b) = "); bigint_print_hex(a);
}
while(bigint_cmp_u(a,r)>=0){
bigint_sub_u(a,a,r);
// cli_putstr("\r\nDBG: (3) = "); bigint_print_hex(a);
}
+// cli_putc(' ');
bigint_adjust(a);
// cli_putstr("\r\nDBG: (a) = "); bigint_print_hex(a);
// cli_putstr("\r\n");
void bigint_changeendianess(bigint_t* a){
uint8_t t, *p, *q;
p = (uint8_t*)(a->wordv);
- q = ((uint8_t*)p)+a->length_B*sizeof(bigint_word_t)-1;
+ q = p + a->length_B * sizeof(bigint_word_t) - 1;
while(p<q){
t = *p;
*p = *q;
typedef uint8_t bigint_word_t;
typedef uint16_t bigint_wordplus_t;
typedef int16_t bigint_wordplus_signed_t;
-typedef uint16_t bigint_ptr_int_t; /* this must be an integer of the size of a pointer for the target architecture */
#define BIGINT_WORD_SIZE 8
#define BIGINT_FBS_MASK (BIGINT_WORD_SIZE-1) /* the last five bits indicate which is the first bit set */
/******************************************************************************/
void bigint_adjust(bigint_t* a);
-uint32_t bigint_get_first_set_bit(bigint_t* a);
-uint32_t bigint_get_last_set_bit(bigint_t* a);
-uint16_t bigint_length_b(bigint_t* a);
-uint16_t bigint_length_B(bigint_t* a);
+uint32_t bigint_get_first_set_bit(const bigint_t* a);
+uint32_t bigint_get_last_set_bit(const bigint_t* a);
+uint16_t bigint_length_b(const bigint_t* a);
+uint16_t bigint_length_B(const bigint_t* a);
void bigint_copy(bigint_t* dest, const bigint_t* src);
void bigint_add_u(bigint_t* dest, const bigint_t* a, const bigint_t* b);
void bigint_add_scale_u(bigint_t* dest, const bigint_t* a, uint16_t scale);
}
void hmac_sha1_lastBlock(hmac_sha1_ctx_t *s, const void* block, uint16_t length_b){
while(length_b>=SHA1_BLOCK_BITS){
- sha1_nextBlock(&(s->a), block);
+ sha1_nextBlock(&s->a, block);
block = (uint8_t*)block + SHA1_BLOCK_BYTES;
length_b -= SHA1_BLOCK_BITS;
}
- sha1_lastBlock(&(s->a), block, length_b);
+ sha1_lastBlock(&s->a, block, length_b);
}
void hmac_sha1_final(void* dest, hmac_sha1_ctx_t *s){
- sha1_ctx2hash((sha1_hash_t*)dest, &(s->a));
- sha1_lastBlock(&(s->b), dest, SHA1_HASH_BITS);
- sha1_ctx2hash((sha1_hash_t*)dest, &(s->b));
+ sha1_ctx2hash(dest, &s->a);
+ sha1_lastBlock(&s->b, dest, SHA1_HASH_BITS);
+ sha1_ctx2hash(dest, &(s->b));
}
#endif
def expmod_test(a,b,c)
begin
+ printf("[testing] expmod(%#x, %#x, %#x)\n",a,b,c) if $debug
line = $sp.gets()
line = "" if line==nil
puts("DBG got: "+line) if $debug
end
$logfile = File.open(logfilename, 'w')
printf("logfile: %s\n", logfilename)
-
+$logfile.sync = true
$logfile.printf("bigint test from: %s\n", Time.now.to_s)
$logfile.printf("skip = %s\n", opts['s']) if opts['s']
$logfile.printf("seed = 0x%X\n", 0xdeadbeef)
require 'serialport'
$debug = false
+$progress_dots = false
def read_line(error_msg=true)
begin
puts("ERROR: read timeout!\n") if error_msg
return nil
end
- putc('.') if s.include?(6.chr)
+ putc('.') if s.include?(6.chr) && $progress_dots
puts(s.inspect) if $debug
end while s == 6.chr
s.gsub(/\006/, '')
$linewidth = 16
$sp = SerialPort.new(ARGV[0], ARGV[1].to_i, ARGV[2].to_i, ARGV[3].to_i, SerialPort::NONE);
$sp.read_timeout=1000; # 1 second
-$extended_wait=10;
+$extended_wait=100000;
$sp.write(command);
if(readTestVector(param)==false)
along with this program. If not, see <http://www.gnu.org/licenses/>.
=end
+$debug = true
+
def skip_header(file)
begin
l = file.gets().strip
end
if(a!=b and a!=nil and b!=nil)
$error += 1
-# puts("a key: "+a[0]+" value: "+a[1])
-# puts("b key: "+b[0]+" value: "+b[1])
+ puts("a key: "+a[0]+" value: "+a[1]) if $debug
+ puts("b key: "+b[0]+" value: "+b[1]) if $debug
end
end until a==nil or b==nil
end
#include "cli.h"
#endif
-void rsa_enc(bigint_t* data, rsa_publickey_t* key){
+void rsa_enc(bigint_t* data, const rsa_publickey_t* key){
/*
cli_putstr_P(PSTR("\r\n -->rsa_enc()\r\n m = "));
bigint_print_hex(data);
m = m2 + q * h
*/
-uint8_t rsa_dec_crt_mono(bigint_t* data, rsa_privatekey_t* key){
+uint8_t rsa_dec_crt_mono(bigint_t* data, const rsa_privatekey_t* key){
bigint_t m1, m2;
- m1.wordv = malloc((key->components[0].length_B + 1) * sizeof(bigint_word_t));
- m2.wordv = malloc((key->components[1].length_B + 1) * sizeof(bigint_word_t));
+ m1.wordv = malloc((key->components[0].length_B /* + 1 */) * sizeof(bigint_word_t));
+ m2.wordv = malloc((key->components[1].length_B /* + 1 */) * sizeof(bigint_word_t));
if(!m1.wordv || !m2.wordv){
#if DEBUG
cli_putstr_P(PSTR("\r\nERROR: OOM!"));
return 0;
}
-uint8_t rsa_dec(bigint_t* data, rsa_privatekey_t* key){
+uint8_t rsa_dec(bigint_t* data, const rsa_privatekey_t* key){
if(key->n == 1){
bigint_expmod_u(data, data, &(key->components[0]), &key->modulus);
return 0;
} rsa_fullkey_t;
-void rsa_enc(bigint_t* data, rsa_publickey_t* key);
-uint8_t rsa_dec(bigint_t* data, rsa_privatekey_t* key);
+void rsa_enc(bigint_t* data, const rsa_publickey_t* key);
+uint8_t rsa_dec(bigint_t* data, const rsa_privatekey_t* key);
void rsa_os2ip(bigint_t* dest, const void* data, uint32_t length_B);
void rsa_i2osp(void* dest, bigint_t* src, uint16_t* out_length_B);
/********************************************************************************************************/
-void sha1_ctx2hash (sha1_hash_t *dest, sha1_ctx_t *state){
+void sha1_ctx2hash (void *dest, sha1_ctx_t *state){
#if defined LITTLE_ENDIAN
uint8_t i;
for(i=0; i<5; ++i){
*
*
*/
-void sha1 (sha1_hash_t *dest, const void* msg, uint32_t length){
+void sha1 (void *dest, const void* msg, uint32_t length){
sha1_ctx_t s;
DEBUG_S("\r\nBLA BLUB");
sha1_init(&s);
* \brief hash value type
* A variable of this type may hold a SHA-1 hash value
*/
+/*
typedef uint8_t sha1_hash_t[SHA1_HASH_BITS/8];
+*/
/** \fn sha1_init(sha1_ctx_t *state)
* \brief initializes a SHA-1 context
* \param dest pointer to the hash value destination
* \param state pointer to the hash context
*/
-void sha1_ctx2hash (sha1_hash_t *dest, sha1_ctx_t *state);
+void sha1_ctx2hash (void *dest, sha1_ctx_t *state);
/** \fn sha1(sha1_hash_t *dest, const void* msg, uint32_t length_b)
* \brief hashing a message which in located entirely in RAM
* \param msg pointer to the message which should be hashed
* \param length_b length of the message in bits
*/
-void sha1(sha1_hash_t *dest, const void* msg, uint32_t length_b);
+void sha1(void *dest, const void* msg, uint32_t length_b);
memcpy(keybuffer, key, (keysize_b+7)/8);
memcpy(t_ctx.h, buffer, SHA1_HASH_BITS/8);
- sha1_ctx2hash((sha1_hash_t*)(&(ctx.h[0])), &t_ctx);
+ sha1_ctx2hash(&ctx.h[0], &t_ctx);
memcpy(t_ctx.h, ctx.h, SHA1_HASH_BITS/8);
sha1_nextBlock(&ctx, keybuffer);
for(i=0; i<5; ++i)
ldd r23, Z+BUFFER_SIZE_OFFSET
cp r22, r23
brne 10f
+5:
ldi r24, 1
ret
10:
ldd r22, Z+FILLCOUNT_OFFSET
ldd r23, Z+BUFFER_SIZE_OFFSET
cp r22, r23
- brne 10f
- ldi r24, 1
- ret
+ brlo 10f
+ rjmp 5b
+; ldi r24, 1
+; ret
10:
- clt
- tst r22
- brne 11f
- set
+; clt
+; tst r22
+; brne 11f
+; set
11:
inc r22
std Z+FILLCOUNT_OFFSET, r22
20:
std Z+HEAD_OFFSET, r26
std Z+HEAD_OFFSET+1, r27
- brtc 30b
- std Z+TAIL_OFFSET, r26
- std Z+TAIL_OFFSET+1, r27
+; brtc 30b
+; std Z+TAIL_OFFSET, r26
+; std Z+TAIL_OFFSET+1, r27
rjmp 30b
/**
* \file circularbytebuffer.h
* \email daniel.otte@rub.de
- * \author Daniel Otte
+ * \author Daniel Otte
* \date 2009-07-24
* \license GPLv3 or later
- * \ingroup circularbytebuffer
+ * \addtogroup circularbytebuffer
* \brief declaration for circular byte buffer
*/
-
+/*@{*/
#ifndef CIRCULARBYTEBUFFER_H_
#define CIRCULARBYTEBUFFER_H_
#include <stdint.h>
#include <stdlib.h>
#include "config.h"
-
+ /**
+ * \brief type holding the managment information for the buffer
+ *
+ * A variable of this type may hold all the information to control the buffer
+ */
typedef struct {
- uint8_t buffer_size;
- uint8_t fillcount;
- uint8_t* buffer;
- uint8_t* head;
- uint8_t* tail;
- uint8_t* top;
+ uint8_t buffer_size; /**< holds the amount of bytes which may be stored in the buffer */
+ uint8_t fillcount; /**< holds the amount of bytes actually stored in the buffer */
+ uint8_t* buffer; /**< pointer to the actual buffer */
+ uint8_t* head; /**< pointer to the head of the buffer */
+ uint8_t* tail; /**< pointer to the tail of the buffer */
+ uint8_t* top; /**< pointer to the last free address in the buffer */
} circularbytebuffer_t;
#if CIRCULARBYTEBUFFER_NO_MALLOC==0
+/** \brief buffer initialisation with automatic allocation
+ *
+ * This function initializes the given buffer context and allocates memory for
+ * it by calling malloc.
+ * \param buffersize size of the buffer to allocate
+ * \param cb buffer context to be initialized
+ */
uint8_t circularbytebuffer_init(uint8_t buffersize, circularbytebuffer_t* cb);
#endif
#if CIRCULARBYTEBUFFER_NO_INIT2==0
+/** \brief buffer initialisation without automatic allocation
+ *
+ * This function initializes the given buffer context and uses the given buffer
+ * for storage, so no malloc is needed.
+ * \param buffersize size of the buffer
+ * \param cb buffer context to be initialized
+ * \param buffer buffer for the storage of data (you are responisble for allocation and freeing)
+ */
void circularbytebuffer_init2(uint8_t buffersize, circularbytebuffer_t* cb, void* buffer);
#endif
+/** \brief
+ *
+ *
+ */
uint16_t circularbytebuffer_get_lifo(circularbytebuffer_t* cb);
uint16_t circularbytebuffer_get_fifo(circularbytebuffer_t* cb);
uint8_t circularbytebuffer_append(uint8_t, circularbytebuffer_t* cb);
uint8_t circularbytebuffer_cnt(circularbytebuffer_t* cb);
void circularbytebuffer_free(circularbytebuffer_t* cb);
+/*@}*/
#endif /* CIRCULARBYTEBUFFER_H_ */
.global cli_hexdump_block
cli_hexdump_block:
- tst r22
- brne 1f
- tst r23
- brne 1f
- ret
+ movw r26, r22
+ adiw r26, 0
+ breq simple_ret
1:
push WIDTH
push INDENT
movw DATA_0, r24
movw LENG_0, r22
2:
- clr r25
+; clr r25
ldi r24, '\r'
rcall cli_putc
- clr r25
+; clr r25
ldi r24, '\n'
rcall cli_putc
mov r4, INDENT
tst r4
breq 4f
-3: clr r25
+3:; clr r25
ldi r24, ' '
rcall cli_putc
dec r4
tst LENG_1
brne 7f
cp WIDTH, LENG_0
- breq 6f
- brcs 7f
+ brlo 7f
mov r22, LENG_0
6: inc r4
7:
pop DATA_0
pop INDENT
pop WIDTH
+simple_ret:
ret
* AES test-suit
*
*/
-
-#include "config.h"
-
-#include "uart_i.h"
-#include "debug.h"
-
+#include "main-test-common.h"
#include "aes.h"
-#include "cli.h"
#include "performance_test.h"
#include "dump.h"
#include "bcal-performance.h"
#include "bcal-nessie.h"
-#include <stdint.h>
-#include <string.h>
-#include <stdlib.h>
-#include <avr/pgmspace.h>
-
const char* algo_name = "AES";
const bcdesc_t* const const algolist[] PROGMEM = {
cmd_interface(cmdlist);
}
}
+int main(void) {
+ main_setup();
+
+ cmacvs_algolist=(bcdesc_t**)algolist;
+ cmacvs_algo=(bcdesc_t*)&aes128_desc;
+
+ for(;;){
+ welcome_msg(algo_name);
+ cmd_interface(cmdlist);
+ }
+
+}
*
*/
-#include "config.h"
-#include "uart_i.h"
-#include "debug.h"
+#include "main-test-common.h"
#include <arcfour.h>
-#include "cli.h"
#include "performance_test.h"
#include "scal_arcfour.h"
#include "scal-basic.h"
#include "scal-nessie.h"
-#include <stdlib.h>
-#include <stdint.h>
-#include <string.h>
-
char* algo_name = "Arcfour";
/*****************************************************************************
{ NULL, NULL, NULL}
};
-int main (void){
- DEBUG_INIT();
-
- cli_rx = (cli_rx_fpt)uart0_getc;
- cli_tx = (cli_tx_fpt)uart0_putc;
+int main(void) {
+ main_setup();
+
+ shavs_algolist=(hfdesc_t**)algolist;
+ shavs_algo=(hfdesc_t*)&sha256_desc;
+
for(;;){
- cli_putstr_P(PSTR("\r\n\r\nCrypto-VS ("));
- cli_putstr(algo_name);
- cli_putstr_P(PSTR(")\r\nloaded and running\r\n"));
+ welcome_msg(algo_name);
cmd_interface(cmdlist);
- }
+ }
+
}
+
*
*/
-#include "config.h"
-
-#include "uart_i.h"
-#include "debug.h"
+#include "main-test-common.h"
#include "des.h"
-#include "cli.h"
#include "performance_test.h"
#include "bcal-performance.h"
#include "bcal-nessie.h"
#include "bcal_tdes.h"
#include "bcal_tdes2.h"
-#include <stdint.h>
-#include <string.h>
-#include <stdlib.h>
-
char* algo_name = "DES";
const bcdesc_t* const algolist[] PROGMEM = {
* additional validation-functions *
*****************************************************************************/
-void testrun_nessie_des(void){
- bcal_nessie_multiple(algolist);
+void testrun_nessie_des(const char* param){
+ if(!param){
+ bcal_nessie_multiple(algolist);
+ }else{
+ uint8_t i=0;
+ bcdesc_t* ptr;
+ for(;;){
+ ptr = (bcdesc_t*)pgm_read_word(&algolist[i++]);
+ if(ptr == NULL){
+ cli_putstr_P(PSTR("\r\nunknown algorithm: "));
+ cli_putstr(param);
+ cli_putstr_P(PSTR("\r\navailable algorithms are:"));
+ i = 0;
+ while((ptr = (bcdesc_t*)pgm_read_word(&algolist[i++]))){
+ cli_putstr_P(PSTR("\r\n\t"));
+ cli_putstr_P((const char*)pgm_read_word(&ptr->name));
+ }
+ return;
+ }
+ if(!strcmp_P(param, (const char*)pgm_read_word(&ptr->name))){
+ bcal_nessie(ptr);
+ return;
+ }
+ }
+ }
}
void testrun_performance_des(void){
const char echo_str[] PROGMEM = "echo";
const cmdlist_entry_t cmdlist[] PROGMEM = {
- { nessie_str, NULL, testrun_nessie_des },
- { test_str, NULL, testrun_nessie_des },
+ { nessie_str, (void*)1, (void_fpt)testrun_nessie_des },
+ { test_str, (void*)1, (void_fpt)testrun_nessie_des },
{ performance_str, NULL, testrun_performance_des},
{ echo_str, (void*)1, (void_fpt)echo_ctrl},
{ NULL, NULL, NULL}
};
-int main (void){
- DEBUG_INIT();
-
- cli_rx = (cli_rx_fpt)uart0_getc;
- cli_tx = (cli_tx_fpt)uart0_putc;
+int main(void) {
+ main_setup();
+
for(;;){
- cli_putstr_P(PSTR("\r\n\r\nCrypto-VS ("));
- cli_putstr(algo_name);
- cli_putstr_P(PSTR(")\r\nloaded and running\r\n"));
+ welcome_msg(algo_name);
cmd_interface(cmdlist);
- }
+ }
+
}
+
*
*/
-#include "config.h"
-
-#include "uart_i.h"
-#include "debug.h"
+#include "main-test-common.h"
#include <present80.h>
#include <present128.h>
-#include "cli.h"
#include "performance_test.h"
#include "bcal-performance.h"
#include "bcal-nessie.h"
#include "bcal_present80.h"
#include "bcal_present128.h"
-#include <stdlib.h>
-#include <stdint.h>
-#include <string.h>
-
char* algo_name = "Present";
const bcdesc_t* const algolist[] PROGMEM = {
{ NULL, NULL, NULL}
};
-int main (void){
- DEBUG_INIT();
-
- cli_rx = (cli_rx_fpt)uart0_getc;
- cli_tx = (cli_tx_fpt)uart0_putc;
+int main(void) {
+ main_setup();
+
+ shavs_algolist=(hfdesc_t**)algolist;
+ shavs_algo=(hfdesc_t*)&sha256_desc;
+
for(;;){
- cli_putstr_P(PSTR("\r\n\r\nCrypto-VS ("));
- cli_putstr(algo_name);
- cli_putstr_P(PSTR(")\r\nloaded and running\r\n"));
+ welcome_msg(algo_name);
cmd_interface(cmdlist);
- }
+ }
+
}
uint8_t *ciphertext, *plaintext, rc;
uint8_t seed[sizeof(SEED)];
uint16_t clen, plen;
+ if(!keys_allocated){
+ load_fix_rsa();
+ }
ciphertext = malloc(clen = pub_key.modulus.length_B * sizeof(bigint_word_t));
plaintext = malloc(pub_key.modulus.length_B * sizeof(bigint_word_t));
memcpy_P(plaintext, MSG, sizeof(MSG));
memcpy_P(seed, SEED, sizeof(SEED));
cli_putstr_P(PSTR("\r\nplaintext:"));
- cli_hexdump_block(plaintext, sizeof(MSG), 4, 8);
+ cli_hexdump_block(plaintext, sizeof(MSG), 4, 16);
cli_putstr_P(PSTR("\r\nencrypting: ..."));
rc = rsa_encrypt_oaep(ciphertext, &clen, plaintext, sizeof(MSG), &pub_key, NULL, NULL, seed);
if(rc){
#include "performance_test.h"
-#define DEBUG 0
+#define DEBUG 1
const char* algo_name = "RSAES-PKCS1V15";
cli_putstr_P(PSTR("\r\nERROR: OOM!"));
return;
}
- msg_ = malloc(bigint_length_B(&pub_key.modulus) + sizeof(bigint_word_t));
+ msg_ = malloc(bigint_length_B(&pub_key.modulus) /* + sizeof(bigint_word_t) */ );
#if DEBUG
cli_putstr_P(PSTR("\r\nDBG: @msg_: 0x"));
cli_hexdump_rev(&msg_, 2);
bcal_performance_multiple(algolist);
}
+int test_enc(const void* buffer, void* key){
+ uint8_t data[8];
+ int r;
+ memcpy(data, buffer, 8);
+ skipjack_enc(data, key);
+ cli_putstr_P(PSTR(" key = "));
+ cli_hexdump(key, 10);
+ cli_putstr_P(PSTR(" plaintext = "));
+ cli_hexdump(buffer, 8);
+ cli_putstr_P(PSTR(" ciphertext = "));
+ cli_hexdump(data, 8);
+ skipjack_dec(data, key);
+ r = memcmp(data, buffer, 8);
+ cli_putstr_P(PSTR(" decrypt: "));
+ if(r){
+ cli_putstr_P(PSTR("fail"));
+ }else{
+ cli_putstr_P(PSTR("ok"));
+ }
+ return r;
+}
+
+void testrun_nist_vectors(void){
+ uint8_t key[10];
+ uint8_t data[8];
+ uint8_t i;
+
+ cli_putstr_P(PSTR("\r\n\r\n=== NIST vectors run 1 ==="));
+ memset(key, 0, 10);
+ for(i=0; i<64; ++i){
+ memset(data, 0, 8);
+ data[i>>3] |= 0x80 >> (i & 7);
+ cli_putstr_P(PSTR("\r\n round: 0x"));
+ cli_hexdump_byte(i);
+ test_enc(data, key);
+ }
+
+ cli_putstr_P(PSTR("\r\n\r\n=== NIST vectors run 2 ==="));
+ memset(data, 0, 8);
+ for(i=0; i<80; ++i){
+ memset(key, 0, 10);
+ key[i>>3] |= 0x80 >> (i & 7);
+ cli_putstr_P(PSTR("\r\n round: 0x"));
+ cli_hexdump_byte(i);
+ test_enc(data, key);
+ }
+}
+
/*****************************************************************************
* self tests *
*****************************************************************************/
const char nessie_str[] PROGMEM = "nessie";
const char test_str[] PROGMEM = "test";
+const char nist_str[] PROGMEM = "nist";
const char performance_str[] PROGMEM = "performance";
const char echo_str[] PROGMEM = "echo";
const cmdlist_entry_t cmdlist[] PROGMEM = {
{ nessie_str, NULL, testrun_nessie_skipjack},
{ test_str, NULL, testrun_skipjack},
+ { nist_str, NULL, testrun_nist_vectors},
{ performance_str, NULL, testrun_performance_skipjack},
{ echo_str, (void*)1, (void_fpt)echo_ctrl},
{ NULL, NULL, NULL}
ldi r26, lo8(uart0_ctx+UART0_CBB_TX_OFFSET)
ldi r27, hi8(uart0_ctx+UART0_CBB_TX_OFFSET)
20:
-; sei
movw r24, r26
-; nop
-; nop
cli
rcall circularbytebuffer_cnt
sei
clr r25
cli
rcall circularbytebuffer_append
- sei
SET_BIT_IO UCSR0B, UDRIE0, r24
- ret
+ reti
/******************************************************************************/
/*
clr r1
LOAD_IO r24, UDR0
#if UART0_SWFLOWCTRL
- ldi r26, lo8(uart0_ctx+UART0_TXON_OFFSET)
+ ldi r26, lo8(uart0_ctx+UART0_TXON_OFFSET)
ldi r27, hi8(uart0_ctx+UART0_TXON_OFFSET)
cpi r24, XON_VALUE
- brne 10f
- ldi r24, 1
- st X, r24
- rjmp 99f
-10:
+ breq 11f
cpi r24, XOFF_VALUE
- brne 20f
+ brne 12f
clr r24
- st X, r24
+11: st X, r24
rjmp 99f
+12:
+ push r24
+/* now the "sending" part*/
+ ldi r24, lo8(uart0_ctx+UART0_CBB_RX_OFFSET)
+ ldi r25, hi8(uart0_ctx+UART0_CBB_RX_OFFSET)
+ rcall circularbytebuffer_cnt
+ ldi r30, lo8(uart0_ctx+UART0_RXON_OFFSET)
+ ldi r31, hi8(uart0_ctx+UART0_RXON_OFFSET)
+ ld r18, Z
+ tst r18
+ breq 15f/* branch if rxon inactive -> we had send an XOFF earlier */
+ /* ok, we did not have send an XOFF, should we? */
+ cpi r24, UART0_THRESH_HIGH
+ brlo 90f /* ok, nothing critical, go on */
+ st Z, r1
+ ldi r24, XOFF_VALUE
+; sbi _SFR_IO_ADDR(PORTD), 5
+ rjmp 16f
+15:
+ cpi r24, UART0_THRESH_LOW
+ brsh 90f /* nothing has changed */
+ /* if we get here, we had send an XOFF and are now below threshold */
+ /* so we sen an XON */
+ ldi r24, XON_VALUE
+ cbi _SFR_IO_ADDR(PORTD), 5
+ st Z, r24
+16:
+ ldi r22, lo8(uart0_ctx+UART0_CBB_TX_OFFSET)
+ ldi r23, hi8(uart0_ctx+UART0_CBB_TX_OFFSET)
+ rcall circularbytebuffer_push
+ SET_BIT_IO UCSR0B, UDRIE0, r24
+90:
+ pop r24
#endif /* UART0_SWFLOWCTRL */
20:
#if UART0_HOOK
ldi r22, lo8(uart0_ctx+UART0_CBB_RX_OFFSET)
ldi r23, hi8(uart0_ctx+UART0_CBB_RX_OFFSET)
clr r25
+; sbi _SFR_IO_ADDR(PORTD), 6
rcall circularbytebuffer_append
-#if UART0_SWFLOWCTRL
- ldi r24, lo8(uart0_ctx+UART0_CBB_RX_OFFSET)
- ldi r25, hi8(uart0_ctx+UART0_CBB_RX_OFFSET)
- rcall circularbytebuffer_cnt
- ldi r22, lo8(uart0_ctx+UART0_CBB_TX_OFFSET)
- ldi r23, hi8(uart0_ctx+UART0_CBB_TX_OFFSET)
- ldi r30, lo8(uart0_ctx+UART0_RXON_OFFSET)
- ldi r31, hi8(uart0_ctx+UART0_RXON_OFFSET)
- ld r18, Z
- tst r18
- breq 60f
- cpi r24, UART0_THRESH_HIGH+1
- brlo 99f
- clr r25
- ldi r24, XOFF_VALUE
- rcall circularbytebuffer_push
- SET_BIT_IO UCSR0B, UDRIE0, r24
- rjmp 99f
-60:
- cpi r24, UART0_THRESH_LOW
- brge 99f
- clr r25
- ldi r24, XON_VALUE
- rcall circularbytebuffer_push
- SET_BIT_IO UCSR0B, UDRIE0, r24
-#endif /* UART0_SWFLOWCTRL */
99:
out _SFR_IO_ADDR(SREG), r16
pop_range 16, 31