Re: [PATCH] Improve mutt's random data generator.

"Kevin J. McCarthy" <[email protected]>
Newsgroups gmane.mail.mutt.devel
Message-ID <aerZahPj01Cp0LV5@qinghai>
On Thu, Apr 23, 2026 at 10:12:25PM -0400, Kurt Hackenberg wrote:
>On Fri, Apr 24, 2026 at 09:48 +0800, Kevin J. McCarthy wrote:
>
>>Ah, sorry.  Yes, the code is executed.  The whole snippet is:
>>
>> if ((res == (size_t) -1) || (res < length_requested))
>> {
>>   if (res < length_requested)
>>   {
>>     length_requested -= res;
>>     random_bytes += res;
>>   }
>>   prng_random_bytes(random_bytes, length_requested);
>> }
>
>I don't know what prng_random_bytes() is, so don't quite know the 
>intent here. But counting on (res < length_requested) when getrandom() 
>failed seems like pushing C pretty hard.

The man page says:

On success, getrandom() returns the number of bytes that were copied to 
the buffer buf.  This may be less than the number of bytes requested via 
size if either GRND_RANDOM was specified in flags and insufficient 
entropy was present in the random source or the system call was 
interrupted by a signal.

On error, -1 is returned, and errno is set to indicate the error.

So that outer "if" checks for one of two possibilities we need to 
correct for: failure (-1), or less than the number bytes requests via 
size.

The call to prng_random_bytes() was falling back on the pseudo random
generator.

However, I'm think I'll take the fallback out, and just loop the call to 
getrandom() until we fill the buffer up.  I'll send a v2 patch today or 
tomorrow.

Thanks for your feedback, Kurt and Alex!

-- 
Kevin J. McCarthy
GPG Fingerprint: 8975 A9B3 3AA3 7910 385C  5308 ADEF 7684 8031 6BDA
signature.asc (application/pgp-signature, 833 B)
-----BEGIN PGP SIGNATURE-----

iQIzBAEBCgAdFiEEiXWpszqjeRA4XFMIre92hIAxa9oFAmnq2WoACgkQre92hIAx
a9rPEQ//XNJncpgbq8Cf+upUq32UeuHd6EMFlM+p0myeBNQTKuNMbEKVFp8ukEZ2
5mpEBqCu26rR0+OXWCdmb7Qj4gzCJ7nqszfnqManOlQcKAW1qiJ1SOAYVcNafKxs
0Ky2UZMYtM2xYBj+ozNjSLPLnoFuNojuKGqJWZxc/5TzCJQmo7mQPW2Y4ceOARfk
pbwxAwjH5LnJK+iq7jcPZi3IZKJSHREc5woFBz1Z4T6NBL4wL1tVl7RWJRRIEY9M
LCCogqoxS0qDFKXvQBfczHiTSp324BnyxoU7GMd5FbFnbNWoYddGkoJxs103stN6
qxVPa0tDJTXSQSnKqXfsizwuDmyU88K6vQTBRgUfqWIMnymxaVOzGPIQP3o5Tomb
gDUvs1ZkAQNEJs10Y5FWjeH4hB1yMp1RoWrBzJ+/RIpIzGGZlhZipkBwfldhQeTk
QZRT19vGZamLrpaSdD258WUTI3UTAU9MdZDjZFiAkOp5pgVphQxKDQaZT7Utj5cQ
hhPfNeJMu53WVvwfENaYPQClJAcK1Q4PsZIg7O6ta6UkZX9fJaA44DsVzFJPUZc8
Xl5m+CAFWfuB5OvRniYQXDgskIwTtSbbYS7Ye7GPICyFR9voCDcK9QaMLNoI03Tn
oduU47cCgMaDgIgyafwadvEnU2D7U3q3ipMJjQOWteuL8LB1yVY=
=8La3
-----END PGP SIGNATURE-----
lmpx.com only provides a reader for public news (NNTP) servers. It is not affiliated with the servers or forums shown here and is not responsible for the content of articles, which is written by their respective authors.