Received: by 2002:a25:6193:0:0:0:0:0 with SMTP id v141csp773634ybb; Sat, 28 Mar 2020 09:44:09 -0700 (PDT) X-Google-Smtp-Source: ADFU+vv3xQyIN1hRIGBWxtQjXoaoAqdrlvpH9IiyNJ1hVBX3L2jSoFQUoq75fdFY9maVQRQPStAS X-Received: by 2002:a9d:6354:: with SMTP id y20mr3228173otk.171.1585413849503; Sat, 28 Mar 2020 09:44:09 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1585413849; cv=none; d=google.com; s=arc-20160816; b=zGMEwEy1SFlmiWbgfTiqFWKVVWpPl0j/cItm9+a6vekPaT7UbfnCK+3xEiKsTSZe9X 3KL6OidnaYKhPB6+irDpSC+ERAdO2Uw9zCHwZamYEW41i+JDRifDsQhcaYlipIhOlved bl+THT2VDrUAc3sLSKguIXKxB819mWWx/aaoMDivvsqRqkVGHVip7P/6l16hkQrIs14Y 6+qaA996BxxF9S6GTjTTY7d4EkvcYqvMlu6D93QMcyY3pf2TDKGm9+aBoGvvtNtHF9pD brx2rMoXLjLblxiwbwzH/MM9op24/wqab2zlNeWiZoTcMzvZ6tU3d6MPWrbUgwCgtrzU vWHA== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:sender:cc:to:subject:date:from:message-id; bh=ijpWHMBs2Prjt5ONBhm3Jy4iOaCovV8CFjHrQF4SVDw=; b=KVfrN2/5N/pCLWNgvNjXRdDYqqmY/+kVX5eQCFM8fEMhGRmZ3XtHc6JouT0OXuDuWq JvwyGc9gH7MMfPUVz7i0LB19vdXFesgywZcexCbSwCHzYXm0gyiqrJjRx+PWGQlieDWY Ko0ZkCxi4qMhNSSDc1VWIB+LcIamL4XC257bpWHSCaknJGETLX0BjB3WiClYibz90FeV gn4zD/NAYToeapXADUM8vjB/cz84D4EZcZOfaA8enYss5nWrXDeKQ3YdsAJJfV4i+l8M HfSjoxZwxz1aTZDU401wSzXjH748COG6p4PplcLwstJKm84seWogQmZCoG6ASzlcG2XX UoTA== ARC-Authentication-Results: i=1; mx.google.com; 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 Return-Path: Received: from vger.kernel.org (vger.kernel.org. [209.132.180.67]) by mx.google.com with ESMTP id w15si2025578otl.260.2020.03.28.09.43.43; Sat, 28 Mar 2020 09:44:09 -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; 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 Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1727549AbgC1QnX (ORCPT + 99 others); Sat, 28 Mar 2020 12:43:23 -0400 Received: from mx.sdf.org ([205.166.94.20]:50208 "EHLO mx.sdf.org" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1727401AbgC1QnU (ORCPT ); Sat, 28 Mar 2020 12:43:20 -0400 Received: from sdf.org (IDENT:lkml@sdf.lonestar.org [205.166.94.16]) by mx.sdf.org (8.15.2/8.14.5) with ESMTPS id 02SGhC9q026662 (using TLSv1.3 with cipher TLS_AES_256_GCM_SHA384 (256 bits) verified NO); Sat, 28 Mar 2020 16:43:12 GMT Received: (from lkml@localhost) by sdf.org (8.15.2/8.12.8/Submit) id 02SGhCt7025631; Sat, 28 Mar 2020 16:43:12 GMT Message-Id: <202003281643.02SGhCt7025631@sdf.org> From: George Spelvin Date: Fri, 29 Nov 2019 15:24:22 -0500 Subject: [RFC PATCH v1 14/50] crypto/testmgr.c: use prandom_u32_max() & prandom_bytes() To: linux-kernel@vger.kernel.org, lkml@sdf.org Cc: Herbert Xu , linux-crypto@vger.kernel.org Sender: linux-crypto-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: linux-crypto@vger.kernel.org ...in a couple of places where they're appropriate. There are many other places where successive code blocks make calls like prandom_u32() % 2 followed immediately by prandom_u32() % 4. This could be easily written to use three bits of one call, but at some cost in clarity and obvious-correctness, which is more important that efficiency in self-test code. Signed-off-by: George Spelvin Cc: Herbert Xu Cc: linux-crypto@vger.kernel.org --- crypto/testmgr.c | 5 ++--- 1 file changed, 2 insertions(+), 3 deletions(-) diff --git a/crypto/testmgr.c b/crypto/testmgr.c index e8f21f7348a48..bc9252768bdba 100644 --- a/crypto/testmgr.c +++ b/crypto/testmgr.c @@ -770,7 +770,7 @@ static void mutate_buffer(u8 *buf, size_t count) if (prandom_u32() % 4 == 0) { num_flips = min_t(size_t, 1 << (prandom_u32() % 8), count * 8); for (i = 0; i < num_flips; i++) { - pos = prandom_u32() % (count * 8); + pos = prandom_u32_max(count * 8); buf[pos / 8] ^= 1 << (pos % 8); } } @@ -821,8 +821,7 @@ static void generate_random_bytes(u8 *buf, size_t count) break; default: /* Fully random bytes */ - for (i = 0; i < count; i++) - buf[i] = (u8)prandom_u32(); + prandom_bytes(buf, count); } } -- 2.26.0