Skip site navigation (1)Skip section navigation (2)
Date:      Sun, 17 Jan 2010 13:36:13 +0000 (UTC)
From:      "Bjoern A. Zeeb" <bz@FreeBSD.org>
To:        src-committers@freebsd.org, svn-src-all@freebsd.org, svn-src-stable@freebsd.org, svn-src-stable-8@freebsd.org
Subject:   svn commit: r202477 - stable/8/sys/opencrypto
Message-ID:  <201001171336.o0HDaDjQ037585@svn.freebsd.org>

next in thread | raw e-mail | index | archive | help
Author: bz
Date: Sun Jan 17 13:36:13 2010
New Revision: 202477
URL: http://svn.freebsd.org/changeset/base/202477

Log:
  MFC r201898:
    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

Modified:
  stable/8/sys/opencrypto/cryptosoft.c
Directory Properties:
  stable/8/sys/   (props changed)
  stable/8/sys/amd64/include/xen/   (props changed)
  stable/8/sys/cddl/contrib/opensolaris/   (props changed)
  stable/8/sys/contrib/dev/acpica/   (props changed)
  stable/8/sys/contrib/pf/   (props changed)
  stable/8/sys/dev/xen/xenpci/   (props changed)

Modified: stable/8/sys/opencrypto/cryptosoft.c
==============================================================================
--- stable/8/sys/opencrypto/cryptosoft.c	Sun Jan 17 13:32:14 2010	(r202476)
+++ stable/8/sys/opencrypto/cryptosoft.c	Sun Jan 17 13:36:13 2010	(r202477)
@@ -434,7 +434,16 @@ swcr_authprepare(struct auth_hash *axf, 
 	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,
 
 	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;



Want to link to this message? Use this URL: <https://mail-archive.FreeBSD.org/cgi/mid.cgi?201001171336.o0HDaDjQ037585>