Hi! * Bernard Fouché <bernard.fou...@kuantic.com> [10-05-19 17:06]: [reordered quote] > >>>// > >>>--------------------------------------------------------------------------- > >>>void xteaDecrypt(uint32_t v[2], uint32_t const k[4]) { > >>> uint32_t v0=v[0], v1=v[1], delta=0x9E3779B9, sum=delta*XTEA_ROUNDS; > >>> for (uint8_t i=0; i< XTEA_ROUNDS; i++) { > >>> v1 -= (((v0<< 4) ^ (v0>> 5)) + v0) ^ (sum + k[(sum>>11)& 3]); > >>> sum -= delta; > >>> v0 -= (((v1<< 4) ^ (v1>> 5)) + v1) ^ (sum + k[sum& 3]); > >>> } > >>> v[0]=v0; v[1]=v1; > >>>} > >>> > >>>void xteaDecryptCbc(uint8_t v[8], uint8_t cb[8], uint8_t const k[16]) { > >>> static uint8_t tmpbuf[8]; > >>> memcpy(tmpbuf, v, 8); > >>> xteaDecrypt((uint32_t*)v, (uint32_t*)k); > >>> for (uint8_t i=0; i< 8; i++) > >>> v[i] ^= cb[i]; > >>> memcpy(cb, tmpbuf, 8); > >>>} > >>> > >>>int main(void) { > >>> uint8_t b1[8], b2[8], b3[16]; > >>> xteaDecryptCbc(b1, b2 b3); > >>>} > >>>// > >>>--------------------------------------------------------------------------- > > I don't understand what 'tmpbuf' is declared 'static'.
tmpbuf is declared static as the compiler produces better code in this case (arrays on the stack are costly). > And what do you mean by 'broken'? In your example, main() calls > functions by providing pointers to uninitialized data located in the > stack. This was just an incomplete example, in my application those buffers are filled with real data. I provided the declarations in main() because for alias analysis the declared type of a variable matters. -- Lars. _______________________________________________ AVR-GCC-list mailing list AVR-GCC-list@nongnu.org http://lists.nongnu.org/mailman/listinfo/avr-gcc-list