summaryrefslogtreecommitdiffstats
path: root/src/crypto/mac/ghash/pclmulqdq
diff options
context:
space:
mode:
authorMatthias Schiffer <mschiffer@universe-factory.net>2013-11-29 05:33:12 +0100
committerMatthias Schiffer <mschiffer@universe-factory.net>2013-11-29 05:35:49 +0100
commit61349d3d273aa23935b0c413c5885005db2669db (patch)
tree9cbc05acb31476d45b48d4a51e9edca19328b8e8 /src/crypto/mac/ghash/pclmulqdq
parentc13fe36e4c0730037ae75d51f7f052d916486aac (diff)
downloadfastd-61349d3d273aa23935b0c413c5885005db2669db.tar
fastd-61349d3d273aa23935b0c413c5885005db2669db.zip
Compile with -std=c99 and restructure some code to ensure there is no invalid aliasing (hopefully)
Diffstat (limited to 'src/crypto/mac/ghash/pclmulqdq')
-rw-r--r--src/crypto/mac/ghash/pclmulqdq/ghash_pclmulqdq_impl.c21
1 files changed, 10 insertions, 11 deletions
diff --git a/src/crypto/mac/ghash/pclmulqdq/ghash_pclmulqdq_impl.c b/src/crypto/mac/ghash/pclmulqdq/ghash_pclmulqdq_impl.c
index 0abff8c..375cf91 100644
--- a/src/crypto/mac/ghash/pclmulqdq/ghash_pclmulqdq_impl.c
+++ b/src/crypto/mac/ghash/pclmulqdq/ghash_pclmulqdq_impl.c
@@ -30,10 +30,10 @@
#include <tmmintrin.h>
-typedef union _vecblock {
+typedef union vecblock {
__m128i v;
fastd_block128_t b;
-} vecblock;
+} vecblock_t;
static inline __m128i shl(__m128i v, int a) {
__m128i tmpl = _mm_slli_epi64(v, a);
@@ -61,7 +61,7 @@ static inline __m128i byteswap(__m128i v) {
fastd_mac_state_t* fastd_ghash_pclmulqdq_init_state(fastd_context_t *ctx UNUSED, const fastd_mac_context_t *mctx UNUSED, const uint8_t *key) {
fastd_mac_state_t *state = malloc(sizeof(fastd_mac_state_t));
- vecblock h;
+ vecblock_t h;
memcpy(&h, key, sizeof(__m128i));
h.v = byteswap(h.v);
@@ -124,19 +124,18 @@ static __m128i gmul(__m128i v, __m128i h) {
bool fastd_ghash_pclmulqdq_hash(fastd_context_t *ctx UNUSED, const fastd_mac_state_t *state, fastd_block128_t *out, const fastd_block128_t *in, size_t n_blocks) {
- const __m128i *inv = (const __m128i*)in;
-
- __m128i h = ((vecblock*)&state->H)->v;
- __m128i v = _mm_setzero_si128();
+ vecblock_t h = {.b = state->H};
+ vecblock_t v = {.v = _mm_setzero_si128()};
size_t i;
for (i = 0; i < n_blocks; i++) {
- __m128i b = inv[i];
- v = _mm_xor_si128(v, byteswap(b));
- v = gmul(v, h);
+ __m128i b = ((vecblock_t)in[i]).v;
+ v.v = _mm_xor_si128(v.v, byteswap(b));
+ v.v = gmul(v.v, h.v);
}
- ((vecblock*)out)->v = byteswap(v);
+ v.v = byteswap(v.v);
+ *out = v.b;
return true;
}