summaryrefslogtreecommitdiff
path: root/sys/crypto
diff options
context:
space:
mode:
authorMarkus Friedl <markus@cvs.openbsd.org>2010-12-21 22:24:22 +0000
committerMarkus Friedl <markus@cvs.openbsd.org>2010-12-21 22:24:22 +0000
commit86df92d44041db53c2c85fc444f902224a42a3e0 (patch)
tree6e51b6e0b559573243616d8918896df90cb06e9f /sys/crypto
parent533610cd3b12c41762f0fbaa058c868cc1458b45 (diff)
remove dead code (ivp did always point to iv in the decrypt path).
instead save one bcopy() per block by alternating between two iv buffers; ok mikeb@
Diffstat (limited to 'sys/crypto')
-rw-r--r--sys/crypto/cryptosoft.c52
1 files changed, 14 insertions, 38 deletions
diff --git a/sys/crypto/cryptosoft.c b/sys/crypto/cryptosoft.c
index 394aa4bd378..6efa9185ce6 100644
--- a/sys/crypto/cryptosoft.c
+++ b/sys/crypto/cryptosoft.c
@@ -1,4 +1,4 @@
-/* $OpenBSD: cryptosoft.c,v 1.57 2010/10/06 22:19:20 mikeb Exp $ */
+/* $OpenBSD: cryptosoft.c,v 1.58 2010/12/21 22:24:21 markus Exp $ */
/*
* The author of this code is Angelos D. Keromytis (angelos@cis.upenn.edu)
@@ -94,7 +94,7 @@ swcr_encdec(struct cryptodesc *crd, struct swcr_data *sw, caddr_t buf,
int outtype)
{
unsigned char iv[EALG_MAX_BLOCK_LEN], blk[EALG_MAX_BLOCK_LEN], *idat;
- unsigned char *ivp, piv[EALG_MAX_BLOCK_LEN];
+ unsigned char *ivp, *nivp, iv2[EALG_MAX_BLOCK_LEN];
struct enc_xform *exf;
int i, k, j, blks, ind, count, ivlen;
struct mbuf *m = NULL;
@@ -188,21 +188,15 @@ swcr_encdec(struct cryptodesc *crd, struct swcr_data *sw, caddr_t buf,
* Keep encrypted block for XOR'ing
* with next block
*/
- if (ivp == iv)
- bcopy(blk, piv, blks);
- else
- bcopy(blk, iv, blks);
+ nivp = (ivp == iv) ? iv2 : iv;
+ bcopy(blk, nivp, blks);
exf->decrypt(sw->sw_kschedule, blk);
/* XOR with previous block */
for (j = 0; j < blks; j++)
blk[j] ^= ivp[j];
-
- if (ivp == iv)
- bcopy(piv, iv, blks);
- else
- ivp = iv;
+ ivp = nivp;
}
/* Copy back decrypted block */
@@ -260,21 +254,15 @@ swcr_encdec(struct cryptodesc *crd, struct swcr_data *sw, caddr_t buf,
* Keep encrypted block to be used
* in next block's processing.
*/
- if (ivp == iv)
- bcopy(idat, piv, blks);
- else
- bcopy(idat, iv, blks);
+ nivp = (ivp == iv) ? iv2 : iv;
+ bcopy(idat, nivp, blks);
exf->decrypt(sw->sw_kschedule, idat);
/* XOR with previous block/IV */
for (j = 0; j < blks; j++)
idat[j] ^= ivp[j];
-
- if (ivp == iv)
- bcopy(piv, iv, blks);
- else
- ivp = iv;
+ ivp = nivp;
}
idat += blks;
@@ -327,21 +315,15 @@ swcr_encdec(struct cryptodesc *crd, struct swcr_data *sw, caddr_t buf,
* Keep encrypted block for XOR'ing
* with next block
*/
- if (ivp == iv)
- bcopy(blk, piv, blks);
- else
- bcopy(blk, iv, blks);
+ nivp = (ivp == iv) ? iv2 : iv;
+ bcopy(blk, nivp, blks);
exf->decrypt(sw->sw_kschedule, blk);
/* XOR with previous block */
for (j = 0; j < blks; j++)
blk[j] ^= ivp[j];
-
- if (ivp == iv)
- bcopy(piv, iv, blks);
- else
- ivp = iv;
+ ivp = nivp;
}
/* Copy back decrypted block */
@@ -390,21 +372,15 @@ swcr_encdec(struct cryptodesc *crd, struct swcr_data *sw, caddr_t buf,
* Keep encrypted block to be used
* in next block's processing.
*/
- if (ivp == iv)
- bcopy(idat, piv, blks);
- else
- bcopy(idat, iv, blks);
+ nivp = (ivp == iv) ? iv2 : iv;
+ bcopy(idat, nivp, blks);
exf->decrypt(sw->sw_kschedule, idat);
/* XOR with previous block/IV */
for (j = 0; j < blks; j++)
idat[j] ^= ivp[j];
-
- if (ivp == iv)
- bcopy(piv, iv, blks);
- else
- ivp = iv;
+ ivp = nivp;
}
idat += blks;