summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorWerner Koch <wk@gnupg.org>2012-11-21 12:58:36 +0100
committerWerner Koch <wk@gnupg.org>2012-11-21 12:58:36 +0100
commitdfb4673da8ee52d95e0a62c9f49ca8599943f22e (patch)
treecdfc7d6a5f01ae6ca13a8155d7a40d93c0d91c4d
parent3047795794eb238aa684bd0729acf64c82a19e09 (diff)
downloadlibgcrypt-dfb4673da8ee52d95e0a62c9f49ca8599943f22e.tar.gz
Fix for strict aliasing rules.
* cipher/rijndael.c (do_setkey, prepare_decryption): Use u32_a_t for casting. -- gcc 4.7.1 now show warnings for more functions. Like: rijndael.c:412:19: warning: dereferencing type-punned pointer will break strict-aliasing rules [-Wstrict-aliasing] This fixes them using the may_alias attribute.
-rw-r--r--cipher/rijndael.c36
1 files changed, 18 insertions, 18 deletions
diff --git a/cipher/rijndael.c b/cipher/rijndael.c
index 3418c99c..d081b423 100644
--- a/cipher/rijndael.c
+++ b/cipher/rijndael.c
@@ -362,7 +362,7 @@ do_setkey (RIJNDAEL_context *ctx, const byte *key, const unsigned keylen)
for (j = KC-1; j >= 0; j--)
{
- *((u32*)tk[j]) = *((u32*)k[j]);
+ *((u32_a_t*)tk[j]) = *((u32_a_t*)k[j]);
}
r = 0;
t = 0;
@@ -371,7 +371,7 @@ do_setkey (RIJNDAEL_context *ctx, const byte *key, const unsigned keylen)
{
for (; (j < KC) && (t < 4); j++, t++)
{
- *((u32*)W[r][t]) = *((u32*)tk[j]);
+ *((u32_a_t*)W[r][t]) = *((u32_a_t*)tk[j]);
}
if (t == 4)
{
@@ -394,14 +394,14 @@ do_setkey (RIJNDAEL_context *ctx, const byte *key, const unsigned keylen)
{
for (j = 1; j < KC; j++)
{
- *((u32*)tk[j]) ^= *((u32*)tk[j-1]);
+ *((u32_a_t*)tk[j]) ^= *((u32_a_t*)tk[j-1]);
}
}
else
{
for (j = 1; j < KC/2; j++)
{
- *((u32*)tk[j]) ^= *((u32*)tk[j-1]);
+ *((u32_a_t*)tk[j]) ^= *((u32_a_t*)tk[j-1]);
}
tk[KC/2][0] ^= S[tk[KC/2 - 1][0]];
tk[KC/2][1] ^= S[tk[KC/2 - 1][1]];
@@ -409,7 +409,7 @@ do_setkey (RIJNDAEL_context *ctx, const byte *key, const unsigned keylen)
tk[KC/2][3] ^= S[tk[KC/2 - 1][3]];
for (j = KC/2 + 1; j < KC; j++)
{
- *((u32*)tk[j]) ^= *((u32*)tk[j-1]);
+ *((u32_a_t*)tk[j]) ^= *((u32_a_t*)tk[j-1]);
}
}
@@ -418,7 +418,7 @@ do_setkey (RIJNDAEL_context *ctx, const byte *key, const unsigned keylen)
{
for (; (j < KC) && (t < 4); j++, t++)
{
- *((u32*)W[r][t]) = *((u32*)tk[j]);
+ *((u32_a_t*)W[r][t]) = *((u32_a_t*)tk[j]);
}
if (t == 4)
{
@@ -488,29 +488,29 @@ prepare_decryption( RIJNDAEL_context *ctx )
for (r=0; r < MAXROUNDS+1; r++ )
{
- *((u32*)ctx->keyschdec[r][0]) = *((u32*)ctx->keyschenc[r][0]);
- *((u32*)ctx->keyschdec[r][1]) = *((u32*)ctx->keyschenc[r][1]);
- *((u32*)ctx->keyschdec[r][2]) = *((u32*)ctx->keyschenc[r][2]);
- *((u32*)ctx->keyschdec[r][3]) = *((u32*)ctx->keyschenc[r][3]);
+ *((u32_a_t*)ctx->keyschdec[r][0]) = *((u32_a_t*)ctx->keyschenc[r][0]);
+ *((u32_a_t*)ctx->keyschdec[r][1]) = *((u32_a_t*)ctx->keyschenc[r][1]);
+ *((u32_a_t*)ctx->keyschdec[r][2]) = *((u32_a_t*)ctx->keyschenc[r][2]);
+ *((u32_a_t*)ctx->keyschdec[r][3]) = *((u32_a_t*)ctx->keyschenc[r][3]);
}
#define W (ctx->keyschdec)
for (r = 1; r < ctx->rounds; r++)
{
w = W[r][0];
- *((u32*)w) = *((u32*)U1[w[0]]) ^ *((u32*)U2[w[1]])
- ^ *((u32*)U3[w[2]]) ^ *((u32*)U4[w[3]]);
+ *((u32_a_t*)w) = *((u32_a_t*)U1[w[0]]) ^ *((u32_a_t*)U2[w[1]])
+ ^ *((u32_a_t*)U3[w[2]]) ^ *((u32_a_t*)U4[w[3]]);
w = W[r][1];
- *((u32*)w) = *((u32*)U1[w[0]]) ^ *((u32*)U2[w[1]])
- ^ *((u32*)U3[w[2]]) ^ *((u32*)U4[w[3]]);
+ *((u32_a_t*)w) = *((u32_a_t*)U1[w[0]]) ^ *((u32_a_t*)U2[w[1]])
+ ^ *((u32_a_t*)U3[w[2]]) ^ *((u32_a_t*)U4[w[3]]);
w = W[r][2];
- *((u32*)w) = *((u32*)U1[w[0]]) ^ *((u32*)U2[w[1]])
- ^ *((u32*)U3[w[2]]) ^ *((u32*)U4[w[3]]);
+ *((u32_a_t*)w) = *((u32_a_t*)U1[w[0]]) ^ *((u32_a_t*)U2[w[1]])
+ ^ *((u32_a_t*)U3[w[2]]) ^ *((u32_a_t*)U4[w[3]]);
w = W[r][3];
- *((u32*)w) = *((u32*)U1[w[0]]) ^ *((u32*)U2[w[1]])
- ^ *((u32*)U3[w[2]]) ^ *((u32*)U4[w[3]]);
+ *((u32_a_t*)w) = *((u32_a_t*)U1[w[0]]) ^ *((u32_a_t*)U2[w[1]])
+ ^ *((u32_a_t*)U3[w[2]]) ^ *((u32_a_t*)U4[w[3]]);
}
#undef W
#undef w