Hi,
Using 27.1.2, the compiler tells me:
fwknop.erl:78:25: Warning: crypto:rand_uniform/2 is deprecated; use rand:uniform/1 instead
As far as I can tell, rand_uniform is not cryptographically secure, whereas crypto:rand_uniform was intended to be, and probably (?) was, at least from about OTP 20 onwards.
Is the compiler’s advice as bad as it seems?
Matthias
Before crypto 3.0 the API used is BN_pseudo_rand_range which is documented as:
pseudo-random numbers generated by this function are not necessarily unpredictabl
Reference: BN_rand_range(3)
When running crypto 3.0 it uses BN_rand_range which is cryptographigally secure. So it depends on which version of libcrypto you are using. The deprecation of crypto:rand_uniform was done long before crypto 3.0 was created.
So using rand instead is a good option. If you want something that is cryptographically secure no matter which version of crypto you have, you should use strong rand bytes.
This should probably be made clear in the crypto docs. A PR would be most welcome.
3 Likes
Replying to my own post, and Lukas’ reply.
I decided to abandon the security code I was trying to update. It’s from a project that’s looking semi-abandoned and I decided leaving it semi-broken was better than risking introducing security problems because I’m not confident I know everything about the code.
The project is ‘fwknop’. It’s a good little tool (it protects SSH servers from being scanned from all over the internet), but its popularity has waned, in part because ‘wireguard’ has overlapping properties and is more popular. The github repo doesn’t have many recent commits, the mailing list has no posts for several years and the code has rotted in several ways.