From patchwork Tue Jul 2 19:41:38 2019 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Ard Biesheuvel X-Patchwork-Id: 168366 Delivered-To: patch@linaro.org Received: by 2002:a92:4782:0:0:0:0:0 with SMTP id e2csp4653613ilk; Tue, 2 Jul 2019 12:42:40 -0700 (PDT) X-Google-Smtp-Source: APXvYqzhmVbQCrst3lcnkQjR4QKjw94yUZYzsiswUri71phtoOS1HCzSn25AXRO3+PR4pKG1ndOG X-Received: by 2002:a17:90a:de02:: with SMTP id m2mr7541135pjv.18.1562096560266; Tue, 02 Jul 2019 12:42:40 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1562096560; cv=none; d=google.com; s=arc-20160816; b=q0uZ3gXdc8sCqNE6KkDowrFTcWQ6XtmtfYoRTDCFmC2vQrlpNJtNvZZN33U10wBaSy +S36a06jZig/ns0mBg5zjLK/+dNVdf0B4G8tVUWeoKvG83Q2OShA34zsbVafXePXcvEF ifkCZiz32K2ct+C5iQ3q1Gq57niK6GZK+DVdx5xNasaUepU9Tleg1e8wf72mhp9MRruH fO0qkhBbEHPEb6JvtyfZ/zCNHMJf9m9y5KMk2HQ9eioKhNofmagUtEzUdv3T5QYVa3Ui PMPAMbFXCRIQo6zQbJmi8RvtWx+gWhEpCVKcFC32GUoUP95Eajb34MnAqP7+hK5279fD M+fQ== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:sender:references:in-reply-to:message-id:date :subject:cc:to:from:dkim-signature; bh=9R634f5tUJpvqy1jJF6+TjW/ZQOJkrwjqwK24wF4gE4=; b=HwBgcWckanczUhWvQdqtS33nUG/+ts7FprGt5oNId9M/ysXKRrf3Uu+gYpVANOQkgk 3hhCFH+ekSJlLxC3joKTSxqU9C9VGqyi090lLHa+RQjdOYb8lGBzlFOZxjtt4lkhOgoH 3cKZ5EHqLF1N52ZSmNimAOsPuROxf9cwqUT+itgTXSnd7Jgqzw9b1caPOrHiFiPdHQRb q0zCFVt1m/ai4jkB7UKPjEesJITdmoVCG0/TnM47sAQVMjdVb7yQv1DK0II49ZZM69lG 0Ahaujjk0l8kPbvx3KP50aiyfKOkOE/216MkUH1cG5s1PrupuZbz+6VSAVrWyVfq/MtW nWwA== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@linaro.org header.s=google header.b=XNauRQ8V; 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 x13si13373092pgh.116.2019.07.02.12.42.40; Tue, 02 Jul 2019 12:42:40 -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=XNauRQ8V; 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 S1727087AbfGBTmj (ORCPT + 3 others); Tue, 2 Jul 2019 15:42:39 -0400 Received: from mail-lj1-f194.google.com ([209.85.208.194]:37922 "EHLO mail-lj1-f194.google.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1727069AbfGBTmj (ORCPT ); Tue, 2 Jul 2019 15:42:39 -0400 Received: by mail-lj1-f194.google.com with SMTP id r9so18181160ljg.5 for ; Tue, 02 Jul 2019 12:42:38 -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; bh=9R634f5tUJpvqy1jJF6+TjW/ZQOJkrwjqwK24wF4gE4=; b=XNauRQ8VO6r2djNte89iUcIO+FGn0a93v3jW5RP0j4XZji/tyXbEkoalx5RSJKGzCR 1D4GgukKAfMxPJsaEnlvIhCS1MdbiNwtwQPWCQ/llgvgB6ltZmxNftph0BvIeV3T3QkD M3/YaEYkRTg3vvnjqYTY/xwPzZxQjftwfca7T8F8FNy5trVQpWOPL1aJah34GVzVu6Qv NVDTvj5L5iMarSbkd8PwZKA4mN2+8K20pv+RerxLGO6Xn/0/sgGY0s7s3FCOQIfoI/eF /o2Y8jUAlG2M6+jG1CDi5dc6jL8NOJEmqqwzlOkaKfiJYRckpUUxXRSIa9YE1Tp1FB4s LedA== 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; bh=9R634f5tUJpvqy1jJF6+TjW/ZQOJkrwjqwK24wF4gE4=; b=JC07bGJll8+xcLuOdHDhFaMuOY4NJoT9R/jOFVek1qfpqyWNC4X97nVgYin5HZG6mf hb6ZZTLCFi8+V9caEkmxAGHbt5AqfANVqE5G+xlEs1nmSgcwVEOGbKrMyDTI/r4cZWd7 p9kUBrCtRHqFa9MqfjDGw86eE08+dEUxjY/9WFJA+C3hMHH+EWx0/c2d56Aucbq2jIHy Zj6rlynqAHweCfXSdmSAiXIqbxhnltT1pZ4f5qUV7y+U5wWtLpdSY3djAXnxQp0tU3Rh JWqFDnLuf+kSahYW/8KxtRMJ/AxlYIJzxwsUX93MpuRgAS31gR99DIY4yUyKCcLlvzgK 8xOA== X-Gm-Message-State: APjAAAV2pfpzJUpLEZ6lag1Sje0TINyyEC7VkqvyLuvzvBVEcA186gGa SHvoacaZdymnyp52pjOmDgJ532TYjcN7Jfss X-Received: by 2002:a2e:a0cf:: with SMTP id f15mr18583670ljm.180.1562096557122; Tue, 02 Jul 2019 12:42:37 -0700 (PDT) Received: from e111045-lin.arm.com (89-212-78-239.static.t-2.net. [89.212.78.239]) by smtp.gmail.com with ESMTPSA id 24sm4475163ljs.63.2019.07.02.12.42.35 (version=TLS1_3 cipher=AEAD-AES256-GCM-SHA384 bits=256/256); Tue, 02 Jul 2019 12:42:36 -0700 (PDT) From: Ard Biesheuvel To: linux-crypto@vger.kernel.org Cc: herbert@gondor.apana.org.au, ebiggers@google.com, Ard Biesheuvel Subject: [PATCH v4 20/32] crypto: arm/aes-ce - provide a synchronous version of ctr(aes) Date: Tue, 2 Jul 2019 21:41:38 +0200 Message-Id: <20190702194150.10405-21-ard.biesheuvel@linaro.org> X-Mailer: git-send-email 2.17.1 In-Reply-To: <20190702194150.10405-1-ard.biesheuvel@linaro.org> References: <20190702194150.10405-1-ard.biesheuvel@linaro.org> 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 | 43 ++++++++++++++++++++ 1 file changed, 43 insertions(+) -- 2.17.1 diff --git a/arch/arm/crypto/aes-ce-glue.c b/arch/arm/crypto/aes-ce-glue.c index e6da3e30018b..1d93da29d03a 100644 --- a/arch/arm/crypto/aes-ce-glue.c +++ b/arch/arm/crypto/aes-ce-glue.c @@ -10,8 +10,10 @@ #include #include +#include #include #include +#include #include #include #include @@ -289,6 +291,29 @@ static int ctr_encrypt(struct skcipher_request *req) return err; } +static void ctr_encrypt_one(struct crypto_skcipher *tfm, const u8 *src, u8 *dst) +{ + struct crypto_aes_ctx *ctx = crypto_skcipher_ctx(tfm); + unsigned long flags; + + /* + * Temporarily disable interrupts to avoid races where + * cachelines are evicted when the CPU is interrupted + * to do something else. + */ + local_irq_save(flags); + aes_encrypt(ctx, dst, src); + local_irq_restore(flags); +} + +static int ctr_encrypt_sync(struct skcipher_request *req) +{ + if (!crypto_simd_usable()) + return crypto_ctr_encrypt_walk(req, ctr_encrypt_one); + + return ctr_encrypt(req); +} + static int xts_encrypt(struct skcipher_request *req) { struct crypto_skcipher *tfm = crypto_skcipher_reqtfm(req); @@ -378,6 +403,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", @@ -421,6 +461,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;