From mboxrd@z Thu Jan 1 00:00:00 1970 X-Spam-Checker-Version: SpamAssassin 3.4.4 (2020-01-24) on inbox.vuxu.org X-Spam-Level: X-Spam-Status: No, score=-3.3 required=5.0 tests=DKIM_SIGNED,DKIM_VALID, MAILING_LIST_MULTI,RCVD_IN_DNSWL_MED autolearn=ham autolearn_force=no version=3.4.4 Received: (qmail 2940 invoked from network); 18 Nov 2022 18:13:15 -0000 Received: from zero.zsh.org (2a02:898:31:0:48:4558:7a:7368) by inbox.vuxu.org with ESMTPUTF8; 18 Nov 2022 18:13:15 -0000 ARC-Seal: i=1; cv=none; a=rsa-sha256; d=zsh.org; s=rsa-20210803; t=1668795195; b=Y5bMeeWwa6b0HnS5xsK0lAUcghM96mu1GSnK/SSJ0kDz6kUEZPr7lQZewA2YnoC1Bff/ysnWk3 mlRVllS2nT9/pI8kdbqkmU4CpJ/4Zkn0RnTNweRS+eR797U4+QlOBJgwy0a0q9rRGVRzIoGEkP NYzAvydHBbjmTnLFBQnkcahZ3QRyVPY6kSxSjtfSdVuKx3kDMcWHmv8Ag5JX2kNccQH8rt2UDz BGHybWHA7vMID4LkOUohLcJwrUa7O4AWNGvfPPuqMyBaca6KUNO3q3f6Cbn/4x7Nv9gmXhfvK8 nKFXHZbU+BvYbXVTJVU2GeC9OA3xEnSXs/lDv7HS/l5XVg==; ARC-Authentication-Results: i=1; zsh.org; iprev=pass (relay9-d.mail.gandi.net) smtp.remote-ip=217.70.183.199; dmarc=none header.from=chazelas.org; arc=none ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed; d=zsh.org; s=rsa-20210803; t=1668795195; bh=N6VRcn/yhYif6jLywfIM7PzknBrr6eWaq8lyD23wwwQ=; h=List-Archive:List-Owner:List-Post:List-Unsubscribe:List-Subscribe:List-Help: List-Id:Sender:In-Reply-To:Content-Transfer-Encoding:Content-Type: MIME-Version:References:Message-ID:Subject:Cc:To:From:Date:DKIM-Signature; b=ezPWsy2gRlovDJeZPhrnV0khQD8MClKAOjclie98ybnthnWjTIHxzLJreIvMPbibWCKlMByw+o IJHdA+SI+1mGw5UcuULO6iEB/3Ak/ZDXtaNVOWPzLoGQgAPbPbPYP1IHk7AdvrEH3TckPjGmIU 5cK6HrjXMFDpVkr+pyc6yPEccUUMWwAMRcvGzL8tQQ2OWZT+y++j/gHMcjbtH/ZYOXSJZIyfvG uPfsucY0WDTfUj6djc4UkIqRuGU2LAsnmtdQctamS2lqK6GASKRUfjzkT+lTr6MGtjtSkSFFQw zj78Tjw6yCr18Rc1HsRpbr8hlIull20ITd3hZJiybckpLA==; DKIM-Signature: v=1; a=rsa-sha256; q=dns/txt; c=relaxed/relaxed; d=zsh.org; s=rsa-20210803; h=List-Archive:List-Owner:List-Post:List-Unsubscribe: List-Subscribe:List-Help:List-Id:Sender:In-Reply-To:Content-Transfer-Encoding :Content-Type:MIME-Version:References:Message-ID:Subject:Cc:To:From:Date: Reply-To:Content-ID:Content-Description:Resent-Date:Resent-From:Resent-Sender :Resent-To:Resent-Cc:Resent-Message-ID; bh=FH2HvJb4e7OlWEnvbKw1uAm1w1LfN3NfFNAU5jeuF/4=; b=kNoGWLCuUgI6Fe8Uk48AHwcEBp 453N6XQFW+4OGOZoQZ2/R4LKIpPPsbWfJke/KJ4sw/AlX+X1msusxn+pKRRto23sl/opzkjyxxLHw cB9Afr64GtGDCy9JiVLxQeH5aFb/NBz79ICgZhxse2pVjB8hiJ1HTEF7xeY/AphPI5j/wGySs8AcE bGhzINBZ1Bc8EdhG9nN+OZeMvNqnJLN5jWFVyW0jyJNrnOcytDkyQisylHiTGT/MWrsxsDCvZRbmb KK6x4e8edH2rZFsUZQkqKOWj+P+Gw+ehGkth3gvR/U9bljSMJPY7+UkhXJcVVhVt75s9KH9MSHMtY 7oaNEn/Q==; Received: by zero.zsh.org with local id 1ow5rW-000Hx4-KH; Fri, 18 Nov 2022 18:13:14 +0000 Authentication-Results: zsh.org; iprev=pass (relay9-d.mail.gandi.net) smtp.remote-ip=217.70.183.199; dmarc=none header.from=chazelas.org; arc=none Received: from relay9-d.mail.gandi.net ([217.70.183.199]:36929) by zero.zsh.org with esmtps (TLS1.2:ECDHE-RSA-AES256-GCM-SHA384:256) id 1ow5rD-000Had-7Z; Fri, 18 Nov 2022 18:12:55 +0000 Received: (Authenticated sender: stephane@chazelas.org) by mail.gandi.net (Postfix) with ESMTPSA id 82F49FF806; Fri, 18 Nov 2022 18:12:54 +0000 (UTC) Date: Fri, 18 Nov 2022 18:12:53 +0000 From: Stephane Chazelas To: Clinton Bunch Cc: zsh-workers@zsh.org Subject: Re: [PATCH] zsh/random module [UPDATED] Message-ID: <20221118181253.cdejvepmnsmia7jm@chazelas.org> Mail-Followup-To: Clinton Bunch , zsh-workers@zsh.org References: <741b77be-b679-76cc-f8ec-49c9d89323c1@zentaur.org> <1e8ea669-7a25-b321-6024-72dbc43ac023@zentaur.org> <41205a86-8aad-4821-baa4-1d2ac9bf3c5d@app.fastmail.com> <1b2cafe6-b4b5-c59a-11f3-4dbc1e99e2bc@zentaur.org> <6275a5ac-3a47-f591-7b3c-380ec4fed5ac@zentaur.org> <20221118162325.7i3qzqljyx4a7z3h@chazelas.org> MIME-Version: 1.0 Content-Type: text/plain; charset=iso-8859-1 Content-Disposition: inline Content-Transfer-Encoding: 8bit In-Reply-To: X-Seq: 50997 Archived-At: X-Loop: zsh-workers@zsh.org Errors-To: zsh-workers-owner@zsh.org Precedence: list Precedence: bulk Sender: zsh-workers-request@zsh.org X-no-archive: yes List-Id: List-Help: , List-Subscribe: , List-Unsubscribe: , List-Post: List-Owner: List-Archive: 2022-11-18 11:08:42 -0600, Clinton Bunch: [...] > > Some comments about the API: > > > > > -c COUNT > > > Sets the number of returned random data. Defaults to 8, > > > unless -i, -L, or -U is specified without -a, in which case > > > the default is 1. COUNT must be between 1 and 64. > > Why those arbitrary limits? Why not from 0 to inf? > > the getrandom function only guarantees 256 bytes.  64 32-bit integers.  > Allowing 256 uint8 would be possible, but harder to explain and doesn't work > well with bounding.  As the difference between the lower and upper limit > surpasses half the max, the number of bytes thrown away to allow uniformity > of distribution becomes unwieldy. > > Also zero would not be particularly useful :) You could call getrandom() as many times as necessary. From a user point of view (mine at least) that limit doesn't make sense. Users don't care what API you use underneath. An array can have from 0 to inf elements, a string 0 to inf bytes, I should be able to request from 0 to inf numbers/bytes to store in my array/string. > > Without -i you get uint8 in hex and with -i uint32 in decimal. > > Why the different bases? > > It's possible to break a hex string into bytes in a rather straight forward > way.   A string of decimal numbers not so much, but decimal numbers are > easier to manipulate. > > If I didn't think it should do *something* when given no arguments, I'd > eliminate the hex string altogether. Alternatively, you could add a -f %02x, -f %u -f %c and do without the -r/-i, with default -c 8 -f %02x -L 0 -U 255. Or maybe keep the -i but only as an alias for -c 1 -f %u -L 0 -U $((2**32-1)). (-r would be -f %c) [...] > > Trying to use it to get a random word with it, I came up with: > > > > $ set -o extendedglob > > $ l=({A..Z} {a..z} {0..9} _) > > $ getrandom -a a -c20 -L1 -U$#l > > $ echo ${(j[])a//(#m)*/$l[MATCH]} > > EMhKvFuQlmCVSuet5uh0 > > > > Doing it straight by reading /dev/urandom would have been a lot > > more awkward. Could that be improved/simplified? > It could be done, but a list of acceptable characters would need to be > agreed upon and documented.  Are symbols acceptable?  About half of > passwords require them, but only accept certain ones and that differs from > website to website. [...] I was not suggesting you to add that as an extra feature to getrandom. -- Stephane