Permalink
Browse files

fix strict-aliasing compiler warnings

  • Loading branch information...
1 parent ec73cfa commit 74ce1a99b7463f6819ed585c10d8c0a9f88ce92a @sjaeckel sjaeckel committed Feb 25, 2014
@@ -244,8 +244,8 @@ int ccm_memory(int cipher,
/* xor the PT against the pad first */
for (z = 0; z < 16; z += sizeof(LTC_FAST_TYPE)) {
- *((LTC_FAST_TYPE*)(&PAD[z])) ^= *((LTC_FAST_TYPE*)(&pt[y+z]));
- *((LTC_FAST_TYPE*)(&ct[y+z])) = *((LTC_FAST_TYPE*)(&pt[y+z])) ^ *((LTC_FAST_TYPE*)(&CTRPAD[z]));
+ *(LTC_FAST_TYPE*)(PAD + z) ^= *(LTC_FAST_TYPE*)(pt + y + z);
+ *(LTC_FAST_TYPE*)(ct + y + z) = *(LTC_FAST_TYPE*)(pt + y + z) ^ *(LTC_FAST_TYPE*)(CTRPAD + z);
}
if ((err = cipher_descriptor[cipher].ecb_encrypt(PAD, PAD, skey)) != CRYPT_OK) {
goto error;
@@ -264,8 +264,8 @@ int ccm_memory(int cipher,
/* xor the PT against the pad last */
for (z = 0; z < 16; z += sizeof(LTC_FAST_TYPE)) {
- *((LTC_FAST_TYPE*)(&pt[y+z])) = *((LTC_FAST_TYPE*)(&ct[y+z])) ^ *((LTC_FAST_TYPE*)(&CTRPAD[z]));
- *((LTC_FAST_TYPE*)(&PAD[z])) ^= *((LTC_FAST_TYPE*)(&pt[y+z]));
+ *(LTC_FAST_TYPE*)(pt + y + z) = *(LTC_FAST_TYPE*)(ct + y + z) ^ *(LTC_FAST_TYPE*)(CTRPAD + z);
+ *(LTC_FAST_TYPE*)(PAD + z) ^= *(LTC_FAST_TYPE*)(pt + y + z);
}
if ((err = cipher_descriptor[cipher].ecb_encrypt(PAD, PAD, skey)) != CRYPT_OK) {
goto error;
@@ -90,9 +90,10 @@ int gcm_add_aad(gcm_state *gcm,
x = 0;
#ifdef LTC_FAST
if (gcm->buflen == 0) {
+ unsigned char* gcm_X = gcm->X;
for (x = 0; x < (adatalen & ~15); x += 16) {
for (y = 0; y < 16; y += sizeof(LTC_FAST_TYPE)) {
- *((LTC_FAST_TYPE*)(&gcm->X[y])) ^= *((LTC_FAST_TYPE*)(&adata[x + y]));
+ *((LTC_FAST_TYPE*)(gcm_X + y)) ^= *(LTC_FAST_TYPE*)(adata + x + y);
}
gcm_mult_h(gcm, gcm->X);
gcm->totlen += 128;
@@ -57,9 +57,10 @@ int gcm_add_iv(gcm_state *gcm,
x = 0;
#ifdef LTC_FAST
if (gcm->buflen == 0) {
+ unsigned char* gcm_X = gcm->X;
for (x = 0; x < (IVlen & ~15); x += 16) {
for (y = 0; y < 16; y += sizeof(LTC_FAST_TYPE)) {
- *((LTC_FAST_TYPE*)(&gcm->X[y])) ^= *((LTC_FAST_TYPE*)(&IV[x + y]));
+ *((LTC_FAST_TYPE*)(gcm_X + y)) ^= *(LTC_FAST_TYPE*)(IV + x + y);
}
gcm_mult_h(gcm, gcm->X);
gcm->totlen += 128;
@@ -36,8 +36,9 @@ void gcm_mult_h(gcm_state *gcm, unsigned char *I)
XMEMCPY(T, &gcm->PC[0][I[0]][0], 16);
for (x = 1; x < 16; x++) {
#ifdef LTC_FAST
+ unsigned char* gcm_PC = gcm->PC[x][I[x]];
for (y = 0; y < 16; y += sizeof(LTC_FAST_TYPE)) {
- *((LTC_FAST_TYPE *)(T + y)) ^= *((LTC_FAST_TYPE *)(&gcm->PC[x][I[x]][y]));
+ *((LTC_FAST_TYPE *)(T + y)) ^= *(LTC_FAST_TYPE *)(gcm_PC + y);
}
#else
for (y = 0; y < 16; y++) {
@@ -77,12 +77,14 @@ int gcm_process(gcm_state *gcm,
x = 0;
#ifdef LTC_FAST
if (gcm->buflen == 0) {
+ unsigned char *gcm_buf = gcm->buf;
+ unsigned char *gcm_X = gcm->X;
if (direction == GCM_ENCRYPT) {
for (x = 0; x < (ptlen & ~15); x += 16) {
/* ctr encrypt */
for (y = 0; y < 16; y += sizeof(LTC_FAST_TYPE)) {
- *((LTC_FAST_TYPE*)(&ct[x + y])) = *((LTC_FAST_TYPE*)(&pt[x+y])) ^ *((LTC_FAST_TYPE*)(&gcm->buf[y]));
- *((LTC_FAST_TYPE*)(&gcm->X[y])) ^= *((LTC_FAST_TYPE*)(&ct[x+y]));
+ *((LTC_FAST_TYPE*)(ct + x + y)) = *((LTC_FAST_TYPE*)(pt + x + y)) ^ *((LTC_FAST_TYPE*)(gcm_buf + y));
+ *((LTC_FAST_TYPE*)(gcm_X + y)) ^= *((LTC_FAST_TYPE*)(ct + x + y));
}
/* GMAC it */
gcm->pttotlen += 128;
@@ -99,8 +101,8 @@ int gcm_process(gcm_state *gcm,
for (x = 0; x < (ptlen & ~15); x += 16) {
/* ctr encrypt */
for (y = 0; y < 16; y += sizeof(LTC_FAST_TYPE)) {
- *((LTC_FAST_TYPE*)(&gcm->X[y])) ^= *((LTC_FAST_TYPE*)(&ct[x+y]));
- *((LTC_FAST_TYPE*)(&pt[x + y])) = *((LTC_FAST_TYPE*)(&ct[x+y])) ^ *((LTC_FAST_TYPE*)(&gcm->buf[y]));
+ *((LTC_FAST_TYPE*)(gcm_X + y)) ^= *((LTC_FAST_TYPE*)(ct + x + y));
+ *((LTC_FAST_TYPE*)(pt + x + y)) = *((LTC_FAST_TYPE*)(ct + x + y)) ^ *((LTC_FAST_TYPE*)(gcm_buf + y));
}
/* GMAC it */
gcm->pttotlen += 128;
View
@@ -42,13 +42,15 @@ int f9_process(f9_state *f9, const unsigned char *in, unsigned long inlen)
#ifdef LTC_FAST
if (f9->buflen == 0) {
+ unsigned char* f9_IV = f9->IV;
+ unsigned char* f9_ACC = f9->ACC;
while (inlen >= (unsigned long)f9->blocksize) {
for (x = 0; x < f9->blocksize; x += sizeof(LTC_FAST_TYPE)) {
- *((LTC_FAST_TYPE*)&(f9->IV[x])) ^= *((LTC_FAST_TYPE*)&(in[x]));
+ *((LTC_FAST_TYPE*)(f9_IV + x)) ^= *((LTC_FAST_TYPE*)(in + x));
}
cipher_descriptor[f9->cipher].ecb_encrypt(f9->IV, f9->IV, &f9->key);
for (x = 0; x < f9->blocksize; x += sizeof(LTC_FAST_TYPE)) {
- *((LTC_FAST_TYPE*)&(f9->ACC[x])) ^= *((LTC_FAST_TYPE*)&(f9->IV[x]));
+ *((LTC_FAST_TYPE*)(f9_ACC + x)) ^= *((LTC_FAST_TYPE*)(f9_IV + x));
}
in += f9->blocksize;
inlen -= f9->blocksize;
@@ -45,9 +45,10 @@ int omac_process(omac_state *omac, const unsigned char *in, unsigned long inlen)
blklen = cipher_descriptor[omac->cipher_idx].block_length;
if (omac->buflen == 0 && inlen > blklen) {
unsigned long y;
+ unsigned char* omac_prev = omac->prev;
for (x = 0; x < (inlen - blklen); x += blklen) {
for (y = 0; y < blklen; y += sizeof(LTC_FAST_TYPE)) {
- *((LTC_FAST_TYPE*)(&omac->prev[y])) ^= *((LTC_FAST_TYPE*)(&in[y]));
+ *((LTC_FAST_TYPE*)(omac_prev + y)) ^= *((LTC_FAST_TYPE*)(in + y));
}
in += blklen;
if ((err = cipher_descriptor[omac->cipher_idx].ecb_encrypt(omac->prev, omac->prev, &omac->key)) != CRYPT_OK) {
@@ -110,10 +110,11 @@ int pelican_process(pelican_state *pelmac, const unsigned char *in, unsigned lon
#ifdef LTC_FAST
if (pelmac->buflen == 0) {
+ unsigned char* pelmac_state = pelmac->state;
while (inlen & ~15) {
int x;
for (x = 0; x < 16; x += sizeof(LTC_FAST_TYPE)) {
- *((LTC_FAST_TYPE*)((unsigned char *)pelmac->state + x)) ^= *((LTC_FAST_TYPE*)((unsigned char *)in + x));
+ *((LTC_FAST_TYPE*)(pelmac_state + x)) ^= *((LTC_FAST_TYPE*)(in + x));
}
four_rounds(pelmac);
in += 16;
@@ -45,16 +45,18 @@ int pmac_process(pmac_state *pmac, const unsigned char *in, unsigned long inlen)
#ifdef LTC_FAST
if (pmac->buflen == 0 && inlen > 16) {
unsigned long y;
+ unsigned char* pmac_Li = pmac->Li;
+ unsigned char* pmac_checksum = pmac->checksum;
for (x = 0; x < (inlen - 16); x += 16) {
pmac_shift_xor(pmac);
for (y = 0; y < 16; y += sizeof(LTC_FAST_TYPE)) {
- *((LTC_FAST_TYPE*)(&Z[y])) = *((LTC_FAST_TYPE*)(&in[y])) ^ *((LTC_FAST_TYPE*)(&pmac->Li[y]));
+ *((LTC_FAST_TYPE*)(Z + y)) = *((LTC_FAST_TYPE*)(in + y)) ^ *((LTC_FAST_TYPE*)(pmac_Li + y));
}
if ((err = cipher_descriptor[pmac->cipher_idx].ecb_encrypt(Z, Z, &pmac->key)) != CRYPT_OK) {
return err;
}
for (y = 0; y < 16; y += sizeof(LTC_FAST_TYPE)) {
- *((LTC_FAST_TYPE*)(&pmac->checksum[y])) ^= *((LTC_FAST_TYPE*)(&Z[y]));
+ *((LTC_FAST_TYPE*)(pmac_checksum + y)) ^= *((LTC_FAST_TYPE*)(Z + y));
}
in += 16;
}
@@ -10,9 +10,9 @@
*/
#include "tomcrypt.h"
-/**
+/**
@file pmac_shift_xor.c
- PMAC implementation, internal function, by Tom St Denis
+ PMAC implementation, internal function, by Tom St Denis
*/
#ifdef LTC_PMAC
@@ -26,9 +26,13 @@ void pmac_shift_xor(pmac_state *pmac)
int x, y;
y = pmac_ntz(pmac->block_index++);
#ifdef LTC_FAST
- for (x = 0; x < pmac->block_len; x += sizeof(LTC_FAST_TYPE)) {
- *((LTC_FAST_TYPE*)((unsigned char *)pmac->Li + x)) ^=
- *((LTC_FAST_TYPE*)((unsigned char *)pmac->Ls[y] + x));
+ {
+ unsigned char* pmac_Li = pmac->Li;
+ unsigned char* pmac_Ls_y = pmac->Ls[y];
+ for (x = 0; x < pmac->block_len; x += sizeof(LTC_FAST_TYPE)) {
+ *((LTC_FAST_TYPE*)(pmac_Li + x)) ^=
+ *((LTC_FAST_TYPE*)(pmac_Ls_y + x));
+ }
}
#else
for (x = 0; x < pmac->block_len; x++) {
@@ -45,9 +45,10 @@ int xcbc_process(xcbc_state *xcbc, const unsigned char *in, unsigned long inlen)
#ifdef LTC_FAST
if (xcbc->buflen == 0) {
+ unsigned char* xcbc_IV = xcbc->IV;
while (inlen > (unsigned long)xcbc->blocksize) {
for (x = 0; x < xcbc->blocksize; x += sizeof(LTC_FAST_TYPE)) {
- *((LTC_FAST_TYPE*)&(xcbc->IV[x])) ^= *((LTC_FAST_TYPE*)&(in[x]));
+ *((LTC_FAST_TYPE*)(xcbc_IV + x)) ^= *((LTC_FAST_TYPE*)(in + x));
}
cipher_descriptor[xcbc->cipher].ecb_encrypt(xcbc->IV, xcbc->IV, &xcbc->key);
in += xcbc->blocksize;
@@ -68,19 +68,22 @@ int cbc_decrypt(const unsigned char *ct, unsigned char *pt, unsigned long len, s
}
/* xor IV against plaintext */
- #if defined(LTC_FAST)
- for (x = 0; x < cbc->blocklen; x += sizeof(LTC_FAST_TYPE)) {
- tmpy = *((LTC_FAST_TYPE*)((unsigned char *)cbc->IV + x)) ^ *((LTC_FAST_TYPE*)((unsigned char *)tmp + x));
- *((LTC_FAST_TYPE*)((unsigned char *)cbc->IV + x)) = *((LTC_FAST_TYPE*)((unsigned char *)ct + x));
- *((LTC_FAST_TYPE*)((unsigned char *)pt + x)) = tmpy;
- }
- #else
+#if defined(LTC_FAST)
+ {
+ unsigned char* cbc_IV = cbc->IV;
+ for (x = 0; x < cbc->blocklen; x += sizeof(LTC_FAST_TYPE)) {
+ tmpy = *((LTC_FAST_TYPE*)(cbc_IV + x)) ^ *((LTC_FAST_TYPE*)(tmp + x));
+ *((LTC_FAST_TYPE*)(cbc_IV + x)) = *((LTC_FAST_TYPE*)(ct + x));
+ *((LTC_FAST_TYPE*)(pt + x)) = tmpy;
+ }
+ }
+#else
for (x = 0; x < cbc->blocklen; x++) {
tmpy = tmp[x] ^ cbc->IV[x];
cbc->IV[x] = ct[x];
pt[x] = tmpy;
}
- #endif
+#endif
ct += cbc->blocklen;
pt += cbc->blocklen;
@@ -57,31 +57,32 @@ int cbc_encrypt(const unsigned char *pt, unsigned char *ct, unsigned long len, s
} else {
while (len) {
/* xor IV against plaintext */
- #if defined(LTC_FAST)
+#if defined(LTC_FAST)
+ unsigned char* cbc_IV = cbc->IV;
for (x = 0; x < cbc->blocklen; x += sizeof(LTC_FAST_TYPE)) {
- *((LTC_FAST_TYPE*)((unsigned char *)cbc->IV + x)) ^= *((LTC_FAST_TYPE*)((unsigned char *)pt + x));
+ *((LTC_FAST_TYPE*)(cbc_IV + x)) ^= *((LTC_FAST_TYPE*)(pt + x));
}
- #else
+#else
for (x = 0; x < cbc->blocklen; x++) {
cbc->IV[x] ^= pt[x];
}
- #endif
+#endif
/* encrypt */
if ((err = cipher_descriptor[cbc->cipher].ecb_encrypt(cbc->IV, ct, &cbc->key)) != CRYPT_OK) {
return err;
}
/* store IV [ciphertext] for a future block */
- #if defined(LTC_FAST)
+#if defined(LTC_FAST)
for (x = 0; x < cbc->blocklen; x += sizeof(LTC_FAST_TYPE)) {
- *((LTC_FAST_TYPE*)((unsigned char *)cbc->IV + x)) = *((LTC_FAST_TYPE*)((unsigned char *)ct + x));
+ *((LTC_FAST_TYPE*)(cbc_IV + x)) = *((LTC_FAST_TYPE*)(ct + x));
}
- #else
+#else
for (x = 0; x < cbc->blocklen; x++) {
cbc->IV[x] = ct[x];
}
- #endif
+#endif
ct += cbc->blocklen;
pt += cbc->blocklen;
@@ -88,9 +88,10 @@ int ctr_encrypt(const unsigned char *pt, unsigned char *ct, unsigned long len, s
}
#ifdef LTC_FAST
if (ctr->padlen == 0 && len >= (unsigned long)ctr->blocklen) {
+ unsigned char* ctr_pad = ctr->pad;
for (x = 0; x < ctr->blocklen; x += sizeof(LTC_FAST_TYPE)) {
- *((LTC_FAST_TYPE*)((unsigned char *)ct + x)) = *((LTC_FAST_TYPE*)((unsigned char *)pt + x)) ^
- *((LTC_FAST_TYPE*)((unsigned char *)ctr->pad + x));
+ *((LTC_FAST_TYPE*)(ct + x)) = *((LTC_FAST_TYPE*)(pt + x)) ^
+ *((LTC_FAST_TYPE*)(ctr_pad + x));
}
pt += ctr->blocklen;
ct += ctr->blocklen;
@@ -61,11 +61,13 @@ int f8_encrypt(const unsigned char *pt, unsigned char *ct, unsigned long len, sy
#ifdef LTC_FAST
if (f8->padlen == 0) {
while (len >= (unsigned long)f8->blocklen) {
+ unsigned char* f8_IV = f8->IV;
+ unsigned char* f8_MIV = f8->MIV;
STORE32H(f8->blockcnt, (buf+(f8->blocklen-4)));
++(f8->blockcnt);
for (x = 0; x < f8->blocklen; x += sizeof(LTC_FAST_TYPE)) {
- *((LTC_FAST_TYPE*)(&ct[x])) = *((LTC_FAST_TYPE*)(&pt[x])) ^ *((LTC_FAST_TYPE*)(&f8->IV[x]));
- *((LTC_FAST_TYPE*)(&f8->IV[x])) ^= *((LTC_FAST_TYPE*)(&f8->MIV[x])) ^ *((LTC_FAST_TYPE*)(&buf[x]));
+ *((LTC_FAST_TYPE*)(ct + x)) = *((LTC_FAST_TYPE*)(pt + x)) ^ *((LTC_FAST_TYPE*)(f8_IV + x));
+ *((LTC_FAST_TYPE*)(f8_IV + x)) ^= *((LTC_FAST_TYPE*)(f8_MIV + x)) ^ *((LTC_FAST_TYPE*)(buf + x));
}
if ((err = cipher_descriptor[f8->cipher].ecb_encrypt(f8->IV, f8->IV, &f8->key)) != CRYPT_OK) {
return err;
@@ -59,8 +59,11 @@ int lrw_process(const unsigned char *pt, unsigned char *ct, unsigned long len, i
/* for each byte changed we undo it's affect on the pad then add the new product */
for (; x < 16; x++) {
#ifdef LTC_FAST
+ unsigned char *lrw_pad = lrw->pad;
+ unsigned char *lrw_PC_IV_x = lrw->PC[x][lrw->IV[x]];
+ unsigned char *lrw_PC_IV_x_1 = lrw->PC[x][(lrw->IV[x]-1)&255];
for (y = 0; y < 16; y += sizeof(LTC_FAST_TYPE)) {
- *((LTC_FAST_TYPE *)(lrw->pad + y)) ^= *((LTC_FAST_TYPE *)(&lrw->PC[x][lrw->IV[x]][y])) ^ *((LTC_FAST_TYPE *)(&lrw->PC[x][(lrw->IV[x]-1)&255][y]));
+ *((LTC_FAST_TYPE *)(lrw_pad + y)) ^= *((LTC_FAST_TYPE *)(lrw_PC_IV_x + y)) ^ *((LTC_FAST_TYPE *)(lrw_PC_IV_x_1 + y));
}
#else
for (y = 0; y < 16; y++) {
@@ -55,8 +55,9 @@ int lrw_setiv(const unsigned char *IV, unsigned long len, symmetric_LRW *lrw)
XMEMCPY(T, &lrw->PC[0][IV[0]][0], 16);
for (x = 1; x < 16; x++) {
#ifdef LTC_FAST
+ unsigned char *lrw_PC_IV_x = lrw->PC[x][IV[x]];
for (y = 0; y < 16; y += sizeof(LTC_FAST_TYPE)) {
- *((LTC_FAST_TYPE *)(T + y)) ^= *((LTC_FAST_TYPE *)(&lrw->PC[x][IV[x]][y]));
+ *((LTC_FAST_TYPE *)(T + y)) ^= *((LTC_FAST_TYPE *)(lrw_PC_IV_x + y));
}
#else
for (y = 0; y < 16; y++) {
View
@@ -61,7 +61,7 @@ int store_test(void)
/* now XOR it word for word */
for (x = 0; x < y; x += sizeof(LTC_FAST_TYPE)) {
- *((LTC_FAST_TYPE*)(&buf[3*y+z+x])) = *((LTC_FAST_TYPE*)(&buf[z+x])) ^ *((LTC_FAST_TYPE*)(&buf[z+y+x]));
+ *((LTC_FAST_TYPE*)(buf + 3*y + z + x)) = *((LTC_FAST_TYPE*)(buf + z + x)) ^ *((LTC_FAST_TYPE*)(buf + z + y + x));
}
if (memcmp(&buf[2*y+z], &buf[3*y+z], y)) {

0 comments on commit 74ce1a9

Please sign in to comment.