From patchwork Wed Oct 2 14:16:56 2019 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Ard Biesheuvel X-Patchwork-Id: 175001 Delivered-To: patch@linaro.org Received: by 2002:a92:7e96:0:0:0:0:0 with SMTP id q22csp818073ill; Wed, 2 Oct 2019 07:17:46 -0700 (PDT) X-Google-Smtp-Source: APXvYqyw/UjiNuvb8eHcaABWag6p3uUPb8xYcNRAm7ySKxx0nC0lU+NC5vWu8mCpMCpFwvJuy9lU X-Received: by 2002:a17:906:7fda:: with SMTP id r26mr3326692ejs.170.1570025865900; Wed, 02 Oct 2019 07:17:45 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1570025865; cv=none; d=google.com; s=arc-20160816; b=yxU8TXAGrm97NNIkuhOV/6qT86pkd6Z51coR76Uwn7AgoliNKfirm7mopu08dSZq8d tkkkyxLRcNkqewMd5KEsaTkxzWD1yjaz84VoC4vVpwr5Vrld2rCPgskJblv4/vZkav45 z62dDnNQv9XFm8khhVbe6+4YOJ+Mj0LiBnL5TJ3jqaU/f3AyW0OFK3Fb1/Y+PFQUN0PF WopAXhN5zXcsWu8VgUVTPl3klBue79mpMiwf8wpUyonhc06wJW5b0K+9gyy8cCRuLvg5 xEhvLzP3AIbIIHfWMZyaysOSy23GMJWS5D+dJMygstRip42Ey+oVGaVlY11Gi+PXzaqD 8ZGg== 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=TmuuAqRzPZh0E74Jry6k34vaegwkUQMiM0zjPLz+tsA=; b=pDpY4afE59T0zUVWMANjk3RCSIan5qkn5TARu/OG10Pif7ahmWBZ1me0hAu+YQ+NvM DP+wA/H9oN5SHuB6wMvPoy7CSG28WdRbJ/3iQzzXO9A8A5ovmxWM+fPpmOp6wc+POzs1 wI3W/wBYFmT4AvYg/+6FGwr8amtmx2mtzX4vdZRmGlGQFGvkAV/cQRAyRc5hpyER1SEZ cKnzuyTEAtkZB5b1HEmSZ8zdYCQ45tJwDUZrpkpcMaw9UIEjfXOqFD5l+PllmvKVUs7x R4afxqHpkloXseR+NP2BcUkoMNMi3dYOTiFvmXX4FY4rCMt1If5tmg7F/1MzmnHTj7Pt Zd/Q== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@linaro.org header.s=google header.b=uIGw6UPH; 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 va7si10939370ejb.4.2019.10.02.07.17.45; Wed, 02 Oct 2019 07:17:45 -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=uIGw6UPH; 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 S1727382AbfJBORp (ORCPT + 3 others); Wed, 2 Oct 2019 10:17:45 -0400 Received: from mail-wm1-f65.google.com ([209.85.128.65]:39313 "EHLO mail-wm1-f65.google.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1727536AbfJBORo (ORCPT ); Wed, 2 Oct 2019 10:17:44 -0400 Received: by mail-wm1-f65.google.com with SMTP id v17so7190051wml.4 for ; Wed, 02 Oct 2019 07:17:43 -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=TmuuAqRzPZh0E74Jry6k34vaegwkUQMiM0zjPLz+tsA=; b=uIGw6UPHuVu79PfMpOds4Kc5zn6vX3EgWiyZqRZg5lVLp4QEma+hXrnvsVDrKufPu3 OhyGfqXyAmyL72sXoQMe6eofTIoa4g0uoLyTVY2MBp2ymjeYkvGL48WdMYlSZBuKNpFG Jww6lUi2UOI9tj566fyb8q6/ug6N5hcdlOtUFwsgPmxM653Y8uFrevtNLi2iks7pTPhR bmSthj7Wm0Nf/XzJ2TwUO7N9ovUPhhX6i3je7koK/NgQ057CJHDA6dmmdHkCgvf1yp1C HTENoC5ta/6ZZPV52h4qAJRIAuk6jYd7THQT6+XL+KXZGwvXLzsD0nJRWYC9ZvW8UfMf KkyA== 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=TmuuAqRzPZh0E74Jry6k34vaegwkUQMiM0zjPLz+tsA=; b=UA1z92TW938ahx4ECa7nZmmxlXBKk4An3t971+dubuaRRlv02EpF/gaBYGVapEACaH rVugRQDoRfDhHruBORXrsPoEHkDZDxZc4v+6fneZLrY2ZTeNB9BM/0BtXocAoiXCQKBc 51gaiTYwcjaxDeAk6gU5kpWA05G6x+KFvI42isIs9rwlBvigSgqoGWp4NWzW4qIqOHd4 Yj7Q+1hr3TsAO59hDcu5kTLXdzVZM10qs2ERuY2g9zxUc3rvP3T13nx08FL+QyUXGir2 Ne/eL3LD13iqV9HPMMym0fy2gI2GUdLdpx7lwNzhapK994ZuDPzbaTdAN8cIcuePh6+A e4+w== X-Gm-Message-State: APjAAAW3bVv0cmo1K+JYnN0/9WvNWApx8x3NTLsMo0ExWSfwMd2FFeiy aotyd+mJYIA5ovt7iBt5S+qw1V20aNKsJE+r X-Received: by 2002:a7b:c112:: with SMTP id w18mr3263701wmi.88.1570025862744; Wed, 02 Oct 2019 07:17:42 -0700 (PDT) Received: from sudo.home ([2a01:cb1d:112:6f00:f145:3252:fc29:76c9]) by smtp.gmail.com with ESMTPSA id t13sm41078149wra.70.2019.10.02.07.17.41 (version=TLS1_2 cipher=ECDHE-RSA-AES128-GCM-SHA256 bits=128/128); Wed, 02 Oct 2019 07:17:42 -0700 (PDT) From: Ard Biesheuvel To: linux-crypto@vger.kernel.org Cc: Ard Biesheuvel , Herbert Xu , David Miller , Greg KH , Linus Torvalds , "Jason A . Donenfeld" , Samuel Neves , Dan Carpenter , Arnd Bergmann , Eric Biggers , Andy Lutomirski , Will Deacon , Marc Zyngier , Catalin Marinas , Martin Willi , Peter Zijlstra , Josh Poimboeuf Subject: [PATCH v2 03/20] crypto: arm64/chacha - expose arm64 ChaCha routine as library function Date: Wed, 2 Oct 2019 16:16:56 +0200 Message-Id: <20191002141713.31189-4-ard.biesheuvel@linaro.org> X-Mailer: git-send-email 2.20.1 In-Reply-To: <20191002141713.31189-1-ard.biesheuvel@linaro.org> References: <20191002141713.31189-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 Expose the accelerated NEON ChaCha routine directly as a symbol export so that users of the ChaCha library can use it directly. Signed-off-by: Ard Biesheuvel --- arch/arm64/crypto/Kconfig | 1 + arch/arm64/crypto/chacha-neon-glue.c | 30 ++++++++++++++++++++ 2 files changed, 31 insertions(+) -- 2.20.1 diff --git a/arch/arm64/crypto/Kconfig b/arch/arm64/crypto/Kconfig index 4922c4451e7c..09aa69ccc792 100644 --- a/arch/arm64/crypto/Kconfig +++ b/arch/arm64/crypto/Kconfig @@ -104,6 +104,7 @@ config CRYPTO_CHACHA20_NEON depends on KERNEL_MODE_NEON select CRYPTO_BLKCIPHER select CRYPTO_CHACHA20 + select CRYPTO_ARCH_HAVE_LIB_CHACHA config CRYPTO_NHPOLY1305_NEON tristate "NHPoly1305 hash function using NEON instructions (for Adiantum)" diff --git a/arch/arm64/crypto/chacha-neon-glue.c b/arch/arm64/crypto/chacha-neon-glue.c index d4cc61bfe79d..982a07070675 100644 --- a/arch/arm64/crypto/chacha-neon-glue.c +++ b/arch/arm64/crypto/chacha-neon-glue.c @@ -59,6 +59,36 @@ static void chacha_doneon(u32 *state, u8 *dst, const u8 *src, } } +void hchacha_block(const u32 *state, u32 *stream, int nrounds) +{ + if (!crypto_simd_usable()) { + hchacha_block_generic(state, stream, nrounds); + } else { + kernel_neon_begin(); + hchacha_block_neon(state, stream, nrounds); + kernel_neon_end(); + } +} +EXPORT_SYMBOL(hchacha_block); + +void chacha_init(u32 *state, const u32 *key, const u8 *iv) +{ + chacha_init_generic(state, key, iv); +} +EXPORT_SYMBOL(chacha_init); + +void chacha_crypt(u32 *state, u8 *dst, const u8 *src, unsigned int bytes, + int nrounds) +{ + if (bytes <= CHACHA_BLOCK_SIZE || !crypto_simd_usable()) + return chacha_crypt_generic(state, dst, src, bytes, nrounds); + + kernel_neon_begin(); + chacha_doneon(state, dst, src, bytes, nrounds); + kernel_neon_end(); +} +EXPORT_SYMBOL(chacha_crypt); + static int chacha_neon_stream_xor(struct skcipher_request *req, const struct chacha_ctx *ctx, const u8 *iv) {