From owner-svn-src-stable-7@FreeBSD.ORG Sun Jan 17 13:36:25 2010 Return-Path: Delivered-To: svn-src-stable-7@freebsd.org Received: from mx1.freebsd.org (mx1.freebsd.org [IPv6:2001:4f8:fff6::34]) by hub.freebsd.org (Postfix) with ESMTP id 8232410656AE; Sun, 17 Jan 2010 13:36:25 +0000 (UTC) (envelope-from bz@FreeBSD.org) Received: from svn.freebsd.org (svn.freebsd.org [IPv6:2001:4f8:fff6::2c]) by mx1.freebsd.org (Postfix) with ESMTP id 570F08FC0C; Sun, 17 Jan 2010 13:36:25 +0000 (UTC) Received: from svn.freebsd.org (localhost [127.0.0.1]) by svn.freebsd.org (8.14.3/8.14.3) with ESMTP id o0HDaPbB037659; Sun, 17 Jan 2010 13:36:25 GMT (envelope-from bz@svn.freebsd.org) Received: (from bz@localhost) by svn.freebsd.org (8.14.3/8.14.3/Submit) id o0HDaPnl037657; Sun, 17 Jan 2010 13:36:25 GMT (envelope-from bz@svn.freebsd.org) Message-Id: <201001171336.o0HDaPnl037657@svn.freebsd.org> From: "Bjoern A. Zeeb" Date: Sun, 17 Jan 2010 13:36:25 +0000 (UTC) To: src-committers@freebsd.org, svn-src-all@freebsd.org, svn-src-stable@freebsd.org, svn-src-stable-7@freebsd.org X-SVN-Group: stable-7 MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Cc: Subject: svn commit: r202478 - stable/7/sys/opencrypto X-BeenThere: svn-src-stable-7@freebsd.org X-Mailman-Version: 2.1.5 Precedence: list List-Id: SVN commit messages for only the 7-stable src tree List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , X-List-Received-Date: Sun, 17 Jan 2010 13:36:25 -0000 Author: bz Date: Sun Jan 17 13:36:25 2010 New Revision: 202478 URL: http://svn.freebsd.org/changeset/base/202478 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/7/sys/opencrypto/cryptosoft.c Directory Properties: stable/7/sys/ (props changed) stable/7/sys/cddl/contrib/opensolaris/ (props changed) stable/7/sys/contrib/dev/acpica/ (props changed) stable/7/sys/contrib/pf/ (props changed) Modified: stable/7/sys/opencrypto/cryptosoft.c ============================================================================== --- stable/7/sys/opencrypto/cryptosoft.c Sun Jan 17 13:36:13 2010 (r202477) +++ stable/7/sys/opencrypto/cryptosoft.c Sun Jan 17 13:36:25 2010 (r202478) @@ -430,7 +430,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; @@ -491,9 +500,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;