Return-Path: X-Spam-Checker-Version: SpamAssassin 3.4.0 (2014-02-07) on aws-us-west-2-korg-lkml-1.web.codeaurora.org Received: from smtp1.osuosl.org (smtp1.osuosl.org [140.211.166.138]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by smtp.lore.kernel.org (Postfix) with ESMTPS id 3A13CC433F5 for ; Sun, 3 Apr 2022 07:30:33 +0000 (UTC) Received: from localhost (localhost [127.0.0.1]) by smtp1.osuosl.org (Postfix) with ESMTP id A488783E3B; Sun, 3 Apr 2022 07:30:33 +0000 (UTC) X-Virus-Scanned: amavisd-new at osuosl.org Received: from smtp1.osuosl.org ([127.0.0.1]) by localhost (smtp1.osuosl.org [127.0.0.1]) (amavisd-new, port 10024) with ESMTP id jSj4S0auvxrI; Sun, 3 Apr 2022 07:30:32 +0000 (UTC) Received: from ash.osuosl.org (ash.osuosl.org [140.211.166.34]) by smtp1.osuosl.org (Postfix) with ESMTP id AB0BE83E05; Sun, 3 Apr 2022 07:30:31 +0000 (UTC) Received: from smtp3.osuosl.org (smtp3.osuosl.org [140.211.166.136]) by ash.osuosl.org (Postfix) with ESMTP id 249751BF5A3 for ; Sun, 3 Apr 2022 07:30:30 +0000 (UTC) Received: from localhost (localhost [127.0.0.1]) by smtp3.osuosl.org (Postfix) with ESMTP id 2142360AC2 for ; Sun, 3 Apr 2022 07:30:30 +0000 (UTC) X-Virus-Scanned: amavisd-new at osuosl.org Received: from smtp3.osuosl.org ([127.0.0.1]) by localhost (smtp3.osuosl.org [127.0.0.1]) (amavisd-new, port 10024) with ESMTP id DkbwqBtd41jy for ; Sun, 3 Apr 2022 07:30:29 +0000 (UTC) X-Greylist: from auto-whitelisted by SQLgrey-1.8.0 Received: from eu-smtp-delivery-151.mimecast.com (eu-smtp-delivery-151.mimecast.com [185.58.86.151]) by smtp3.osuosl.org (Postfix) with ESMTPS id DFB9060A87 for ; Sun, 3 Apr 2022 07:30:28 +0000 (UTC) Received: from AcuMS.aculab.com (156.67.243.121 [156.67.243.121]) by relay.mimecast.com with ESMTP with STARTTLS (version=TLSv1.2, cipher=TLS_ECDHE_RSA_WITH_AES_256_CBC_SHA384) id uk-mta-241-glwBTEN9Osap53v6il0XZA-1; Sun, 03 Apr 2022 08:30:25 +0100 X-MC-Unique: glwBTEN9Osap53v6il0XZA-1 Received: from AcuMS.Aculab.com (fd9f:af1c:a25b:0:994c:f5c2:35d6:9b65) by AcuMS.aculab.com (fd9f:af1c:a25b:0:994c:f5c2:35d6:9b65) with Microsoft SMTP Server (TLS) id 15.0.1497.32; Sun, 3 Apr 2022 08:30:23 +0100 Received: from AcuMS.Aculab.com ([fe80::994c:f5c2:35d6:9b65]) by AcuMS.aculab.com ([fe80::994c:f5c2:35d6:9b65%12]) with mapi id 15.00.1497.033; Sun, 3 Apr 2022 08:30:23 +0100 From: David Laight To: 'Arnout Vandecappelle' , "'Jason A. Donenfeld'" , James Hilliard Thread-Topic: [Buildroot] [PATCH v3] package/urandom-scripts: actually credit seed files via seedrng Thread-Index: AQHYRbhKzS72cv7q9kGHCbtoXkDsoaza6TGggAHjKgCAAPdlkA== Date: Sun, 3 Apr 2022 07:30:23 +0000 Message-ID: <2d5e8287df984f16b4b90e8a2921d399@AcuMS.aculab.com> References: <20220327202415.1248312-1-Jason@zx2c4.com> <20220329050401.110856-1-Jason@zx2c4.com> <871qyj8kpk.fsf@dell.be.48ers.dk> <7bcc0cf7-5759-1ef4-9667-fd8ae0c4741f@mind.be> In-Reply-To: <7bcc0cf7-5759-1ef4-9667-fd8ae0c4741f@mind.be> Accept-Language: en-GB, en-US X-MS-Has-Attach: X-MS-TNEF-Correlator: x-ms-exchange-transport-fromentityheader: Hosted x-originating-ip: [10.202.205.107] MIME-Version: 1.0 Authentication-Results: relay.mimecast.com; auth=pass smtp.auth=C51A453 smtp.mailfrom=david.laight@aculab.com X-Mimecast-Spam-Score: 0 X-Mimecast-Originator: aculab.com Content-Language: en-US Subject: Re: [Buildroot] [PATCH v3] package/urandom-scripts: actually credit seed files via seedrng X-BeenThere: buildroot@buildroot.org X-Mailman-Version: 2.1.29 Precedence: list List-Id: Discussion and development of buildroot List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Cc: "Yann E. MORIN" , buildroot Content-Type: text/plain; charset="us-ascii" Content-Transfer-Encoding: 7bit Errors-To: buildroot-bounces@buildroot.org Sender: "buildroot" From: Arnout Vandecappelle > Sent: 02 April 2022 18:09 ... > > Busybox tends to care about code size. > > Yes, but if it's not overly bloated, it's not going to be blocker for initial > inclusion. > > > You really want to roll-up the unrolled loop in blakes2. > > Performance really doesn't matter here. > > AFAIU (but neither the commit message nor the seedrng about page explain it) > the Blake2 algorithm was simply chosen because it's small. Any hash function > should be fine. There's sha1, sha2 and sha3 in libbb, so I guess one of them > should have all the desired properties. The unrolled blakes2 is typically 5kb of object code. The unrolled code is better for large buffers, but just fetching the code to the I-cache will significantly affect performance for small buffers. I really ought to sit and measure the cutoff. The code is: +#define G(r, i, a, b, c, d) do { \ + a += b + m[blake2s_sigma[r][2 * i + 0]]; \ + d = ror32(d ^ a, 16); \ + c += d; \ + b = ror32(b ^ c, 12); \ + a += b + m[blake2s_sigma[r][2 * i + 1]]; \ + d = ror32(d ^ a, 8); \ + c += d; \ + b = ror32(b ^ c, 7); \ +} while (0) + +#define ROUND(r) do { \ + G(r, 0, v[0], v[ 4], v[ 8], v[12]); \ + G(r, 1, v[1], v[ 5], v[ 9], v[13]); \ + G(r, 2, v[2], v[ 6], v[10], v[14]); \ + G(r, 3, v[3], v[ 7], v[11], v[15]); \ + G(r, 4, v[0], v[ 5], v[10], v[15]); \ + G(r, 5, v[1], v[ 6], v[11], v[12]); \ + G(r, 6, v[2], v[ 7], v[ 8], v[13]); \ + G(r, 7, v[3], v[ 4], v[ 9], v[14]); \ +} while (0) + ROUND(0); + ROUND(1); + ROUND(2); + ROUND(3); + ROUND(4); + ROUND(5); + ROUND(6); + ROUND(7); + ROUND(8); + ROUND(9); + +#undef G +#undef ROUND Now G() is a 14 instruction register dependency chain. But since each batch of 4 G() is independent the compiler can interleave them - significant on modern cpu. OTOH the 10 ROUND() just advance through blake2s_sigma[]. Unrolling these that is probably not that significant. Especially if the compiler manages to increment the pointer. While modern gcc manage to optimise the array away completely the code isn't constrained by memory accesses so loading from an actual array won't make much difference. On some architectures the constants either take multiple instructions to load, or load from memory anyway. But these bloat that code block by a factor of 10. David - Registered Address Lakeside, Bramley Road, Mount Farm, Milton Keynes, MK1 1PT, UK Registration No: 1397386 (Wales) _______________________________________________ buildroot mailing list buildroot@buildroot.org https://lists.buildroot.org/mailman/listinfo/buildroot