summaryrefslogtreecommitdiffstats
path: root/src/crypto/mac
diff options
context:
space:
mode:
Diffstat (limited to 'src/crypto/mac')
-rw-r--r--src/crypto/mac/ghash/builtin/ghash_builtin.c26
-rw-r--r--src/crypto/mac/ghash/pclmulqdq/ghash_pclmulqdq_impl.c21
2 files changed, 23 insertions, 24 deletions
diff --git a/src/crypto/mac/ghash/builtin/ghash_builtin.c b/src/crypto/mac/ghash/builtin/ghash_builtin.c
index cc81e74..511e844 100644
--- a/src/crypto/mac/ghash/builtin/ghash_builtin.c
+++ b/src/crypto/mac/ghash/builtin/ghash_builtin.c
@@ -35,13 +35,13 @@ struct fastd_mac_state {
static const fastd_block128_t r = { .b = {0xe1} };
-static inline uint8_t shr(fastd_block128_t *out, const fastd_block128_t *in, int n) {
+static inline uint8_t shr(fastd_block128_t *out, fastd_block128_t in, int n) {
size_t i;
uint8_t c = 0;
for (i = 0; i < sizeof(fastd_block128_t); i++) {
- uint8_t c2 = in->b[i] << (8-n);
- out->b[i] = (in->b[i] >> n) | c;
+ uint8_t c2 = in.b[i] << (8-n);
+ out->b[i] = (in.b[i] >> n) | c;
c = c2;
}
@@ -53,8 +53,8 @@ static inline void mulH_a(fastd_block128_t *x, const fastd_mac_state_t *cstate)
int i;
for (i = 0; i < 16; i++) {
- xor_a(&out, &cstate->H[2*i][x->b[i]>>4]);
- xor_a(&out, &cstate->H[2*i+1][x->b[i]&0xf]);
+ xor_a(&out, cstate->H[2*i][x->b[i]>>4]);
+ xor_a(&out, cstate->H[2*i+1][x->b[i]&0xf]);
}
*x = out;
@@ -76,11 +76,11 @@ static fastd_mac_state_t* ghash_init_state(fastd_context_t *ctx UNUSED, const fa
int i;
for (i = 1; i < 4; i++) {
- uint8_t carry = shr(&Hbase[i], &Hbase[i-1], 1);
+ uint8_t carry = shr(&Hbase[i], Hbase[i-1], 1);
if (carry)
- xor_a(&Hbase[i], &r);
+ xor_a(&Hbase[i], r);
- shr(&Rbase[i], &Rbase[i-1], 1);
+ shr(&Rbase[i], Rbase[i-1], 1);
}
fastd_block128_t R[16];
@@ -91,8 +91,8 @@ static fastd_mac_state_t* ghash_init_state(fastd_context_t *ctx UNUSED, const fa
int j;
for (j = 0; j < 4; j++) {
if (i & (8 >> j)) {
- xor_a(&state->H[0][i], &Hbase[j]);
- xor_a(&R[i], &Rbase[j]);
+ xor_a(&state->H[0][i], Hbase[j]);
+ xor_a(&R[i], Rbase[j]);
}
}
}
@@ -101,8 +101,8 @@ static fastd_mac_state_t* ghash_init_state(fastd_context_t *ctx UNUSED, const fa
int j;
for (j = 0; j < 16; j++) {
- uint8_t carry = shr(&state->H[i][j], &state->H[i-1][j], 4);
- xor_a(&state->H[i][j], &R[carry]);
+ uint8_t carry = shr(&state->H[i][j], state->H[i-1][j], 4);
+ xor_a(&state->H[i][j], R[carry]);
}
}
@@ -114,7 +114,7 @@ static bool ghash_hash(fastd_context_t *ctx UNUSED, const fastd_mac_state_t *sta
size_t i;
for (i = 0; i < n_blocks; i++) {
- xor_a(out, &in[i]);
+ xor_a(out, in[i]);
mulH_a(out, state);
}
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;
}