avr-gcc-list
[Top][All Lists]
Advanced

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

[avr-gcc-list] C aliasing rules


From: Lars Noschinski
Subject: [avr-gcc-list] C aliasing rules
Date: Tue, 18 May 2010 17:44:18 +0200
User-agent: Mutt/1.5.20 (2009-06-14)

Hello!

I'm trying to debug a strange problem, which depends on whether a
function is inlined (then it's broken) or not (then it's ok). Can
someone tell me if the following code snippet violates the C aliasing
rules for b1 (declared as uint8_t*, written as uint32_t* by
xteaDecrypt)?

If I read http://mail-index.netbsd.org/tech-kern/2003/08/11/0001.html
correctly, it should violate the rules?

// ---------------------------------------------------------------------------
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);
}
// ---------------------------------------------------------------------------


  -- Lars



reply via email to

[Prev in Thread] Current Thread [Next in Thread]