Received: by 2002:a05:6a10:9e8c:0:0:0:0 with SMTP id y12csp84222pxx; Wed, 28 Oct 2020 19:03:59 -0700 (PDT) X-Google-Smtp-Source: ABdhPJysCmBgYywuMFaajEYM2rrTGx5eC24bUQ68zasmC02lFk7t/eEUDRWg76FOQBfcFimMwJPn X-Received: by 2002:a17:906:a05a:: with SMTP id bg26mr862820ejb.379.1603937039084; Wed, 28 Oct 2020 19:03:59 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1603937039; cv=none; d=google.com; s=arc-20160816; b=Iq4vH4m0ZUwra/xDtflProSwKtuNCTFEsocYtCm9/56cWdzJcJOGAcYMxX/iwGpLgz Bk8MY50BarsncTZpo9KNtb3nI2jDrgUsUpTnUjkrTPlm71OmCzrtYnCEN8wVn9BDHxNf n377yiCOCxQfboc/rcKtigefJCK/piBUI+3EFf7ydqSRRGkcPfEvniGW7zXusaFSqOo0 Qika6d3+bEYJyBUyRkR9d0SJwsqIcS4vhxwyn5K2OxS6uDzulHDj8HGCXr7WQvfBhuAF QaqSQzeoafo+bVMN8O3IrFcn53QeDDYLrilCFMpV5pnYbM+dUjPbOctS6c2/n5TK8VXn oTmg== 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=Sgos3VZeQH336WxzEU0FsTdzfwhezmNJRKLgQOFBEh01D0mekluv6LyGGq2ggSI6t0 hjMzBxbsjPYqFVRA4mL2HWLAIeztPp6DQwvc2L/HTHHl5r2wUiDzpqRpIeSjpIsJMDof eKIqKzZhc3k+QkqUCncPMU70oS9VsaVJBwp2MH1EXNCEgofa59AzQbX6wkUhrXiERVIx QC5ihv403Ij/0E+FU94o3AeXyy4DrJrejb5rh3BE18obxfGZKK8ddxilJpdPCysDvANq J1rcuXXM9PGKgb/Gf/uPGZejvIgT9+ONBNAY+Q9lkKypR59ztxPsp+/kXm4W/CYjAy5P d3uw== 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 be17si1023900edb.35.2020.10.28.19.03.26; Wed, 28 Oct 2020 19:03:59 -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 S1729557AbgJ1WDB (ORCPT + 99 others); Wed, 28 Oct 2020 18:03:01 -0400 Received: from foss.arm.com ([217.140.110.172]:38792 "EHLO foss.arm.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1729502AbgJ1WCQ (ORCPT ); Wed, 28 Oct 2020 18:02:16 -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 32B3F176A; Wed, 28 Oct 2020 05:34:36 -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 3B9E43F719; Wed, 28 Oct 2020 05:34:34 -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 v2 3/4] dm crypt: switch to EBOIV crypto API template Date: Wed, 28 Oct 2020 14:34:18 +0200 Message-Id: <20201028123420.30623-4-gilad@benyossef.com> X-Mailer: git-send-email 2.28.0 In-Reply-To: <20201028123420.30623-1-gilad@benyossef.com> References: <20201028123420.30623-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