From patchwork Thu Mar 16 14:39:42 2017 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Milan Broz X-Patchwork-Id: 9628425 X-Patchwork-Delegate: snitzer@redhat.com Return-Path: Received: from mail.wl.linuxfoundation.org (pdx-wl-mail.web.codeaurora.org [172.30.200.125]) by pdx-korg-patchwork.web.codeaurora.org (Postfix) with ESMTP id 3FC1160244 for ; Thu, 16 Mar 2017 14:40:34 +0000 (UTC) Received: from mail.wl.linuxfoundation.org (localhost [127.0.0.1]) by mail.wl.linuxfoundation.org (Postfix) with ESMTP id 3374E2857D for ; Thu, 16 Mar 2017 14:40:34 +0000 (UTC) Received: by mail.wl.linuxfoundation.org (Postfix, from userid 486) id 286EA285EB; Thu, 16 Mar 2017 14:40:34 +0000 (UTC) X-Spam-Checker-Version: SpamAssassin 3.3.1 (2010-03-16) on pdx-wl-mail.web.codeaurora.org X-Spam-Level: X-Spam-Status: No, score=-6.3 required=2.0 tests=BAYES_00, DKIM_ADSP_CUSTOM_MED, DKIM_SIGNED, FREEMAIL_FROM, RCVD_IN_DNSWL_HI, RCVD_IN_SORBS_SPAM, T_DKIM_INVALID autolearn=ham version=3.3.1 Received: from mx1.redhat.com (mx1.redhat.com [209.132.183.28]) (using TLSv1.2 with cipher DHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by mail.wl.linuxfoundation.org (Postfix) with ESMTPS id 259E5285A1 for ; Thu, 16 Mar 2017 14:40:32 +0000 (UTC) Received: from smtp.corp.redhat.com (int-mx06.intmail.prod.int.phx2.redhat.com [10.5.11.16]) (using TLSv1.2 with cipher AECDH-AES256-SHA (256/256 bits)) (No client certificate requested) by mx1.redhat.com (Postfix) with ESMTPS id 202243B709; Thu, 16 Mar 2017 14:40:31 +0000 (UTC) DMARC-Filter: OpenDMARC Filter v1.3.2 mx1.redhat.com 202243B709 Authentication-Results: ext-mx06.extmail.prod.ext.phx2.redhat.com; dmarc=fail (p=none dis=none) header.from=gmail.com Authentication-Results: ext-mx06.extmail.prod.ext.phx2.redhat.com; spf=pass smtp.mailfrom=dm-devel-bounces@redhat.com DKIM-Filter: OpenDKIM Filter v2.11.0 mx1.redhat.com 202243B709 Authentication-Results: mx1.redhat.com; dkim=fail reason="signature verification failed" (2048-bit key) header.d=gmail.com header.i=@gmail.com header.b="eg7h7IHe" Received: from colo-mx.corp.redhat.com (unknown [10.5.11.21]) by smtp.corp.redhat.com (Postfix) with ESMTPS id EB6225C888; Thu, 16 Mar 2017 14:40:29 +0000 (UTC) Received: from lists01.pubmisc.prod.ext.phx2.redhat.com (lists01.pubmisc.prod.ext.phx2.redhat.com [10.5.19.33]) by colo-mx.corp.redhat.com (Postfix) with ESMTP id B54825EC66; Thu, 16 Mar 2017 14:40:28 +0000 (UTC) Received: from smtp.corp.redhat.com (int-mx05.intmail.prod.int.phx2.redhat.com [10.5.11.15]) by lists01.pubmisc.prod.ext.phx2.redhat.com (8.13.8/8.13.8) with ESMTP id v2GEeA1Z029454 for ; Thu, 16 Mar 2017 10:40:10 -0400 Received: by smtp.corp.redhat.com (Postfix) id 8272BC0D80; Thu, 16 Mar 2017 14:40:10 +0000 (UTC) Delivered-To: dm-devel@redhat.com Received: from mx1.redhat.com (ext-mx09.extmail.prod.ext.phx2.redhat.com [10.5.110.38]) by smtp.corp.redhat.com (Postfix) with ESMTPS id 7BD28627D9 for ; Thu, 16 Mar 2017 14:40:07 +0000 (UTC) Received: from mail-wr0-f194.google.com (mail-wr0-f194.google.com [209.85.128.194]) (using TLSv1.2 with cipher ECDHE-RSA-AES128-GCM-SHA256 (128/128 bits)) (No client certificate requested) by mx1.redhat.com (Postfix) with ESMTPS id 8099163141 for ; Thu, 16 Mar 2017 14:40:06 +0000 (UTC) DMARC-Filter: OpenDMARC Filter v1.3.2 mx1.redhat.com 8099163141 Authentication-Results: ext-mx09.extmail.prod.ext.phx2.redhat.com; dmarc=pass (p=none dis=none) header.from=gmail.com Authentication-Results: ext-mx09.extmail.prod.ext.phx2.redhat.com; spf=pass smtp.mailfrom=gmazyland@gmail.com DKIM-Filter: OpenDKIM Filter v2.11.0 mx1.redhat.com 8099163141 Received: by mail-wr0-f194.google.com with SMTP id l37so6168094wrc.3 for ; Thu, 16 Mar 2017 07:40:05 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20161025; h=from:to:cc:subject:date:message-id:in-reply-to:references :in-reply-to:references; bh=D61uWMYL9gioPeSPRuN4StJr+twgULrNVJXojSk2pjs=; b=eg7h7IHeyuSr1p2jb8DNW/0uP2rodt1RGzzLNkUYJcmCCPa4jF/qbrbT3ORBoq+jUC GdbTElJtNBcEY49jQNj132ZsROSVCobx/ylMeWbBNehZaN7syI6qordkU4I0dPxY4i2B WPVAs5JlqvGnrOd/dGzHE9zgMIGQseqn9GVdx4W4UE6JgSAUsKnoD2qPVzezGUxFY14a wGioPHJM5rtY5S5qtVh/MpzE6PPHdoQ1EOWNl7G5YxSBIvs47HwtYnrGOL9uWDM6A25H 3eek1nAShQal72agugv+nncf7yMS8MqAVqwsFf55CwuvNAT96cMeimlLT7nVzNAw2cTh d81w== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20161025; h=x-gm-message-state:from:to:cc:subject:date:message-id:in-reply-to :references:in-reply-to:references; bh=D61uWMYL9gioPeSPRuN4StJr+twgULrNVJXojSk2pjs=; b=l1EZ8lV8hdOB6dbu3739NBImm3512eoT7ekiXq6INXaSQZbtQCzhQGdUZvCeSPX7KA 1Ip7TimcHItfjSfFVHQK6/oCGFMYQ/ZCI1qdZpdiVXHbpMvL9plmf5awsxcB9QvJsBX5 eG6RSJjV+vlJR6QW9e3LTiXgaREBusW57VTsIR7xKP3HqLnxctajO9BLNMziKuB6n56F ebeBR/0uSZbf9ZjroRwoLaSS39M/2hhhr4kOZZHKmraDr0nybccwL7wu6kxOPRgb+N5M e9Oocw9v15DqDMSVXKzJ9ge87vkBve4vU2aAQ6cDhj/2PjWI1N2GlBdcb0oRWagqSkn+ DJIg== X-Gm-Message-State: AFeK/H1+2Eqhvb8nAMegipeEiu4rYZJSWHrUH4MA923GZIyi8Px4Bze/Fzm9IhvSmlpYww== X-Received: by 10.223.146.195 with SMTP id 61mr7884563wrn.91.1489675204230; Thu, 16 Mar 2017 07:40:04 -0700 (PDT) Received: from merlot.mazyland.net (nat-pool-brq-t.redhat.com. [213.175.37.10]) by smtp.googlemail.com with ESMTPSA id i203sm4553466wmf.12.2017.03.16.07.40.03 (version=TLS1_2 cipher=ECDHE-RSA-AES128-GCM-SHA256 bits=128/128); Thu, 16 Mar 2017 07:40:03 -0700 (PDT) From: Milan Broz To: dm-devel@redhat.com Date: Thu, 16 Mar 2017 15:39:42 +0100 Message-Id: <20170316143944.19843-6-gmazyland@gmail.com> In-Reply-To: <20170316143944.19843-1-gmazyland@gmail.com> References: <20170316143944.19843-1-gmazyland@gmail.com> In-Reply-To: References: X-Greylist: Sender IP whitelisted, not delayed by milter-greylist-4.5.16 (mx1.redhat.com [10.5.110.38]); Thu, 16 Mar 2017 14:40:06 +0000 (UTC) X-Greylist: inspected by milter-greylist-4.5.16 (mx1.redhat.com [10.5.110.38]); Thu, 16 Mar 2017 14:40:06 +0000 (UTC) for IP:'209.85.128.194' DOMAIN:'mail-wr0-f194.google.com' HELO:'mail-wr0-f194.google.com' FROM:'gmazyland@gmail.com' RCPT:'' X-RedHat-Spam-Score: -1.71 (BAYES_50, DCC_REPUT_13_19, DKIM_SIGNED, DKIM_VALID, DKIM_VALID_AU, FREEMAIL_FROM, RCVD_IN_DNSWL_NONE, RCVD_IN_MSPIKE_H2, RCVD_IN_SORBS_SPAM, SPF_PASS) 209.85.128.194 mail-wr0-f194.google.com 209.85.128.194 mail-wr0-f194.google.com X-Scanned-By: MIMEDefang 2.78 on 10.5.110.38 X-Scanned-By: MIMEDefang 2.79 on 10.5.11.15 X-loop: dm-devel@redhat.com Cc: Milan Broz Subject: [dm-devel] [PATCH 5/7] dm-crypt: Parse cipher specification according to AEAD flag. X-BeenThere: dm-devel@redhat.com X-Mailman-Version: 2.1.12 Precedence: junk List-Id: device-mapper development List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , MIME-Version: 1.0 Sender: dm-devel-bounces@redhat.com Errors-To: dm-devel-bounces@redhat.com X-Scanned-By: MIMEDefang 2.79 on 10.5.11.16 X-Greylist: Sender IP whitelisted, not delayed by milter-greylist-4.5.16 (mx1.redhat.com [10.5.110.30]); Thu, 16 Mar 2017 14:40:32 +0000 (UTC) X-Virus-Scanned: ClamAV using ClamSMTP This patch siplifies allocation of HMAC composed mode by parsing the new cipher format directly. For native AEAD mode (like GCM), we can use crypto_tfm_alg_name() API to get the cipher specification, for HMAC composed mode we need to parse crypto API string to get cipher mode nested in specification. Signed-off-by: Milan Broz --- drivers/md/dm-crypt.c | 49 +++++++++++++++++-------------------------------- 1 file changed, 17 insertions(+), 32 deletions(-) diff --git a/drivers/md/dm-crypt.c b/drivers/md/dm-crypt.c index 48e8dfe91c53..3a4bf5791a3b 100644 --- a/drivers/md/dm-crypt.c +++ b/drivers/md/dm-crypt.c @@ -873,12 +873,12 @@ static bool crypt_integrity_aead(struct crypt_config *cc) static bool crypt_integrity_hmac(struct crypt_config *cc) { - return test_bit(CRYPT_MODE_INTEGRITY_HMAC, &cc->cipher_flags); + return crypt_integrity_aead(cc) && cc->key_mac_size; } static bool crypt_integrity_mode(struct crypt_config *cc) { - return crypt_integrity_aead(cc) || crypt_integrity_hmac(cc); + return crypt_integrity_aead(cc); } /* Get sg containing data */ @@ -1879,27 +1879,12 @@ static int crypt_alloc_tfms_skcipher(struct crypt_config *cc, char *ciphermode) static int crypt_alloc_tfms_aead(struct crypt_config *cc, char *ciphermode) { - char *authenc = NULL; int err; cc->cipher_tfm.tfms = kmalloc(sizeof(struct crypto_aead *), GFP_KERNEL); if (!cc->cipher_tfm.tfms) return -ENOMEM; - /* Compose AEAD cipher with autenc(authenticator,cipher) structure */ - if (crypt_integrity_hmac(cc)) { - authenc = kmalloc(CRYPTO_MAX_ALG_NAME, GFP_KERNEL); - if (!authenc) - return -ENOMEM; - err = snprintf(authenc, CRYPTO_MAX_ALG_NAME, - "authenc(%s,%s)", cc->cipher_auth, ciphermode); - if (err < 0) { - kzfree(authenc); - return err; - } - ciphermode = authenc; - } - cc->cipher_tfm.tfms_aead[0] = crypto_alloc_aead(ciphermode, 0, 0); if (IS_ERR(cc->cipher_tfm.tfms_aead[0])) { err = PTR_ERR(cc->cipher_tfm.tfms_aead[0]); @@ -1907,7 +1892,6 @@ static int crypt_alloc_tfms_aead(struct crypt_config *cc, char *ciphermode) return err; } - kzfree(authenc); return 0; } @@ -1964,13 +1948,13 @@ static int crypt_setkey(struct crypt_config *cc) subkey_size - cc->key_mac_size, cc->key_mac_size); for (i = 0; i < cc->tfms_count; i++) { - if (crypt_integrity_aead(cc)) - r = crypto_aead_setkey(cc->cipher_tfm.tfms_aead[i], - cc->key + (i * subkey_size), - subkey_size); - else if (crypt_integrity_hmac(cc)) + if (crypt_integrity_hmac(cc)) r = crypto_aead_setkey(cc->cipher_tfm.tfms_aead[i], cc->authenc_key, crypt_authenckey_size(cc)); + else if (crypt_integrity_aead(cc)) + r = crypto_aead_setkey(cc->cipher_tfm.tfms_aead[i], + cc->key + (i * subkey_size), + subkey_size); else r = crypto_skcipher_setkey(cc->cipher_tfm.tfms[i], cc->key + (i * subkey_size), @@ -2205,14 +2189,6 @@ static int crypt_ctr_ivmode(struct dm_target *ti, const char *ivmode) else cc->iv_size = crypto_skcipher_ivsize(any_tfm(cc)); - if (crypt_integrity_hmac(cc)) { - cc->authenc_key = kmalloc(crypt_authenckey_size(cc), GFP_KERNEL); - if (!cc->authenc_key) { - ti->error = "Error allocating authenc key space"; - return -ENOMEM; - } - } - if (cc->iv_size) /* at least a 64 bit sector number should fit in our buffer */ cc->iv_size = max(cc->iv_size, @@ -2270,9 +2246,18 @@ static int crypt_ctr_ivmode(struct dm_target *ti, const char *ivmode) */ static int crypt_ctr_blkdev_cipher(struct crypt_config *cc) { - const char *alg_name = crypto_tfm_alg_name(crypto_skcipher_tfm(any_tfm(cc))); + const char *alg_name = NULL; char *start, *end; + if (crypt_integrity_aead(cc)) { + if (!(alg_name = crypto_tfm_alg_name(crypto_aead_tfm(any_tfm_aead(cc))))) + return -EINVAL; + if (crypt_integrity_hmac(cc) && !(alg_name = strchr(alg_name, ','))) + return -EINVAL; + alg_name++; + } else if (!(alg_name = crypto_tfm_alg_name(crypto_skcipher_tfm(any_tfm(cc))))) + return -EINVAL; + start = strchr(alg_name, '('); end = strchr(alg_name, ')');