summaryrefslogtreecommitdiff
path: root/sys
diff options
context:
space:
mode:
authorMike Belopuhov <mikeb@cvs.openbsd.org>2014-11-12 17:52:03 +0000
committerMike Belopuhov <mikeb@cvs.openbsd.org>2014-11-12 17:52:03 +0000
commitcbdc5a2c9424fd375cb84dc28265c5f1468531ff (patch)
tree409bcf3e51a30d76ee8c01c935427caacad83253 /sys
parenta2e2bd90e50b4e7d27dba3eb5a0a50a97f628863 (diff)
Improve performance of an internal loop by saving up on branching
Pointed out by John-Mark Gurney <jmg at funkthat ! com>, thanks!
Diffstat (limited to 'sys')
-rw-r--r--sys/crypto/gmac.c16
1 files changed, 8 insertions, 8 deletions
diff --git a/sys/crypto/gmac.c b/sys/crypto/gmac.c
index d90f2ceaf4a..eb031546637 100644
--- a/sys/crypto/gmac.c
+++ b/sys/crypto/gmac.c
@@ -1,4 +1,4 @@
-/* $OpenBSD: gmac.c,v 1.3 2011/01/11 15:44:23 deraadt Exp $ */
+/* $OpenBSD: gmac.c,v 1.4 2014/11/12 17:52:02 mikeb Exp $ */
/*
* Copyright (c) 2010 Mike Belopuhov <mike@vantronix.net>
@@ -38,7 +38,7 @@ ghash_gfmul(uint32_t *X, uint32_t *Y, uint32_t *product)
uint32_t v[4];
uint32_t z[4] = { 0, 0, 0, 0};
uint8_t *x = (uint8_t *)X;
- uint32_t mul;
+ uint32_t mask, mul;
int i;
v[0] = betoh32(Y[0]);
@@ -48,12 +48,12 @@ ghash_gfmul(uint32_t *X, uint32_t *Y, uint32_t *product)
for (i = 0; i < GMAC_BLOCK_LEN * 8; i++) {
/* update Z */
- if (x[i >> 3] & (1 << (~i & 7))) {
- z[0] ^= v[0];
- z[1] ^= v[1];
- z[2] ^= v[2];
- z[3] ^= v[3];
- } /* else: we preserve old values */
+ mask = !!(x[i >> 3] & (1 << (~i & 7)));
+ mask = ~(mask - 1);
+ z[0] ^= v[0] & mask;
+ z[1] ^= v[1] & mask;
+ z[2] ^= v[2] & mask;
+ z[3] ^= v[3] & mask;
/* update V */
mul = v[3] & 1;