From patchwork Wed Jun 12 12:48:36 2019 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Ard Biesheuvel X-Patchwork-Id: 166562 Delivered-To: patch@linaro.org Received: by 2002:a92:4782:0:0:0:0:0 with SMTP id e2csp3640950ilk; Wed, 12 Jun 2019 05:49:10 -0700 (PDT) X-Google-Smtp-Source: APXvYqwha3EMnlrniNfg3o8D+re1KihB9ubGd0/GFD0X6nxbkOVDLeYwN5Cedk7QgyHgsQcKNg7b X-Received: by 2002:a63:c94f:: with SMTP id y15mr25317139pgg.159.1560343750743; Wed, 12 Jun 2019 05:49:10 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1560343750; cv=none; d=google.com; s=arc-20160816; b=H0KSrtsDOpq1T/AfqcsNDc/4fnPVXsg5NzKPcYDBj2WQ9rotFEcIL4jD7rmc3waZ+Q /zznpwsC3PjzcVqGkt1Tl0zaPz1nEEW8XkA42eiLR3/s3BzXwN2uyqrgIB1QJSPimn5j E/a9+kGnLBAPh6BH+O3Rf6XuzUUwQblnusUzl6fX+rAQEMy2Gc8AB72icfwNY0IUISKN wFzI9vIh0dcjdXeeaMc7Bt3GIuH4S1aXOomcKoP4vy5JhwTXX15dyu6d2euh7VkWuVtR cVV3uMrRT76tVxOYrjLIt09giSTFdMASKX8GHhe9fCx6ctO9RcW27ud3GUrnc3u/YyPz tUuw== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:sender:content-transfer-encoding:mime-version :references:in-reply-to:message-id:date:subject:cc:to:from :dkim-signature; bh=1xxctaVyY+STLE0T/Ia3mG1xDByiyGRaSaAm3A+Hnfc=; b=QtW1BB2J5/tytlyVsDtfoD3esbV72HL1WUumdzG+Y3B4u4um26Y7Ef8wHuXwBOgdnu w3lSpnWUYfCe4q55YTZytaBBmUqOOqds5wY2ld1qyOISqjd4f3VONbdlYRSVkFzg6bcv nAqOzjk1sAHebvOmImiAbcFrTVbbao5BXFmN80MdovOb37xv/zI1ZIXTHGAv3sP6lowN XbrfexrtCbRDwAGKVlis+PTSoE6a1f/OgFhbAa0uu5zcdvKjqwY+w/hh0iqVTTbIta5a BBQBhmtfTOEt4AMEmqIw6EoHVmxQNDGZblfb7bDaFPOFajBfJL64cYwaFVjI76QOKksH SXaA== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@linaro.org header.s=google header.b=tz4lZUGm; spf=pass (google.com: best guess record for domain of linux-crypto-owner@vger.kernel.org designates 209.132.180.67 as permitted sender) smtp.mailfrom=linux-crypto-owner@vger.kernel.org; dmarc=pass (p=NONE sp=NONE dis=NONE) header.from=linaro.org Return-Path: Received: from vger.kernel.org (vger.kernel.org. [209.132.180.67]) by mx.google.com with ESMTP id b14si16011497pgk.423.2019.06.12.05.49.10; Wed, 12 Jun 2019 05:49:10 -0700 (PDT) Received-SPF: pass (google.com: best guess record for domain of linux-crypto-owner@vger.kernel.org designates 209.132.180.67 as permitted sender) client-ip=209.132.180.67; Authentication-Results: mx.google.com; dkim=pass header.i=@linaro.org header.s=google header.b=tz4lZUGm; spf=pass (google.com: best guess record for domain of linux-crypto-owner@vger.kernel.org designates 209.132.180.67 as permitted sender) smtp.mailfrom=linux-crypto-owner@vger.kernel.org; dmarc=pass (p=NONE sp=NONE dis=NONE) header.from=linaro.org Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S2439234AbfFLMtJ (ORCPT + 3 others); Wed, 12 Jun 2019 08:49:09 -0400 Received: from mail-wr1-f67.google.com ([209.85.221.67]:45980 "EHLO mail-wr1-f67.google.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S2439227AbfFLMtJ (ORCPT ); Wed, 12 Jun 2019 08:49:09 -0400 Received: by mail-wr1-f67.google.com with SMTP id f9so16738345wre.12 for ; Wed, 12 Jun 2019 05:49:07 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=linaro.org; s=google; h=from:to:cc:subject:date:message-id:in-reply-to:references :mime-version:content-transfer-encoding; bh=1xxctaVyY+STLE0T/Ia3mG1xDByiyGRaSaAm3A+Hnfc=; b=tz4lZUGm9GNsN5QswSxBu7YXktply7N1ckplmsyGaNzKPqdMjhYQIq5MA5Za8gHjVv hbmHeCSyK9Dv1HCnMTpSoZuYGyLJcOccSyP8R9Wlt5gRPw7cEK4ArZ5pLJnKCI+QeEtT jn0ql/+fmwDUAt+1c2EgEFXX1XuxCczqDAGslmpsFUU2LCQZGEhBEjt6KKYQzuNZM+VI PZQNvwUOv0/D3yTH8JTNF3Oyl65MrIBMnLBLuMDcOYPabmhfCtaAvgK/9SzQCWq2D15L 8yi/Hml1UiDmGFEws/lyBKVDlHJFjsQyUEc8MhCwy90KY9ki2vxhabPaIPfReMKal4nV C12Q== 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:mime-version:content-transfer-encoding; bh=1xxctaVyY+STLE0T/Ia3mG1xDByiyGRaSaAm3A+Hnfc=; b=iImMA1ahyb/c6nZ6b3P8COk8rbhMib4CSondHip2M+1iPVctbH6g0k+ryPVkiF4aXL EaviRYaAQuo31kXGrlsiJC7c+tHAoOL4rsGr7IJ9Wtj9Z17XIZXP8vKJoOEsezUlKpt+ yuTCNVxlsZYi3kt9xU/LWdEt0RFwX88DmOGFcPxJJhUOLBHk+bk++vYJbKiI1RbXLR9e ptAPVV8RUIVkAdBYLcZg6e8tlcBzAIN/RpI/3Cfxt0S0GtvNZhciv1plz5GV66RmOiBK 8TqhMBt9ELQT7POnZWw1ZqCrIjin8H7WzffO8vMDweX/QOTCIcdngPfWwb+uKjDp5iIL /ToQ== X-Gm-Message-State: APjAAAWkbL/U51IF/3X3Z4jMJa8FP3H1MnuYG9mSWbrNC/rADA5o0Y44 vr8flDz937CO89fU2zblX8/vp2ejuUrB+A== X-Received: by 2002:adf:9d81:: with SMTP id p1mr5078018wre.294.1560343746557; Wed, 12 Jun 2019 05:49:06 -0700 (PDT) Received: from sudo.home ([2a01:cb1d:112:6f00:353a:f33a:a393:3ada]) by smtp.gmail.com with ESMTPSA id s8sm28505480wra.55.2019.06.12.05.49.05 (version=TLS1_2 cipher=ECDHE-RSA-AES128-GCM-SHA256 bits=128/128); Wed, 12 Jun 2019 05:49:05 -0700 (PDT) From: Ard Biesheuvel To: linux-crypto@vger.kernel.org Cc: herbert@gondor.apana.org.au, ebiggers@kernel.org, Ard Biesheuvel Subject: [RFC PATCH 18/20] crypto: arm/aes-ce - provide a synchronous version of ctr(aes) Date: Wed, 12 Jun 2019 14:48:36 +0200 Message-Id: <20190612124838.2492-19-ard.biesheuvel@linaro.org> X-Mailer: git-send-email 2.20.1 In-Reply-To: <20190612124838.2492-1-ard.biesheuvel@linaro.org> References: <20190612124838.2492-1-ard.biesheuvel@linaro.org> MIME-Version: 1.0 Sender: linux-crypto-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: linux-crypto@vger.kernel.org AES in CTR mode is used by modes such as GCM and CCM, which are often used in contexts where only synchronous ciphers are permitted. So provide a synchronous version of ctr(aes) based on the existing code. This requires a non-SIMD fallback to deal with invocations occurring from a context where SIMD instructions may not be used. We have a helper for this now in the AES library, so wire that up. Signed-off-by: Ard Biesheuvel --- arch/arm/crypto/aes-ce-glue.c | 36 ++++++++++++++++++++ 1 file changed, 36 insertions(+) -- 2.20.1 diff --git a/arch/arm/crypto/aes-ce-glue.c b/arch/arm/crypto/aes-ce-glue.c index 04ba66903674..cdcc4b09e7db 100644 --- a/arch/arm/crypto/aes-ce-glue.c +++ b/arch/arm/crypto/aes-ce-glue.c @@ -10,6 +10,7 @@ #include #include +#include #include #include #include @@ -292,6 +293,23 @@ static int ctr_encrypt(struct skcipher_request *req) return err; } +static int ctr_encrypt_sync(struct skcipher_request *req) +{ + struct crypto_skcipher *tfm = crypto_skcipher_reqtfm(req); + struct crypto_aes_ctx *ctx = crypto_skcipher_ctx(tfm); + + if (!crypto_simd_usable()) { + struct skcipher_walk walk; + int err; + + err = skcipher_walk_virt(&walk, req, true); + if (err) + return err; + return skcipher_encrypt_aes_ctr(&walk, ctx); + } + return ctr_encrypt(req); +} + static int xts_encrypt(struct skcipher_request *req) { struct crypto_skcipher *tfm = crypto_skcipher_reqtfm(req); @@ -381,6 +399,21 @@ static struct skcipher_alg aes_algs[] = { { .setkey = ce_aes_setkey, .encrypt = ctr_encrypt, .decrypt = ctr_encrypt, +}, { + .base.cra_name = "ctr(aes)", + .base.cra_driver_name = "ctr-aes-ce-sync", + .base.cra_priority = 300 - 1, + .base.cra_blocksize = 1, + .base.cra_ctxsize = sizeof(struct crypto_aes_ctx), + .base.cra_module = THIS_MODULE, + + .min_keysize = AES_MIN_KEY_SIZE, + .max_keysize = AES_MAX_KEY_SIZE, + .ivsize = AES_BLOCK_SIZE, + .chunksize = AES_BLOCK_SIZE, + .setkey = ce_aes_setkey, + .encrypt = ctr_encrypt_sync, + .decrypt = ctr_encrypt_sync, }, { .base.cra_name = "__xts(aes)", .base.cra_driver_name = "__xts-aes-ce", @@ -424,6 +457,9 @@ static int __init aes_init(void) return err; for (i = 0; i < ARRAY_SIZE(aes_algs); i++) { + if (!(aes_algs[i].base.cra_flags & CRYPTO_ALG_INTERNAL)) + continue; + algname = aes_algs[i].base.cra_name + 2; drvname = aes_algs[i].base.cra_driver_name + 2; basename = aes_algs[i].base.cra_driver_name;