[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]
Re: urandom number in Emacs
From: |
Emanuel Berg |
Subject: |
Re: urandom number in Emacs |
Date: |
Sun, 07 Nov 2021 09:49:27 +0100 |
User-agent: |
Gnus/5.13 (Gnus v5.13) Emacs/29.0.50 (gnu/linux) |
Omar Polo wrote:
> I mean, if you really need something like that and emacs
> doesn't already provide it, why don't try cooking a diff to
> add it to base emacs instead that an external module?
`random' isn't good enough for passwords, it could since it is
a C built-in read from /dev/urandom but it doesn't, and you
can't do that from Lisp since /dev/urandom is a non-regular
file. head(1) and pwgen(1) can do it from C and so can Emacs,
but to have it as a Lisp primitive or a DM ... but isn't that
why you have DMs, you shouldn't have to recompile the whole
thing to get it? It is more ... modular?
> Also, the code is wrong:
>> if (nbytes == 0) {
>> return (rnd_num % max_num);
>> } else {
>> fprintf(stderr, "No entropy available!\n");
>> exit(1);
>> }
>
> I don't think you want to quit emacs unconditionally if
> there's no entropy.
OK ... I'll just return something to denote it didn't work.
Hm ...
> Also, in some circumstances there could be better (and
> faster) ways to obtain a random number, see for
> e.g. arc4random.
Doesn't that read from /dev/urandom as well?
What's better/faster about it? You need a DM/recompile for
that as well since it is in libc, or am I wrong?
Nah, if it was good enough for pwgen(1) I take it ...
> P.S.: are you sure about checking for EAGAIN? A read for
> a file descriptor not marked as non-blocking shouldn't fail
> with EAGAIN
I am not sure, again they had it in pwgen ...
> but that's a minor nitpick.
Indeed ... hehe
--
underground experts united
https://dataswamp.org/~incal