From mboxrd@z Thu Jan 1 00:00:00 1970 X-Msuck: nntp://news.gmane.org/gmane.linux.lib.musl.general/2705 Path: news.gmane.org!not-for-mail From: Szabolcs Nagy Newsgroups: gmane.linux.lib.musl.general Subject: Re: [PATCH] Add support for mkostemp, mkstemps and mkostemps Date: Thu, 31 Jan 2013 01:28:09 +0100 Message-ID: <20130131002808.GI6181@port70.net> References: <1359349583-3643-1-git-send-email-basile@opensource.dyc.edu> <20130128093755.GI10600@port70.net> <5108583B.4080002@opensource.dyc.edu> <20130130072108.GN20323@brightrain.aerifal.cx> <5108D2F7.3050207@qomboo.com> <20130130134537.GF6181@port70.net> <20130130165127.GO20323@brightrain.aerifal.cx> <20130130191257.GH6181@port70.net> <20130130192233.GP20323@brightrain.aerifal.cx> Reply-To: musl@lists.openwall.com NNTP-Posting-Host: plane.gmane.org Mime-Version: 1.0 Content-Type: text/plain; charset=us-ascii X-Trace: ger.gmane.org 1359592100 20618 80.91.229.3 (31 Jan 2013 00:28:20 GMT) X-Complaints-To: usenet@ger.gmane.org NNTP-Posting-Date: Thu, 31 Jan 2013 00:28:20 +0000 (UTC) To: musl@lists.openwall.com Original-X-From: musl-return-2706-gllmg-musl=m.gmane.org@lists.openwall.com Thu Jan 31 01:28:40 2013 Return-path: Envelope-to: gllmg-musl@plane.gmane.org Original-Received: from mother.openwall.net ([195.42.179.200]) by plane.gmane.org with smtp (Exim 4.69) (envelope-from ) id 1U0i19-0003IB-Vr for gllmg-musl@plane.gmane.org; Thu, 31 Jan 2013 01:28:40 +0100 Original-Received: (qmail 19786 invoked by uid 550); 31 Jan 2013 00:28:21 -0000 Mailing-List: contact musl-help@lists.openwall.com; run by ezmlm Precedence: bulk List-Post: List-Help: List-Unsubscribe: List-Subscribe: Original-Received: (qmail 19778 invoked from network); 31 Jan 2013 00:28:21 -0000 Content-Disposition: inline In-Reply-To: <20130130192233.GP20323@brightrain.aerifal.cx> User-Agent: Mutt/1.5.21 (2010-09-15) Xref: news.gmane.org gmane.linux.lib.musl.general:2705 Archived-At: * Rich Felker [2013-01-30 14:22:33 -0500]: > On Wed, Jan 30, 2013 at 08:12:58PM +0100, Szabolcs Nagy wrote: > > void __randname(char *p) > > { > > struct timespec ts; > > unsigned long r; > > int i; > > > > clock_gettime(CLOCK_REALTIME, &ts); > > r = ts.tv_nsec*65537 ^ (uintptr_t)&ts / 16 + (uintptr_t)p; > > for (i=0; i<6; i++, r>>=5) > > p[i] = 'A'+(r&15)+(r&16)*2; > > } > > > > this uses 30bits of r and mixes the random low bits of nsec > > into the high bits > > Keep in mind it might be bits 8-15 that are most valuable with ASLR > (assuming the randomization only adjusts by small amounts and not so > much to waste lots of address space). I think this needs a little bit > more consideration. hm then use *69069 (a favourite lcg multiplier of the above mentioned george marsaglia according to knuth, [taocp vol2 p108] so it probably mixes the low bits of nsec well) > > > Other implementations probably use 36 bits or slightly less (base64 > > > perhaps modified base64). > > > > > > I could see it being feasible to increase this slightly and maybe even > > > > <= 36bits is probably ok > > You mean >=36? Or..? i wanted to say that using <=64 chars in the filename is reasonable (i thought there were only 62 robust chars: lower,upper,digits so going above 36 does not make sense and we have 32bit input anyway) but maybe #%+-._~ are ok as well (these are the ascii chars that are not escaped by bash for whatever reason), except #+-.~ should not be first char in urls only -._ are the always safe extra chars in regex #%-_~ are safe from the above set but if we go above 62chars then more than 32bit input is needed another proposal: uint64_t r=1; uint64_t a[]={stackptr, inputptr, sec, ns, pid, retrycount}; // entropy sources for (i = 0; i < 6; i++) { r += a[i]; r *= 6364136223846793005ull; r ^= r>>24; } for (i = 0; i < 6; i++, r /= 63) p[i] = "ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789_"[r%63];