From patchwork Tue Aug 27 08:13:52 2019 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Michael Walle X-Patchwork-Id: 1153632 X-Patchwork-Delegate: joe.hershberger@gmail.com Return-Path: X-Original-To: incoming@patchwork.ozlabs.org Delivered-To: patchwork-incoming@bilbo.ozlabs.org Authentication-Results: ozlabs.org; spf=none (mailfrom) smtp.mailfrom=lists.denx.de (client-ip=81.169.180.215; helo=lists.denx.de; envelope-from=u-boot-bounces@lists.denx.de; receiver=) Authentication-Results: ozlabs.org; dmarc=none (p=none dis=none) header.from=walle.cc Authentication-Results: ozlabs.org; dkim=fail reason="signature verification failed" (1024-bit key; unprotected) header.d=walle.cc header.i=@walle.cc header.b="Sg6RP5TN"; dkim-atps=neutral Received: from lists.denx.de (dione.denx.de [81.169.180.215]) by ozlabs.org (Postfix) with ESMTP id 46HhVR6Ms3z9sQt for ; Tue, 27 Aug 2019 18:14:23 +1000 (AEST) Received: by lists.denx.de (Postfix, from userid 105) id 58162C22032; Tue, 27 Aug 2019 08:14:11 +0000 (UTC) X-Spam-Checker-Version: SpamAssassin 3.4.0 (2014-02-07) on lists.denx.de X-Spam-Level: X-Spam-Status: No, score=0.0 required=5.0 tests=T_DKIM_INVALID autolearn=unavailable autolearn_force=no version=3.4.0 Received: from lists.denx.de (localhost [IPv6:::1]) by lists.denx.de (Postfix) with ESMTP id A2E17C21E9F; Tue, 27 Aug 2019 08:14:09 +0000 (UTC) Received: by lists.denx.de (Postfix, from userid 105) id BF3EEC21E9F; Tue, 27 Aug 2019 08:14:08 +0000 (UTC) Received: from ssl.serverraum.org (ssl.serverraum.org [176.9.125.105]) by lists.denx.de (Postfix) with ESMTPS id AFFAAC21E39 for ; Tue, 27 Aug 2019 08:14:07 +0000 (UTC) Received: from mwalle01.sab.local. (unknown [213.135.10.150]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by ssl.serverraum.org (Postfix) with ESMTPSA id 412B7230E2; Tue, 27 Aug 2019 10:14:07 +0200 (CEST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=walle.cc; s=mail2016061301; t=1566893647; bh=z5TpWf+NrmEZT3OhfmZ377XuD3QkZZIqSBFI4Nfknk8=; h=From:To:Cc:Subject:Date:From; b=Sg6RP5TNIDKG+P5Tpnxj34DwxaV8MGkZB30+Me5aWbH2aszjVHGQMoqYjNol4ZLth 1UCw1q8qUO4rwr2q1qF7zOWCNczJ2jc0kWgld1Xoy/D9tSvh/ay0Qwr6B+taEszDAL aN4QmuA33jNqVMlwfUKlh0Sb8GJ5nk9GvWyw2ybE= From: Michael Walle To: u-boot@lists.denx.de Date: Tue, 27 Aug 2019 10:13:52 +0200 Message-Id: <20190827081352.598-1-michael@walle.cc> X-Mailer: git-send-email 2.11.0 X-Virus-Scanned: clamav-milter 0.100.3 at web X-Virus-Status: Clean Cc: Joe Hershberger Subject: [U-Boot] [PATCH v2] net: make net_random_ethaddr() more random X-BeenThere: u-boot@lists.denx.de X-Mailman-Version: 2.1.18 Precedence: list List-Id: U-Boot discussion List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , MIME-Version: 1.0 Errors-To: u-boot-bounces@lists.denx.de Sender: "U-Boot" The net_random_ethaddr() tries to get some entropy from different startup times of a board. The seed is initialized with get_timer() which has only a granularity of milliseconds. We can do better if we use get_ticks() which returns the raw timer ticks. Using this we have a higher chance of getting different values at startup. Signed-off-by: Michael Walle Reviewed-by: Bin Meng Acked-by: Joe Hershberger --- since v1: - Removed the and-mask. Since there were no more comments I did some tests and apparently there are no compiler warnings. include/net.h | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/include/net.h b/include/net.h index a54d5eeac5..75a16e4c8f 100644 --- a/include/net.h +++ b/include/net.h @@ -816,7 +816,7 @@ static inline int is_valid_ethaddr(const u8 *addr) static inline void net_random_ethaddr(uchar *addr) { int i; - unsigned int seed = get_timer(0); + unsigned int seed = get_ticks(); for (i = 0; i < 6; i++) addr[i] = rand_r(&seed);