From patchwork Thu Aug 22 22:08:01 2019 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Michael Walle X-Patchwork-Id: 1151847 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="kwjzo4M5"; dkim-atps=neutral Received: from lists.denx.de (dione.denx.de [81.169.180.215]) by ozlabs.org (Postfix) with ESMTP id 46DzFF1xPDz9sN1 for ; Fri, 23 Aug 2019 08:08:31 +1000 (AEST) Received: by lists.denx.de (Postfix, from userid 105) id 78E0AC22101; Thu, 22 Aug 2019 22:08:18 +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 F2249C22066; Thu, 22 Aug 2019 22:08:16 +0000 (UTC) Received: by lists.denx.de (Postfix, from userid 105) id 24CCDC22066; Thu, 22 Aug 2019 22:08:16 +0000 (UTC) Received: from ssl.serverraum.org (ssl.serverraum.org [176.9.125.105]) by lists.denx.de (Postfix) with ESMTPS id 02B55C22047 for ; Thu, 22 Aug 2019 22:08:15 +0000 (UTC) Received: from apollo.fritz.box (unknown [IPv6:2a02:810c:c200:2e91:6257:18ff:fec4:ca34]) (using TLSv1.3 with cipher TLS_AES_256_GCM_SHA384 (256/256 bits)) (No client certificate requested) by ssl.serverraum.org (Postfix) with ESMTPSA id BE80B22FCA; Fri, 23 Aug 2019 00:08:13 +0200 (CEST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=walle.cc; s=mail2016061301; t=1566511693; bh=7kjvwimm9EXodLgtbQsuqtwVwtWsjRk3GZzz4CKLTOA=; h=From:To:Cc:Subject:Date:From; b=kwjzo4M56sphlO9gxAqKx6LLibhEg9BKGzYUyoFENjMHaHvz4gCcONGk/IytRlgld 4YLZDJYnP7Ye6eiq3VXAhRqxDpS64EUbqFWaWPzqHbXnhUwuhs/JwtjhZ5uHO+UTIH EANUKKLxojn/BjSNyAuyH8gxFE4vSEqXwccFxTaQ= From: Michael Walle To: u-boot@lists.denx.de Date: Fri, 23 Aug 2019 00:08:01 +0200 Message-Id: <20190822220801.28439-1-michael@walle.cc> X-Mailer: git-send-email 2.20.1 MIME-Version: 1.0 X-Virus-Scanned: clamav-milter 0.100.3 at web X-Virus-Status: Clean Cc: Joe Hershberger Subject: [U-Boot] [PATCH] 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: , 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 --- include/net.h | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/include/net.h b/include/net.h index a54d5eeac5..8215316bd3 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() & (unsigned int)-1; for (i = 0; i < 6; i++) addr[i] = rand_r(&seed);