From patchwork Thu Oct 29 10:05:44 2020 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Gilad Ben-Yossef X-Patchwork-Id: 319367 Delivered-To: patch@linaro.org Received: by 2002:a92:7b12:0:0:0:0:0 with SMTP id w18csp310462ilc; Thu, 29 Oct 2020 03:06:06 -0700 (PDT) X-Google-Smtp-Source: ABdhPJzkcX3lCG8UXjc0Ry/rk+trA36fqPde5oSI2PCXharX7cY4cJm36VG4Ejh7iit40r0Po44t X-Received: by 2002:a17:906:1a11:: with SMTP id i17mr3133973ejf.381.1603965965802; Thu, 29 Oct 2020 03:06:05 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1603965965; cv=none; d=google.com; s=arc-20160816; b=ncb5X0wsJESivtnn7i9dvCg1Yr33vUELPjAs1wkPf4igZ0d9Ue006T2snOjSXvXhhS Ykr1wLhZtrygp2Lk7DIxyQ+pAkbj8iHooer1MP3Zh9n3iTjH3kBZncGp0qioYJZaXmvg tmjRoA6XxUIkxLidAQOzwB9Y1Xq5DTKYasCiyysQ/vlmiiiToXdmnwRrpqQtlvqgwzPC fXU2tO2Axy8nZEdlKRjJOZ6e337FFFcF70nqxyD2KR5s/GnwDNmh4yQ2QyYYoFyLtLtb pi2FEq2Q4bWJ9OFK0/ddHROPqIEL/3AdunjnY+sZ/hhbtWAq4lorzNBeha8qH4Owdg1b Axgg== 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 89si1558072edy.301.2020.10.29.03.06.05; Thu, 29 Oct 2020 03:06:05 -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 + 2 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 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(-) -- 2.28.0 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);