From patchwork Thu Jun 27 10:26:35 2019 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Ard Biesheuvel X-Patchwork-Id: 167919 Delivered-To: patch@linaro.org Received: by 2002:a92:4782:0:0:0:0:0 with SMTP id e2csp2148785ilk; Thu, 27 Jun 2019 03:28:15 -0700 (PDT) X-Google-Smtp-Source: APXvYqzgwFZARm0/46LFI55nr66pSsm1fgMzcHxF1J6X0xPAeIecRgsy56MFTl0pC/H6jkT+pwzy X-Received: by 2002:a17:902:8205:: with SMTP id x5mr3815813pln.279.1561631295639; Thu, 27 Jun 2019 03:28:15 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1561631295; cv=none; d=google.com; s=arc-20160816; b=c4FiYhDQ/p0i0sNWc0wKbgLCC85eV47uTPKUHH1jypMf795jLxqs2AEj6sxM2hDIeQ B9AYontFV0J9PoiY3WXR5P7mLXVwpu6lIc2syXCQQotYQ3GMXGY5l9LGHN97dpVAo5QJ 7eod+1ZICqSDNNsKzxuZV4LPi1SUjsMSrld/yOOZIjf1fMghYJDAttCm78Bz/TJHYfjk AXSWdSufvXUKO1TOAG7oI5CctDozPD0leh7kBaMqwUcFAXzdJRErdoAsta4JpZrj3g+f lyhI9Ggdmc8ivh8oux/+5mblXVMbOR9xigDJieoNjQkkH7rUx1uNamBDoFzGlafMG+sQ h4Ew== 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=i5YAml7KVGLr/1+CAScarRaj3NSVjbEGTREd9Bd1Ltw=; b=qnuH2evO7YCGEyEHfxmBZb+Jp15VrRCCCm2sYdrtXCDk3FrP/AwpszI8nWL+rVTSUL rRb0COj5wwW//Cp1geS6IFSH6WMkt73YJSLpQxgPlANfTxTE6t0BJ+0cd2Oyb5T5wfGY cGd25azuL1PJuKekvlXZIqOGdwgiUq2BI59cMqzauCIQE8lK/E/6BIZUh8+R4UB15zG2 qB7y9Hmw9645rcm6Nv3sFDMc6yL+zB/OX2Ch67EL6A9bZyB3iyBLc9mzk0m141IW2iT7 Jw9E1Z4wfsHj/pVAZVZem4TFD3CCXIWfQmy2xjziLzCHFFuv8H1Dj616/AjEn9rTTfDr SgSQ== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@linaro.org header.s=google header.b=tankqLnd; 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 f32si4829522pjg.42.2019.06.27.03.28.15; Thu, 27 Jun 2019 03:28:15 -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=tankqLnd; 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 S1726669AbfF0K2O (ORCPT + 3 others); Thu, 27 Jun 2019 06:28:14 -0400 Received: from mail-wr1-f65.google.com ([209.85.221.65]:44978 "EHLO mail-wr1-f65.google.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1726678AbfF0K2O (ORCPT ); Thu, 27 Jun 2019 06:28:14 -0400 Received: by mail-wr1-f65.google.com with SMTP id r16so49818wrl.11 for ; Thu, 27 Jun 2019 03:28:13 -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=i5YAml7KVGLr/1+CAScarRaj3NSVjbEGTREd9Bd1Ltw=; b=tankqLndRYXGNmAVTZk/Pky4kvmRMq1n2DYXeBLsNcqN8AqdSHFpUqyTNDAsj1gmJ3 wWsscDBDce7G71pfIaDJW2vj6uuiWnJY2MIR+1Bepvhl3DW0DrTSl0bbMYipl6osGYp+ LTJCsAh2bRq+d8e4ZiXJMVqPAWn5EL1ELFMIEUVwCjfbhwBKXwfuFHbE7V7FUhEJyk0s vXzDL4pqqTOPyBpk4+1R/MkGDgHJ+3fPXQhhpeNyUmQ3J4ikBEEEcJNMDjgUGcsexVkM /KBbPTyzrel5SZaIo6rGgvSNbNI2hvOvvbRFzH9NoSCfenQFbucSdGO1BFOK7sa2BMAK wHRg== 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=i5YAml7KVGLr/1+CAScarRaj3NSVjbEGTREd9Bd1Ltw=; b=JeHCI9Q+hslh41z5JQJmwPxqpVf4P1qovPLrRuEQoX6/Nr2xj7LEucagOvgRHcqijB fxuV9u5tOcWpGHmcCVse1DNyj1XSsBztfUmunlnqAG2tqy5HN+30fBx1DRi9UwP0cynW fP3e24I+gfnF5G2dYiUo3jBIyvirdlpPG7DOQheXYwDUlya9wsAaa0nBRiv+armn2EKJ TSBKFA5P+bRSALgCxWYGsChDw9YKT1OeoBCSNUQnq86sugwl445wXytmHY9uHwllFekL QY8TCfp7ZqC4i8xDQ1XMRmgXoP2GiFV0QF6sud5WV3wFn/pbV69y9f3WWdTZG3LRhQkl Zmjw== X-Gm-Message-State: APjAAAXJ673Gz9iBOnqS0O5TzcSU1KKY5kZJX5EaBmTQS/HZHrSMWsyn sWG2dK667J+8lkenxqxTFUwgRZDkYnc= X-Received: by 2002:adf:a143:: with SMTP id r3mr95191wrr.236.1561631292517; Thu, 27 Jun 2019 03:28:12 -0700 (PDT) Received: from localhost.localdomain (aaubervilliers-681-1-8-173.w90-88.abo.wanadoo.fr. [90.88.13.173]) by smtp.gmail.com with ESMTPSA id g2sm5584533wmh.0.2019.06.27.03.28.11 (version=TLS1_3 cipher=AEAD-AES256-GCM-SHA384 bits=256/256); Thu, 27 Jun 2019 03:28:11 -0700 (PDT) From: Ard Biesheuvel To: linux-crypto@vger.kernel.org Cc: herbert@gondor.apana.org.au, ebiggers@kernel.org, Ard Biesheuvel Subject: [PATCH v3 20/32] crypto: arm/aes-ce - provide a synchronous version of ctr(aes) Date: Thu, 27 Jun 2019 12:26:35 +0200 Message-Id: <20190627102647.2992-21-ard.biesheuvel@linaro.org> X-Mailer: git-send-email 2.20.1 In-Reply-To: <20190627102647.2992-1-ard.biesheuvel@linaro.org> References: <20190627102647.2992-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 | 43 ++++++++++++++++++++ 1 file changed, 43 insertions(+) -- 2.20.1 diff --git a/arch/arm/crypto/aes-ce-glue.c b/arch/arm/crypto/aes-ce-glue.c index e6da3e30018b..c3a78c5a5c35 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 + * 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;