From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: X-Spam-Checker-Version: SpamAssassin 3.4.2 (2018-09-13) on dcvr.yhbt.net X-Spam-Level: X-Spam-ASN: AS31976 209.132.180.0/23 X-Spam-Status: No, score=-3.3 required=3.0 tests=AWL,BAYES_00,BODY_8BITS, DKIMWL_WL_MED,DKIM_SIGNED,DKIM_VALID,DKIM_VALID_EF, HEADER_FROM_DIFFERENT_DOMAINS,MAILING_LIST_MULTI,RCVD_IN_DNSWL_MED, SPF_HELO_PASS,SPF_PASS shortcircuit=no autolearn=ham autolearn_force=no version=3.4.2 Received: from sourceware.org (server1.sourceware.org [209.132.180.131]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by dcvr.yhbt.net (Postfix) with ESMTPS id 7884B20248 for ; Wed, 20 Mar 2019 15:32:57 +0000 (UTC) DomainKey-Signature: a=rsa-sha1; c=nofws; d=sourceware.org; h=list-id :list-unsubscribe:list-subscribe:list-archive:list-post :list-help:sender:from:to:cc:subject:date:message-id:references :in-reply-to:content-type:content-transfer-encoding :mime-version; q=dns; s=default; b=X+Ls9gVAZgdkZkYkhTukTBjzzX/SV 5ANyBZ71cZBxHs4umTTKL+0nkB+r3GsEQhX7CMr4LW0p/qkeuq+TENZK7dkCfaq6 fgijq75lfPl+lyYLPY+DJQGg92AcnW3ixZAVbsWXaLrY9KdqPV+X0TwEbZQ41TzJ 2kGmLhtWCg1rRI= DKIM-Signature: v=1; a=rsa-sha1; c=relaxed; d=sourceware.org; h=list-id :list-unsubscribe:list-subscribe:list-archive:list-post :list-help:sender:from:to:cc:subject:date:message-id:references :in-reply-to:content-type:content-transfer-encoding :mime-version; s=default; bh=8Rcb1ECcqHPDQqg22KhESVWWulk=; b=CJ+ 0a9iNEQok3aY5Ax+U4BO2uYF79h18juJkK1kbTLMU7qoJUH/WWf3p/KVyBT6pDy7 +xQq0ARWEAlQ99xt1niRLkpJIFdCtetDb1boWr+tva109v50eE7gEKrpSvqO4dYU Jd0dUx/hP25+tyWxn6W9EiQDhdWmN4Sx7IiRyt0Q= Received: (qmail 82081 invoked by alias); 20 Mar 2019 15:32:55 -0000 Mailing-List: contact libc-alpha-help@sourceware.org; run by ezmlm Precedence: bulk List-Id: List-Unsubscribe: List-Subscribe: List-Archive: List-Post: List-Help: , Sender: libc-alpha-owner@sourceware.org Received: (qmail 82070 invoked by uid 89); 20 Mar 2019 15:32:54 -0000 Authentication-Results: sourceware.org; auth=none X-HELO: EUR03-AM5-obe.outbound.protection.outlook.com DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=armh.onmicrosoft.com; s=selector1-arm-com; h=From:Date:Subject:Message-ID:Content-Type:MIME-Version:X-MS-Exchange-SenderADCheck; bh=sc1jkqno+5ZHVDcSTQe/jQFQXcKnK3hx7kqzvOXsoa0=; b=qcjyRMLg4PAzUDW2ht9cZAViNDiwMTOxnlbVaUoSFkOmtDfrvKk2wNdmCeMENAHC54vylWsGqtOww9k/yNmpVsrl9bkYQzNmahuLKgWf0nxDNMgoCAvfMWU6jHfUdGQyqEIr9/zwv48Kcj9MwskuVH9oNFgXw7QazZ2pEa9hILk= From: Wilco Dijkstra To: Adhemerval Zanella CC: nd , "libc-alpha@sourceware.org" Subject: Re: [PATCH v2 4/6] Do not use HP_TIMING_NOW for random bits Date: Wed, 20 Mar 2019 15:32:50 +0000 Message-ID: References: ,<6ea276af-aa62-2bfe-ee6c-83c8eeaf283a@linaro.org> In-Reply-To: <6ea276af-aa62-2bfe-ee6c-83c8eeaf283a@linaro.org> authentication-results: spf=none (sender IP is ) smtp.mailfrom=Wilco.Dijkstra@arm.com; received-spf: None (protection.outlook.com: arm.com does not designate permitted sender hosts) x-ms-exchange-senderadcheck: 1 Content-Type: text/plain; charset="iso-8859-1" Content-Transfer-Encoding: quoted-printable MIME-Version: 1.0 X-MS-Exchange-CrossTenant-mailboxtype: HOSTED Hi Adhemerval, > +# include > +# define RANDOM_BITS(Var) ((Var) =3D random_bits ()) >=20 > This define is not used (removed above). > I think we need to still define it if we eventually decide to sync it bac= k > to gnulib. Well this is the question - do we really need all this clutter just for gnu= lib? It looks to me we should keep the code as clean as possible (so we don't need any the !_LIBC code given these files are always in LIBC). > I fact the new line should not be added, since random_time_bits should al= ready > get the random_bits() value. In any case I think we can remove random_tim= e_bits > altogether and just call RANDOM_BITS on value instead. Agreed. > And it seems 'value' is static by design, but I do agree there is no impe= ding > reason to continue to do so. Indeed. --- diff --git a/sysdeps/posix/tempname.c b/sysdeps/posix/tempname.c index 5217cb38e1..d062e4b82f 100644 --- a/sysdeps/posix/tempname.c +++ b/sysdeps/posix/tempname.c @@ -73,6 +73,13 @@ =A0#ifdef _LIBC =A0# include =A0# define RANDOM_BITS(Var) ((Var) =3D random_bits ()) +# else +# define RANDOM_BITS(Var) \ +=A0=A0=A0 {=A0=A0=A0=A0=A0=A0=A0=A0=A0=A0=A0=A0=A0=A0=A0=A0=A0=A0=A0=A0=A0= =A0=A0=A0=A0=A0=A0=A0=A0=A0=A0=A0=A0=A0=A0=A0=A0=A0=A0=A0=A0=A0=A0=A0=A0=A0= =A0=A0=A0=A0=A0=A0=A0=A0=A0=A0=A0=A0=A0=A0=A0=A0=A0=A0=A0=A0=A0=A0=A0=A0=A0= =A0 \ +=A0=A0=A0=A0=A0 struct timeval tv;=A0=A0=A0=A0=A0=A0=A0=A0=A0=A0=A0=A0=A0= =A0=A0=A0=A0=A0=A0=A0=A0=A0=A0=A0=A0=A0=A0=A0=A0=A0=A0=A0=A0=A0=A0=A0=A0=A0= =A0=A0=A0=A0=A0=A0=A0=A0=A0=A0=A0=A0=A0=A0=A0 \ +=A0=A0=A0=A0=A0 __gettimeofday (&tv, NULL);=A0=A0=A0=A0=A0=A0=A0=A0=A0=A0= =A0=A0=A0=A0=A0=A0=A0=A0=A0=A0=A0=A0=A0=A0=A0=A0=A0=A0=A0=A0=A0=A0=A0=A0=A0= =A0=A0=A0=A0=A0=A0=A0=A0=A0 \ +=A0=A0=A0=A0=A0 (Var) =3D ((uint64_t) tv.tv_usec << 16) ^ tv.tv_sec;=A0=A0= =A0=A0=A0=A0=A0=A0=A0=A0=A0=A0=A0=A0=A0=A0=A0=A0=A0=A0=A0 \ +=A0=A0=A0 } =A0#endif =A0 I don't see the point of this, especially using gettimeofday. If we want to= export these changes to gnulib, we could just add random_bits to gnulib. -=A0 value +=3D random_time_bits ^ __getpid (); -=A0 value +=3D random_bits () ^ __getpid (); +=A0 RANDOM_BITS (value); +=A0 value ^=3D __getpid (); +=A0 /* Shuffle the lower bits to minimize the pid bias due low maximum val= ue.=A0 */ +=A0 value =3D (value << 24) | (value >> 8); random_bits already does that shuffle, so doing it again doesn't help. It's= better to avoid the aliasing of getpid with the random bits, eg. value ^=3D __get_= pid << 32 so we end up with more than 32 random bits. Wilco =