From owner-svn-src-all@FreeBSD.ORG Fri Oct 22 22:13:12 2010 Return-Path: Delivered-To: svn-src-all@freebsd.org Received: from mx1.freebsd.org (mx1.freebsd.org [IPv6:2001:4f8:fff6::34]) by hub.freebsd.org (Postfix) with ESMTP id E95391065675; Fri, 22 Oct 2010 22:13:11 +0000 (UTC) (envelope-from pjd@FreeBSD.org) Received: from svn.freebsd.org (svn.freebsd.org [IPv6:2001:4f8:fff6::2c]) by mx1.freebsd.org (Postfix) with ESMTP id D80878FC13; Fri, 22 Oct 2010 22:13:11 +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 o9MMDBWU067591; Fri, 22 Oct 2010 22:13:11 GMT (envelope-from pjd@svn.freebsd.org) Received: (from pjd@localhost) by svn.freebsd.org (8.14.3/8.14.3/Submit) id o9MMDBii067587; Fri, 22 Oct 2010 22:13:11 GMT (envelope-from pjd@svn.freebsd.org) Message-Id: <201010222213.o9MMDBii067587@svn.freebsd.org> From: Pawel Jakub Dawidek Date: Fri, 22 Oct 2010 22:13:11 +0000 (UTC) To: src-committers@freebsd.org, svn-src-all@freebsd.org, svn-src-head@freebsd.org X-SVN-Group: head MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Cc: Subject: svn commit: r214225 - head/sys/geom/eli X-BeenThere: svn-src-all@freebsd.org X-Mailman-Version: 2.1.5 Precedence: list List-Id: "SVN commit messages for the entire src tree \(except for " user" and " projects" \)" List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , X-List-Received-Date: Fri, 22 Oct 2010 22:13:12 -0000 Author: pjd Date: Fri Oct 22 22:13:11 2010 New Revision: 214225 URL: http://svn.freebsd.org/changeset/base/214225 Log: Move sc_akeyctx and sc_ivctx initialization to the g_eli_mkey_propagate() function which eliminates code duplication and will ensure proper order of operation. Modified: head/sys/geom/eli/g_eli.c head/sys/geom/eli/g_eli_ctl.c head/sys/geom/eli/g_eli_key.c Modified: head/sys/geom/eli/g_eli.c ============================================================================== --- head/sys/geom/eli/g_eli.c Fri Oct 22 21:38:56 2010 (r214224) +++ head/sys/geom/eli/g_eli.c Fri Oct 22 22:13:11 2010 (r214225) @@ -817,30 +817,6 @@ g_eli_create(struct gctl_req *req, struc */ g_eli_mkey_propagate(sc, mkey); sc->sc_ekeylen = md->md_keylen; - if (sc->sc_flags & G_ELI_FLAG_AUTH) { - /* - * Precalculate SHA256 for HMAC key generation. - * This is expensive operation and we can do it only once now or - * for every access to sector, so now will be much better. - */ - SHA256_Init(&sc->sc_akeyctx); - SHA256_Update(&sc->sc_akeyctx, sc->sc_akey, - sizeof(sc->sc_akey)); - } - /* - * Precalculate SHA256 for IV generation. - * This is expensive operation and we can do it only once now or for - * every access to sector, so now will be much better. - */ - switch (sc->sc_ealgo) { - case CRYPTO_AES_XTS: - break; - default: - SHA256_Init(&sc->sc_ivctx); - SHA256_Update(&sc->sc_ivctx, sc->sc_ivkey, - sizeof(sc->sc_ivkey)); - break; - } LIST_INIT(&sc->sc_workers); Modified: head/sys/geom/eli/g_eli_ctl.c ============================================================================== --- head/sys/geom/eli/g_eli_ctl.c Fri Oct 22 21:38:56 2010 (r214224) +++ head/sys/geom/eli/g_eli_ctl.c Fri Oct 22 22:13:11 2010 (r214225) @@ -882,26 +882,10 @@ g_eli_ctl_resume(struct gctl_req *req, s mtx_lock(&sc->sc_queue_mtx); /* Restore sc_mkey, sc_ekeys, sc_akey and sc_ivkey. */ g_eli_mkey_propagate(sc, mkey); - bzero(mkey, sizeof(mkey)); - bzero(&md, sizeof(md)); - /* Restore sc_akeyctx. */ - if (sc->sc_flags & G_ELI_FLAG_AUTH) { - SHA256_Init(&sc->sc_akeyctx); - SHA256_Update(&sc->sc_akeyctx, sc->sc_akey, - sizeof(sc->sc_akey)); - } - /* Restore sc_ivctx. */ - switch (sc->sc_ealgo) { - case CRYPTO_AES_XTS: - break; - default: - SHA256_Init(&sc->sc_ivctx); - SHA256_Update(&sc->sc_ivctx, sc->sc_ivkey, - sizeof(sc->sc_ivkey)); - break; - } sc->sc_flags &= ~G_ELI_FLAG_SUSPEND; mtx_unlock(&sc->sc_queue_mtx); + bzero(mkey, sizeof(mkey)); + bzero(&md, sizeof(md)); G_ELI_DEBUG(1, "Resumed %s.", pp->name); wakeup(sc); } Modified: head/sys/geom/eli/g_eli_key.c ============================================================================== --- head/sys/geom/eli/g_eli_key.c Fri Oct 22 21:38:56 2010 (r214224) +++ head/sys/geom/eli/g_eli_key.c Fri Oct 22 22:13:11 2010 (r214225) @@ -264,5 +264,30 @@ g_eli_mkey_propagate(struct g_eli_softc /* Generate all encryption keys. */ g_eli_ekeys_generate(sc); } + + if (sc->sc_flags & G_ELI_FLAG_AUTH) { + /* + * Precalculate SHA256 for HMAC key generation. + * This is expensive operation and we can do it only once now or + * for every access to sector, so now will be much better. + */ + SHA256_Init(&sc->sc_akeyctx); + SHA256_Update(&sc->sc_akeyctx, sc->sc_akey, + sizeof(sc->sc_akey)); + } + /* + * Precalculate SHA256 for IV generation. + * This is expensive operation and we can do it only once now or for + * every access to sector, so now will be much better. + */ + switch (sc->sc_ealgo) { + case CRYPTO_AES_XTS: + break; + default: + SHA256_Init(&sc->sc_ivctx); + SHA256_Update(&sc->sc_ivctx, sc->sc_ivkey, + sizeof(sc->sc_ivkey)); + break; + } } #endif