diff options
author | Matthias Schiffer <mschiffer@universe-factory.net> | 2013-12-04 18:22:33 +0100 |
---|---|---|
committer | Matthias Schiffer <mschiffer@universe-factory.net> | 2013-12-04 19:15:56 +0100 |
commit | 822c9e935a25a7590cd99b4c5407bb6596be41b7 (patch) | |
tree | bbb54a32dc204bd87174b6c444032a306f7e5c73 | |
parent | 35748654f39a99c226cd14f3b92822eb64bd7037 (diff) | |
download | fastd-822c9e935a25a7590cd99b4c5407bb6596be41b7.tar fastd-822c9e935a25a7590cd99b4c5407bb6596be41b7.zip |
Change xor and xor_a back to work on pointers
For some reason, this makes GCC generate much better code on MIPS with -Os
-rw-r--r-- | src/crypto.h | 10 | ||||
-rw-r--r-- | src/crypto/cipher/blowfish_ctr/builtin/blowfish_ctr.c | 6 | ||||
-rw-r--r-- | src/crypto/mac/ghash/builtin/ghash_builtin.c | 26 | ||||
-rw-r--r-- | src/methods/composed_gmac/composed_gmac.c | 2 | ||||
-rw-r--r-- | src/methods/generic_gcm/generic_gcm.c | 2 | ||||
-rw-r--r-- | src/methods/generic_gmac/generic_gmac.c | 2 |
6 files changed, 26 insertions, 22 deletions
diff --git a/src/crypto.h b/src/crypto.h index 124d06d..af8547d 100644 --- a/src/crypto.h +++ b/src/crypto.h @@ -80,13 +80,13 @@ static inline void secure_memzero(void *s, size_t n) { __asm__ volatile("" : : "m"(s)); } -static inline void xor(fastd_block128_t *x, fastd_block128_t a, fastd_block128_t b) { - x->qw[0] = a.qw[0] ^ b.qw[0]; - x->qw[1] = a.qw[1] ^ b.qw[1]; +static inline void xor(fastd_block128_t *x, const fastd_block128_t *a, const fastd_block128_t *b) { + x->qw[0] = a->qw[0] ^ b->qw[0]; + x->qw[1] = a->qw[1] ^ b->qw[1]; } -static inline void xor_a(fastd_block128_t *x, fastd_block128_t a) { - xor(x, *x, a); +static inline void xor_a(fastd_block128_t *x, const fastd_block128_t *a) { + xor(x, x, a); } static inline bool fastd_true(void) { diff --git a/src/crypto/cipher/blowfish_ctr/builtin/blowfish_ctr.c b/src/crypto/cipher/blowfish_ctr/builtin/blowfish_ctr.c index feb1406..64ea0f1 100644 --- a/src/crypto/cipher/blowfish_ctr/builtin/blowfish_ctr.c +++ b/src/crypto/cipher/blowfish_ctr/builtin/blowfish_ctr.c @@ -267,7 +267,11 @@ static bool blowfish_ctr_crypt(const fastd_cipher_state_t *state, fastd_block128 block.u32[2] = htonl(block.u32[2]); block.u32[3] = htonl(block.u32[3]); - xor(out++, *(in++), block.b); + out->qw[0] = in->qw[0] ^ block.b.qw[0]; + out->qw[1] = in->qw[1] ^ block.b.qw[1]; + + in++; + out++; } return true; diff --git a/src/crypto/mac/ghash/builtin/ghash_builtin.c b/src/crypto/mac/ghash/builtin/ghash_builtin.c index c518663..651c7ed 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, fastd_block128_t in, int n) { +static inline uint8_t shr(fastd_block128_t *out, const 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; @@ -74,11 +74,11 @@ static fastd_mac_state_t* ghash_init(const uint8_t *key) { 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]; @@ -89,8 +89,8 @@ static fastd_mac_state_t* ghash_init(const uint8_t *key) { 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]); } } } @@ -99,8 +99,8 @@ static fastd_mac_state_t* ghash_init(const uint8_t *key) { 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]); } } @@ -112,7 +112,7 @@ static bool ghash_hash(const fastd_mac_state_t *state, fastd_block128_t *out, co 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/methods/composed_gmac/composed_gmac.c b/src/methods/composed_gmac/composed_gmac.c index 25805fa..b3b22d6 100644 --- a/src/methods/composed_gmac/composed_gmac.c +++ b/src/methods/composed_gmac/composed_gmac.c @@ -215,7 +215,7 @@ static bool method_encrypt(fastd_context_t *ctx, fastd_peer_t *peer UNUSED, fast return false; } - xor_a(&outblocks[0], tag); + xor_a(&outblocks[0], &tag); fastd_buffer_free(in); diff --git a/src/methods/generic_gcm/generic_gcm.c b/src/methods/generic_gcm/generic_gcm.c index 345bb61..f1aebd5 100644 --- a/src/methods/generic_gcm/generic_gcm.c +++ b/src/methods/generic_gcm/generic_gcm.c @@ -182,7 +182,7 @@ static bool method_encrypt(fastd_context_t *ctx, fastd_peer_t *peer UNUSED, fast return false; } - xor_a(&outblocks[0], tag); + xor_a(&outblocks[0], &tag); fastd_buffer_free(in); diff --git a/src/methods/generic_gmac/generic_gmac.c b/src/methods/generic_gmac/generic_gmac.c index 825bf48..f1d98ca 100644 --- a/src/methods/generic_gmac/generic_gmac.c +++ b/src/methods/generic_gmac/generic_gmac.c @@ -172,7 +172,7 @@ static bool method_encrypt(fastd_context_t *ctx, fastd_peer_t *peer UNUSED, fast return false; } - xor_a(&outblocks[0], tag); + xor_a(&outblocks[0], &tag); fastd_buffer_free(in); |