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=-14.8 required=3.0 tests=BAYES_00,DKIM_INVALID, DKIM_SIGNED,HEADER_FROM_DIFFERENT_DOMAINS,INCLUDES_PATCH,MAILING_LIST_MULTI, MENTIONS_GIT_HOSTING,SIGNED_OFF_BY,SPF_HELO_NONE,SPF_PASS autolearn=ham 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 D3E29C433E0 for ; Wed, 12 Aug 2020 17:14:50 +0000 (UTC) Received: from lists.gnu.org (lists.gnu.org [209.51.188.17]) (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 9E4B620774 for ; Wed, 12 Aug 2020 17:14:50 +0000 (UTC) Authentication-Results: mail.kernel.org; dkim=fail reason="signature verification failed" (2048-bit key) header.d=linaro.org header.i=@linaro.org header.b="wZ1XVAw0" DMARC-Filter: OpenDMARC Filter v1.3.2 mail.kernel.org 9E4B620774 Authentication-Results: mail.kernel.org; dmarc=fail (p=none dis=none) header.from=linaro.org Authentication-Results: mail.kernel.org; spf=pass smtp.mailfrom=qemu-devel-bounces+qemu-devel=archiver.kernel.org@nongnu.org Received: from localhost ([::1]:38364 helo=lists1p.gnu.org) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1k5uKv-0000yh-QM for qemu-devel@archiver.kernel.org; Wed, 12 Aug 2020 13:14:49 -0400 Received: from eggs.gnu.org ([2001:470:142:3::10]:54618) by lists.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.90_1) (envelope-from ) id 1k5uJv-0008IN-78 for qemu-devel@nongnu.org; Wed, 12 Aug 2020 13:13:47 -0400 Received: from mail-wm1-x341.google.com ([2a00:1450:4864:20::341]:56109) by eggs.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_128_GCM_SHA256:128) (Exim 4.90_1) (envelope-from ) id 1k5uJt-0000Ib-2p for qemu-devel@nongnu.org; Wed, 12 Aug 2020 13:13:46 -0400 Received: by mail-wm1-x341.google.com with SMTP id 9so2432863wmj.5 for ; Wed, 12 Aug 2020 10:13:43 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=linaro.org; s=google; h=references:user-agent:from:to:cc:subject:in-reply-to:date :message-id:mime-version:content-transfer-encoding; bh=f/3cxxeyxzjcfx7o55j+TwOvXxd8MKM8NXgdbS6cIrs=; b=wZ1XVAw0Je3fVAKEORQKO85jzEmsYf3X1C3lge87aOEJ0IlMDc/eRhsolG5aW0DKZ0 VZTzdGR8+YEEDa2ic+Amf3sblc/HoQjKB3sU9eEJq9nqb3QX32010ditk82esVUwEQjB nOb0P+jmXxDFx4ak4KMJhFbXXhhHVSnjJc1ZVqQNB7vaWLKQw4k8rc4V94wLVCm0rJqj DSSrDw4Q50Rn4D4rU1w5OsI1dRe/vYwNyyLrh/POqpkgzW39WmRDDrF6Smv+zv8No8GT HAL2oIDyuxASajkz1y4ktmHQnlZuXTOF8Mgmxbj+PzIMMe02TJBqOcvwGlE/1iWj0gOB deYw== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20161025; h=x-gm-message-state:references:user-agent:from:to:cc:subject :in-reply-to:date:message-id:mime-version:content-transfer-encoding; bh=f/3cxxeyxzjcfx7o55j+TwOvXxd8MKM8NXgdbS6cIrs=; b=bzeiIGq1zq9J0gq6+cJcI7o09Ibh72Cf6eojplO3IX7fxDkch+gcEEzs12OGhDz/SN BONAq0TLlBUOsmnSPtypuJaQ/7aG2BMgOCbFDAydfGcf3WUaBGEJRP23AFCrvlT9l/Ns E8QwpKiyasSnl1CHmxLdHKnb6edRG25GWAY0vPl6C4eHlq05NOylBHwmAH7d5olaGg+b 0Lg7yDUJXELIMOcGhMI9qLpobeRsNbJRQxH4YMytyK58q7gcm7vFUh4NFFGfzRS8c982 fepdM+P2XRHC83zwHWobo9ROhCGjBBJyRB3IwxwKyYu95SNskf2LP2nt6nYIsSDGTuFT lojg== X-Gm-Message-State: AOAM531cYzw8DUX+6dQpCAqew+G6OU2g/z56LZ0OTOPofpREIbcxHJiY QUSOCWkMdeFFXmS2c/A6wYcm9Q== X-Google-Smtp-Source: ABdhPJz3iYNu/2Ax4I4Q6JK2Zx9xW6jH+JphQR2O6zY5UyLpP0ucd7azjnZZSr7evkdRpcatCNTRFQ== X-Received: by 2002:a7b:c845:: with SMTP id c5mr651879wml.180.1597252421702; Wed, 12 Aug 2020 10:13:41 -0700 (PDT) Received: from zen.linaroharston ([51.148.130.216]) by smtp.gmail.com with ESMTPSA id o124sm4903963wmb.2.2020.08.12.10.13.40 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Wed, 12 Aug 2020 10:13:40 -0700 (PDT) Received: from zen (localhost [127.0.0.1]) by zen.linaroharston (Postfix) with ESMTP id 9708C1FF7E; Wed, 12 Aug 2020 18:13:39 +0100 (BST) References: <20200812065339.2030527-1-richard.henderson@linaro.org> <20200812065339.2030527-3-richard.henderson@linaro.org> <87k0y419dm.fsf@linaro.org> User-agent: mu4e 1.5.5; emacs 28.0.50 From: Alex =?utf-8?Q?Benn=C3=A9e?= To: Richard Henderson Subject: Re: [PATCH 2/2] target/arm: Implement an IMPDEF pauth algorithm In-reply-to: Date: Wed, 12 Aug 2020 18:13:39 +0100 Message-ID: <87zh6zzt18.fsf@linaro.org> MIME-Version: 1.0 Content-Type: text/plain; charset=utf-8 Content-Transfer-Encoding: quoted-printable Received-SPF: pass client-ip=2a00:1450:4864:20::341; envelope-from=alex.bennee@linaro.org; helo=mail-wm1-x341.google.com X-detected-operating-system: by eggs.gnu.org: No matching host in p0f cache. That's all we know. X-Spam_score_int: -20 X-Spam_score: -2.1 X-Spam_bar: -- X-Spam_report: (-2.1 / 5.0 requ) BAYES_00=-1.9, DKIM_SIGNED=0.1, DKIM_VALID=-0.1, DKIM_VALID_AU=-0.1, DKIM_VALID_EF=-0.1, RCVD_IN_DNSWL_NONE=-0.0001, SPF_HELO_NONE=0.001, SPF_PASS=-0.001 autolearn=ham autolearn_force=no X-Spam_action: no action X-BeenThere: qemu-devel@nongnu.org X-Mailman-Version: 2.1.23 Precedence: list List-Id: List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Cc: mark.rutland@arm.com, peter.maydell@linaro.org, qemu-devel@nongnu.org Errors-To: qemu-devel-bounces+qemu-devel=archiver.kernel.org@nongnu.org Sender: "Qemu-devel" Richard Henderson writes: > On 8/12/20 2:49 AM, Alex Benn=C3=A9e wrote: >>=20 >> Richard Henderson writes: >>=20 >>> Without hardware acceleration, a cryptographically strong >>> algorithm is too expensive for pauth_computepac. >>> >>> Even with hardware accel, we are not currently expecting >>> to link the linux-user binaries to any crypto libraries, >>> and doing so would generally make the --static build fail. >>> >>> So choose XXH64 as a reasonably quick and decent hash. >>> >>> Signed-off-by: Richard Henderson >>> --- >>> target/arm/pauth_helper.c | 75 ++++++++++++++++++++++++++++++++++++--- >>> 1 file changed, 70 insertions(+), 5 deletions(-) >>> >>> diff --git a/target/arm/pauth_helper.c b/target/arm/pauth_helper.c >>> index 6dbab03768..f1a4389465 100644 >>> --- a/target/arm/pauth_helper.c >>> +++ b/target/arm/pauth_helper.c >>> @@ -207,8 +207,8 @@ static uint64_t tweak_inv_shuffle(uint64_t i) >>> return o; >>> } >>>=20=20 >>> -static uint64_t pauth_computepac(uint64_t data, uint64_t modifier, >>> - ARMPACKey key) >>> +static uint64_t __attribute__((noinline)) >>> +pauth_computepac_architected(uint64_t data, uint64_t modifier, ARMPACK= ey key) >>> { >>> static const uint64_t RC[5] =3D { >>> 0x0000000000000000ull, >>> @@ -272,6 +272,71 @@ static uint64_t pauth_computepac(uint64_t data, ui= nt64_t modifier, >>> return workingval; >>> } >>>=20=20 >>> +/* >>> + * The XXH64 algorithm from >>> + * https://github.com/Cyan4973/xxHash/blob/v0.8.0/xxhash.h >>> + */ >>> +#define PRIME64_1 0x9E3779B185EBCA87ULL >>> +#define PRIME64_2 0xC2B2AE3D27D4EB4FULL >>> +#define PRIME64_3 0x165667B19E3779F9ULL >>> +#define PRIME64_4 0x85EBCA77C2B2AE63ULL >>> +#define PRIME64_5 0x27D4EB2F165667C5ULL >>> + >>> +static inline uint64_t XXH64_round(uint64_t acc, uint64_t input) >>> +{ >>> + return rol64(acc + input * PRIME64_2, 31) * PRIME64_1; >>> +} >>> + >>> +static inline uint64_t XXH64_mergeround(uint64_t acc, uint64_t val) >>> +{ >>> + return (acc ^ XXH64_round(0, val)) * PRIME64_1 + PRIME64_4; >>> +} >>> + >>> +static inline uint64_t XXH64_avalanche(uint64_t h64) >>> +{ >>> + h64 ^=3D h64 >> 33; >>> + h64 *=3D PRIME64_2; >>> + h64 ^=3D h64 >> 29; >>> + h64 *=3D PRIME64_3; >>> + /* h64 ^=3D h64 >> 32; -- does not affect high 64 for pauth */ >>> + return h64; >>> +} >>> + >>> +static uint64_t __attribute__((noinline)) >>> +pauth_computepac_impdef(uint64_t data, uint64_t modifier, ARMPACKey ke= y) >>> +{ >>> + uint64_t v1 =3D 1 + PRIME64_1 + PRIME64_2; >>> + uint64_t v2 =3D 1 + PRIME64_2; >>> + uint64_t v3 =3D 1 + 0; >>> + uint64_t v4 =3D 1 - PRIME64_1; >>> + uint64_t h64; >>> + >>> + v1 =3D XXH64_round(v1, data); >>> + v2 =3D XXH64_round(v2, modifier); >>> + v3 =3D XXH64_round(v3, key.lo); >>> + v4 =3D XXH64_round(v4, key.hi); >>> + >>> + h64 =3D rol64(v1, 1) + rol64(v2, 7) + rol64(v3, 12) + rol64(v4, 18= ); >>> + h64 =3D XXH64_mergeround(h64, v1); >>> + h64 =3D XXH64_mergeround(h64, v2); >>> + h64 =3D XXH64_mergeround(h64, v3); >>> + h64 =3D XXH64_mergeround(h64, v4); >>> + >>> + return XXH64_avalanche(h64); >>> +} >>=20 >> You might find it easier to #include "qemu/xxhash.h" which we use for tb >> hashing amongst other things.=20=20 > > First, that's the 32-bit version, XXH32. Ahh I missed that detail. > Second, we define xxhash7 there; we would need xxhash8 here. We could at least put the code in the header with the others. > > > r~ --=20 Alex Benn=C3=A9e