| Store | Cart

Re: [Python-Dev] PEP 506 secrets module

From: Serhiy Storchaka <stor...@gmail.com>
Fri, 16 Oct 2015 18:35:14 +0300
On 16.10.15 09:57, Victor Stinner wrote:
> I suggest to raise an error if token_bytes(n) if calls with n < 16> bytes (128 bits). Well, I'm not sure that 16 is the good compromise> between performance and security, but we must enforce users to use a> minimum number of bits of entropy. token_bytes(1) looks valid, even> token_bytes(0), according to the Python code in the PEP.

This will provoke to write code token_bytes(16)[:5].

> I don't like the idea how having two functions doing *almost* the same> thing: randint() and randrange(). There is a risk that these functions> will be misused. I consider that I know some stuff on PRNG but I'm> still confused by randint() and randrange(). Usually, I open python> and type:>>>>> x=[s.randrange(1,6) for n in range(100)]>>>> min(x), max(x)> (1, 5)>> Hum, ok, it's not a good dice :-) I probably wanted to use randint().> So I suggest to only add randint() to secrets.

I suggest to add only randrange(). randint() is historical artefact, we 
shouldn't repeat this mistake in new module. The secrets module is not 
good way to generate dice rolls. In most other cases you need to 
generate integers in half-open interval [0; N).

And randbelow() is absolute redundant. Random._randbelow() is 
implementation detail and I inclined to get rid of it (implementing 
randrange() in C instead).


_______________________________________________
Python-Dev mailing list
Pyth...@python.org
https://mail.python.org/mailman/listinfo/python-dev
Unsubscribe: https://mail.python.org/mailman/options/python-dev/python-dev-ml%40activestate.com

Recent Messages in this Thread
Steven DAprano Oct 16, 2015 12:57 am
Chris Rebert Oct 16, 2015 05:33 am
Victor Stinner Oct 16, 2015 06:57 am
Steven DAprano Oct 16, 2015 10:04 am
Chris Angelico Oct 16, 2015 10:32 am
Nick Coghlan Oct 20, 2015 09:11 am
Victor Stinner Oct 20, 2015 09:33 am
Nick Coghlan Oct 20, 2015 09:56 am
Serhiy Storchaka Oct 16, 2015 03:35 pm
Steven DAprano Oct 16, 2015 04:26 pm
Serhiy Storchaka Oct 16, 2015 06:29 pm
Guido van Rossum Oct 16, 2015 06:33 pm
Steven DAprano Oct 17, 2015 09:50 am
Guido van Rossum Oct 17, 2015 07:51 pm
Random832 Oct 17, 2015 08:30 pm
Tim Peters Oct 17, 2015 09:13 pm
Guido van Rossum Oct 17, 2015 11:05 pm
Brett Cannon Jan 14, 2016 06:36 pm
Guido van Rossum Jan 14, 2016 06:47 pm
Messages in this thread