Received: by 2002:a05:6a10:9e8c:0:0:0:0 with SMTP id y12csp303781pxx; Thu, 29 Oct 2020 03:06:32 -0700 (PDT) X-Google-Smtp-Source: ABdhPJyNxpWVEtI9hP+PmfkeOS5wTsszmHdH/3CMgKK1vpuUzAZIHkbeONPtahsGm2qddMbYKy58 X-Received: by 2002:a50:cf8f:: with SMTP id h15mr2998552edk.211.1603965991767; Thu, 29 Oct 2020 03:06:31 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1603965991; cv=none; d=google.com; s=arc-20160816; b=O1BIwFurcxkWSUOqxrR/H5sZef2SxLfoP+7JTUX2TwDzmCXNCgtCkCNxAzx8cz3TVL x1LPc3ya2xoKHwe6prndPB7GI5ohZKj9G7DnJekmIJt1dCSGFQqv4rju3kjllfdAUbCh 4M+ZeRbUSoexfRLO9Nlglq7OKvN/TFdxeYo+vnatZL1SGuMyJ1BXFU6u0RjGhR9Bj4oz 41SO2pA3RwTxl6Bbz960DroVkkrDbWWlHQNRFxr3mC5Q2k11LxS1lEPGexyItRKa1QQp ljUGmqhGTWUUAzx+JWZA/eKEMgiH5s0N1Dn95OKc7bIvTh5372k8SvgwL51WesczHqXm bg2w== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:content-transfer-encoding:mime-version :references:in-reply-to:message-id:date:subject:cc:to:from; bh=7CjCmu2ujwqqGeYrVtFnI/c2TifWcpExtc7ENorrRw8=; b=dRG7AfD+9Hv+9bDSCcq7jMQGKXPDjbFoWbVqm0JPvvWQtKgXAKQrJYXDEsOrtQVqYE 4bihFhassoXf5iWO5rvxaaBCLyEEf5WVPht/emuzLbZq52pR+SMvHrXcNfibZlGiQ2HO 40uf/nqXe0HOr79Z1oSwtU1mKg31uzYu3BEfLrppBYTuj9joVr5Cd1qfdyny5pFhAQwx 1EGqR/iVec7Xr2XbeS5FdGPcYNT2vMa+/oJ/H6EqektZkvdS4sy4U9XGqOLuASaXjZad r3Cv0zjV39VUeu1nJ59N0h5sxX+YYUjUCRtnv/EGQXr4frU16skhAQrEbzVVLkxLDooO iXEQ== ARC-Authentication-Results: i=1; mx.google.com; spf=pass (google.com: domain of linux-crypto-owner@vger.kernel.org designates 23.128.96.18 as permitted sender) smtp.mailfrom=linux-crypto-owner@vger.kernel.org Return-Path: Received: from vger.kernel.org (vger.kernel.org. [23.128.96.18]) by mx.google.com with ESMTP id f25si1465073eje.196.2020.10.29.03.06.08; Thu, 29 Oct 2020 03:06:31 -0700 (PDT) Received-SPF: pass (google.com: domain of linux-crypto-owner@vger.kernel.org designates 23.128.96.18 as permitted sender) client-ip=23.128.96.18; Authentication-Results: mx.google.com; spf=pass (google.com: domain of linux-crypto-owner@vger.kernel.org designates 23.128.96.18 as permitted sender) smtp.mailfrom=linux-crypto-owner@vger.kernel.org Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1725943AbgJ2KGE (ORCPT + 99 others); Thu, 29 Oct 2020 06:06:04 -0400 Received: from foss.arm.com ([217.140.110.172]:58668 "EHLO foss.arm.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1725562AbgJ2KGB (ORCPT ); Thu, 29 Oct 2020 06:06:01 -0400 Received: from usa-sjc-imap-foss1.foss.arm.com (unknown [10.121.207.14]) by usa-sjc-mx-foss1.foss.arm.com (Postfix) with ESMTP id 62449139F; Thu, 29 Oct 2020 03:06:00 -0700 (PDT) Received: from e110176-lin.kfn.arm.com (unknown [172.31.20.19]) by usa-sjc-imap-foss1.foss.arm.com (Postfix) with ESMTPSA id 6334E3F66E; Thu, 29 Oct 2020 03:05:58 -0700 (PDT) From: Gilad Ben-Yossef To: Herbert Xu , "David S. Miller" , Alasdair Kergon , Mike Snitzer , dm-devel@redhat.com Cc: Ofir Drang , linux-crypto@vger.kernel.org, linux-kernel@vger.kernel.org Subject: [PATCH v3 3/4] dm crypt: switch to EBOIV crypto API template Date: Thu, 29 Oct 2020 12:05:44 +0200 Message-Id: <20201029100546.28686-4-gilad@benyossef.com> X-Mailer: git-send-email 2.28.0 In-Reply-To: <20201029100546.28686-1-gilad@benyossef.com> References: <20201029100546.28686-1-gilad@benyossef.com> MIME-Version: 1.0 Content-Transfer-Encoding: 8bit Precedence: bulk List-ID: X-Mailing-List: linux-crypto@vger.kernel.org Replace the explicit EBOIV handling in the dm-crypt driver with calls into the crypto API, which now possesses the capability to perform this processing within the crypto subsystem. Signed-off-by: Gilad Ben-Yossef --- drivers/md/dm-crypt.c | 61 ++++++++++++++----------------------------- 1 file changed, 19 insertions(+), 42 deletions(-) diff --git a/drivers/md/dm-crypt.c b/drivers/md/dm-crypt.c index 148960721254..86b7c7ee3225 100644 --- a/drivers/md/dm-crypt.c +++ b/drivers/md/dm-crypt.c @@ -716,47 +716,18 @@ static int crypt_iv_random_gen(struct crypt_config *cc, u8 *iv, return 0; } -static int crypt_iv_eboiv_ctr(struct crypt_config *cc, struct dm_target *ti, - const char *opts) -{ - if (crypt_integrity_aead(cc)) { - ti->error = "AEAD transforms not supported for EBOIV"; - return -EINVAL; - } - - if (crypto_skcipher_blocksize(any_tfm(cc)) != cc->iv_size) { - ti->error = "Block size of EBOIV cipher does " - "not match IV size of block cipher"; - return -EINVAL; - } - - return 0; -} - static int crypt_iv_eboiv_gen(struct crypt_config *cc, u8 *iv, struct dm_crypt_request *dmreq) { - u8 buf[MAX_CIPHER_BLOCKSIZE] __aligned(__alignof__(__le64)); - struct skcipher_request *req; - struct scatterlist src, dst; - struct crypto_wait wait; - int err; - - req = skcipher_request_alloc(any_tfm(cc), GFP_NOIO); - if (!req) - return -ENOMEM; - - memset(buf, 0, cc->iv_size); - *(__le64 *)buf = cpu_to_le64(dmreq->iv_sector * cc->sector_size); - sg_init_one(&src, page_address(ZERO_PAGE(0)), cc->iv_size); - sg_init_one(&dst, iv, cc->iv_size); - skcipher_request_set_crypt(req, &src, &dst, cc->iv_size, buf); - skcipher_request_set_callback(req, 0, crypto_req_done, &wait); - err = crypto_wait_req(crypto_skcipher_encrypt(req), &wait); - skcipher_request_free(req); + /* + * ESSIV encryption of the IV is handled by the crypto API, + * so compute and pass the sector offset here. + */ + memset(iv, 0, cc->iv_size); + *(__le64 *)iv = cpu_to_le64(dmreq->iv_sector * cc->sector_size); - return err; + return 0; } static void crypt_iv_elephant_dtr(struct crypt_config *cc) @@ -771,18 +742,14 @@ static int crypt_iv_elephant_ctr(struct crypt_config *cc, struct dm_target *ti, const char *opts) { struct iv_elephant_private *elephant = &cc->iv_gen_private.elephant; - int r; + int r = 0; elephant->tfm = crypto_alloc_skcipher("ecb(aes)", 0, 0); if (IS_ERR(elephant->tfm)) { r = PTR_ERR(elephant->tfm); elephant->tfm = NULL; - return r; } - r = crypt_iv_eboiv_ctr(cc, ti, NULL); - if (r) - crypt_iv_elephant_dtr(cc); return r; } @@ -1092,7 +1059,6 @@ static struct crypt_iv_operations crypt_iv_random_ops = { }; static struct crypt_iv_operations crypt_iv_eboiv_ops = { - .ctr = crypt_iv_eboiv_ctr, .generator = crypt_iv_eboiv_gen }; @@ -2739,6 +2705,15 @@ static int crypt_ctr_cipher_new(struct dm_target *ti, char *cipher_in, char *key cipher_api = buf; } + if (*ivmode && (!strcmp(*ivmode, "eboiv") || !strcmp(*ivmode, "elephant"))) { + ret = snprintf(buf, CRYPTO_MAX_ALG_NAME, "eboiv(%s)", cipher_api); + if (ret < 0 || ret >= CRYPTO_MAX_ALG_NAME) { + ti->error = "Cannot allocate cipher string"; + return -ENOMEM; + } + cipher_api = buf; + } + cc->key_parts = cc->tfms_count; /* Allocate cipher */ @@ -2817,6 +2792,8 @@ static int crypt_ctr_cipher_old(struct dm_target *ti, char *cipher_in, char *key } ret = snprintf(cipher_api, CRYPTO_MAX_ALG_NAME, "essiv(%s(%s),%s)", chainmode, cipher, *ivopts); + } else if (*ivmode && (!strcmp(*ivmode, "eboiv") || !strcmp(*ivmode, "elephant"))) { + ret = snprintf(cipher_api, CRYPTO_MAX_ALG_NAME, "eboiv(%s(%s))", chainmode, cipher); } else { ret = snprintf(cipher_api, CRYPTO_MAX_ALG_NAME, "%s(%s)", chainmode, cipher); -- 2.28.0