From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: X-Spam-Checker-Version: SpamAssassin 3.4.0 (2014-02-07) on aws-us-west-2-korg-lkml-1.web.codeaurora.org X-Spam-Level: X-Spam-Status: No, score=-7.0 required=3.0 tests=DKIMWL_WL_HIGH,DKIM_SIGNED, DKIM_VALID,HEADER_FROM_DIFFERENT_DOMAINS,INCLUDES_PATCH,MAILING_LIST_MULTI, SIGNED_OFF_BY,SPF_PASS,URIBL_BLOCKED autolearn=unavailable autolearn_force=no version=3.4.0 Received: from mail.kernel.org (mail.kernel.org [198.145.29.99]) by smtp.lore.kernel.org (Postfix) with ESMTP id F099BC43381 for ; Fri, 22 Mar 2019 06:42:29 +0000 (UTC) Received: from bombadil.infradead.org (bombadil.infradead.org [198.137.202.133]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by mail.kernel.org (Postfix) with ESMTPS id BA463213F2 for ; Fri, 22 Mar 2019 06:42:29 +0000 (UTC) Authentication-Results: mail.kernel.org; dkim=pass (2048-bit key) header.d=lists.infradead.org header.i=@lists.infradead.org header.b="MiTiEIH2" DMARC-Filter: OpenDMARC Filter v1.3.2 mail.kernel.org BA463213F2 Authentication-Results: mail.kernel.org; dmarc=none (p=none dis=none) header.from=gondor.apana.org.au Authentication-Results: mail.kernel.org; spf=none smtp.mailfrom=linux-arm-kernel-bounces+infradead-linux-arm-kernel=archiver.kernel.org@lists.infradead.org DKIM-Signature: v=1; a=rsa-sha256; q=dns/txt; c=relaxed/relaxed; d=lists.infradead.org; s=bombadil.20170209; h=Sender: Content-Transfer-Encoding:Content-Type:MIME-Version:List-Subscribe:List-Help: List-Post:List-Archive:List-Unsubscribe:List-Id:Date:From:Message-Id:To: References:Subject:Reply-To:Cc:Content-ID:Content-Description:Resent-Date: Resent-From:Resent-Sender:Resent-To:Resent-Cc:Resent-Message-ID:In-Reply-To: List-Owner; bh=fknR+AXlyDAbsIFIuLceYqj3wM8B7mJvmATxAiOP1BU=; b=MiTiEIH2BFf91+ w7vVIUKu1QlaXmYREhNbPs7gWuIJNtGGOOjF1k2kL6ocwpDZ1v7iwVj5GCceCGqpwrL5I3gBi+PFm 2SOSSnbYkqGCmJzR0pDXsHj2YuySIat4Py1D1SnwpMXVLYEi4wfsKi+jvWdK2xfi9x0gD8KI66KAw PapLfgO1YAPQ1V6/weefsk7/l+T92jbYHqR9PM3SlW819qgbdJ9ttRzTKdkFERcpv1qiIZnt17B2O CjwplkQHtW8COUVTV00ShGeT1lKZcoNGGXOlXelyJJ8B6x8cS/NIZ+G5IPfOlWj3HHsZYOiyivPTk +MBgqh2EQ59627tiVWrA==; Received: from localhost ([127.0.0.1] helo=bombadil.infradead.org) by bombadil.infradead.org with esmtp (Exim 4.90_1 #2 (Red Hat Linux)) id 1h7Dsm-0004Ja-Id; Fri, 22 Mar 2019 06:42:24 +0000 Received: from orcrist.hmeau.com ([104.223.48.154] helo=deadmen.hmeau.com) by bombadil.infradead.org with esmtps (Exim 4.90_1 #2 (Red Hat Linux)) id 1h7Dsi-0004JC-NV for linux-arm-kernel@lists.infradead.org; Fri, 22 Mar 2019 06:42:22 +0000 Received: from gondobar.mordor.me.apana.org.au ([192.168.128.4] helo=gondobar) by deadmen.hmeau.com with esmtps (Exim 4.89 #2 (Debian)) id 1h7Dgj-0002Yu-1A; Fri, 22 Mar 2019 14:30:01 +0800 Received: from herbert by gondobar with local (Exim 4.89) (envelope-from ) id 1h7DgZ-0001IW-E8; Fri, 22 Mar 2019 14:29:47 +0800 Subject: [PATCH 9/17] zinc: Add x86 accelerated poly1305 References: <20190322062740.nrwfx2rvmt7lzotj@gondor.apana.org.au> To: Linus Torvalds , "David S. Miller" , "Jason A. Donenfeld" , Eric Biggers , Ard Biesheuvel , Linux Crypto Mailing List , linux-fscrypt@vger.kernel.org, linux-arm-kernel@lists.infradead.org, LKML , Paul Crowley , Greg Kaiser , Samuel Neves , Tomer Ashur , Martin Willi Message-Id: From: Herbert Xu Date: Fri, 22 Mar 2019 14:29:47 +0800 X-CRM114-Version: 20100106-BlameMichelson ( TRE 0.8.0 (BSD) ) MR-646709E3 X-CRM114-CacheID: sfid-20190321_234221_018762_2A43B79A X-CRM114-Status: GOOD ( 11.43 ) X-BeenThere: linux-arm-kernel@lists.infradead.org X-Mailman-Version: 2.1.21 Precedence: list List-Id: List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , MIME-Version: 1.0 Content-Type: text/plain; charset="us-ascii" Content-Transfer-Encoding: 7bit Sender: "linux-arm-kernel" Errors-To: linux-arm-kernel-bounces+infradead-linux-arm-kernel=archiver.kernel.org@lists.infradead.org This patch exposes the crypto API x86 poly1305 implementation through zinc. Signed-off-by: Herbert Xu --- lib/zinc/Kconfig | 1 lib/zinc/poly1305/poly1305-x86_64-glue.c | 68 +++++++++++++++++++++++++++++++ lib/zinc/poly1305/poly1305.c | 4 + 3 files changed, 73 insertions(+) diff --git a/lib/zinc/Kconfig b/lib/zinc/Kconfig index 70d45b3288d2..34fa49beb37f 100644 --- a/lib/zinc/Kconfig +++ b/lib/zinc/Kconfig @@ -8,6 +8,7 @@ config ZINC_CHACHA20 config ZINC_POLY1305 tristate select CRYPTO_POLY1305 + select CRYPTO_POLY1305_X86_64 if ZINC_ARCH_X86_64 config ZINC_SELFTEST bool "Zinc cryptography library self-tests" diff --git a/lib/zinc/poly1305/poly1305-x86_64-glue.c b/lib/zinc/poly1305/poly1305-x86_64-glue.c new file mode 100644 index 000000000000..9e6dbd40911d --- /dev/null +++ b/lib/zinc/poly1305/poly1305-x86_64-glue.c @@ -0,0 +1,68 @@ +// SPDX-License-Identifier: GPL-2.0 OR MIT +/* + * Copyright (C) 2015-2018 Jason A. Donenfeld . All Rights Reserved. + */ + +#include +#include +#include + +static bool poly1305_use_sse2 __ro_after_init; +static bool *const poly1305_nobs[] __initconst = { + &poly1305_use_sse2 }; + +static void __init poly1305_fpu_init(void) +{ + poly1305_use_sse2 = boot_cpu_has(X86_FEATURE_XMM2); +} + +struct poly1305_arch_internal { + struct poly1305_internal base; + struct poly1305_simd_xtra x; +}; + +static inline bool poly1305_init_arch(void *ctx, + const u8 key[POLY1305_KEY_SIZE]) +{ + struct poly1305_arch_internal *state = ctx; + + poly1305_simd_init(&state->x); + poly1305_core_setkey(&state->base.r, key); + return true; +} + +static inline bool poly1305_blocks_arch(void *ctx, const u8 *inp, + size_t len, const u32 padbit, + simd_context_t *simd_context) +{ + struct poly1305_arch_internal *state = ctx; + + /* SIMD disables preemption, so relax after processing each page. */ + BUILD_BUG_ON(PAGE_SIZE < POLY1305_BLOCK_SIZE || + PAGE_SIZE % POLY1305_BLOCK_SIZE); + + if (!poly1305_use_sse2 || !simd_use(simd_context) || padbit) + return false; + + for (;;) { + const size_t bytes = min_t(size_t, len, PAGE_SIZE); + + poly1305_simd_blocks(&state->base.h, &state->base.r, + &state->x, inp, bytes); + + len -= bytes; + if (!len) + break; + inp += bytes; + simd_relax(simd_context); + } + + return true; +} + +static inline bool poly1305_emit_arch(void *ctx, u8 mac[POLY1305_MAC_SIZE], + const u32 nonce[4], + simd_context_t *simd_context) +{ + return false; +} diff --git a/lib/zinc/poly1305/poly1305.c b/lib/zinc/poly1305/poly1305.c index 1546f5ac6d1c..c6a88136abb7 100644 --- a/lib/zinc/poly1305/poly1305.c +++ b/lib/zinc/poly1305/poly1305.c @@ -22,6 +22,9 @@ struct poly1305_internal { struct poly1305_state h; }; +#if defined(CONFIG_ZINC_ARCH_X86_64) +#include "poly1305-x86_64-glue.c" +#else static inline bool poly1305_init_arch(void *ctx, const u8 key[POLY1305_KEY_SIZE]) { @@ -43,6 +46,7 @@ static bool *const poly1305_nobs[] __initconst = { }; static void __init poly1305_fpu_init(void) { } +#endif static void poly1305_init_generic(void *ctx, const u8 key[16]) { _______________________________________________ linux-arm-kernel mailing list linux-arm-kernel@lists.infradead.org http://lists.infradead.org/mailman/listinfo/linux-arm-kernel