summaryrefslogtreecommitdiffstats
path: root/sys/opencrypto
diff options
context:
space:
mode:
authorbz <bz@FreeBSD.org>2010-01-09 15:43:47 +0000
committerbz <bz@FreeBSD.org>2010-01-09 15:43:47 +0000
commit60abca0fe5131e0a3144aa79287b5a3ad5cc2329 (patch)
treed165134da5538996230c750fde58556c452cabcc /sys/opencrypto
parent1634b4cdc45804e920c59295508bf4f20aae1c64 (diff)
downloadFreeBSD-src-60abca0fe5131e0a3144aa79287b5a3ad5cc2329.zip
FreeBSD-src-60abca0fe5131e0a3144aa79287b5a3ad5cc2329.tar.gz
Add comments trying to explain what bad things happen here, i.e.
how hashed MD5/SHA are implemented, abusing Final() for padding and sw_octx to transport the key from the beginning to the end. Enlightened about what was going on here by: cperciva Reviewed by: cperciva MFC After: 3 days X-MFC with: r187826 PR: kern/126468
Diffstat (limited to 'sys/opencrypto')
-rw-r--r--sys/opencrypto/cryptosoft.c19
1 files changed, 18 insertions, 1 deletions
diff --git a/sys/opencrypto/cryptosoft.c b/sys/opencrypto/cryptosoft.c
index 97b73a2..a404cbc 100644
--- a/sys/opencrypto/cryptosoft.c
+++ b/sys/opencrypto/cryptosoft.c
@@ -434,7 +434,16 @@ swcr_authprepare(struct auth_hash *axf, struct swcr_data *sw, u_char *key,
case CRYPTO_MD5_KPDK:
case CRYPTO_SHA1_KPDK:
{
- /* We need a buffer that can hold an md5 and a sha1 result. */
+ /*
+ * We need a buffer that can hold an md5 and a sha1 result
+ * just to throw it away.
+ * What we do here is the initial part of:
+ * ALGO( key, keyfill, .. )
+ * adding the key to sw_ictx and abusing Final() to get the
+ * "keyfill" padding.
+ * In addition we abuse the sw_octx to save the key to have
+ * it to be able to append it at the end in swcr_authcompute().
+ */
u_char buf[SHA1_RESULTLEN];
sw->sw_klen = klen;
@@ -495,9 +504,17 @@ swcr_authcompute(struct cryptodesc *crd, struct swcr_data *sw, caddr_t buf,
case CRYPTO_MD5_KPDK:
case CRYPTO_SHA1_KPDK:
+ /* If we have no key saved, return error. */
if (sw->sw_octx == NULL)
return EINVAL;
+ /*
+ * Add the trailing copy of the key (see comment in
+ * swcr_authprepare()) after the data:
+ * ALGO( .., key, algofill )
+ * and let Final() do the proper, natural "algofill"
+ * padding.
+ */
axf->Update(&ctx, sw->sw_octx, sw->sw_klen);
axf->Final(aalg, &ctx);
break;
OpenPOWER on IntegriCloud