I've decided to try writing a script for my R7800. I have been reading about BusyBox and in the OpenWRT documentation. I can generate a random number in my Ubuntu terminal easily, but not in the OpenWRT terminal. I either get a syntax error or a permission denied. I know of a hardware version at /dev/urandom, but permission was denied. Without resorting to script dedicated to a random number generator, is there a command accessible to me inside OpenWRT for a simple random number generator? I wanted to avoid starting/restarting a device or downloading a package.
I found this page, and the bottom most comment has the following command (the user says is unreliable, not sure why -- it does appear to work and probably well enough for most practical purposes):
$(head -30 /dev/urandom | tr -dc "0123456789" | head -c3)
Need more digits -- change head -c3
to head -c10
or whatever number of digits is required.
The thing is that router hardware (embedded devices) doesn’t have meaningful hardware support to actually seed a random number generator with cryptographic meaningful data.
That is why you never ever make crypto keys on these kind of simple embedded hardware devices.
A real computer makes DRNG better, sometimes they actually have embedded DRNG in the cpu but they don’t do the whole job. The seeding is a continuously process that seeds random data from everything the computer does but human interaction with mice and keyboard is i big seeding tool for the DRNG.
But making a good DRNG is pretty much the hardest problem there is in the world since computer hardware aren’t random to begin with. So the concept demands a working computer to be broken to work fine.
Or if you want to visualize the “thing” of DRNG.
Download the RasyRSA to both the router and computer that hopefully have a modern Intel cpu.
And make a 2048bit DH key.
Then you will see the difference in DRNG for embedded or not embedded devices.
A hint is that the embedded device will take many hours to make that key while the computer takes about 5seconds.
I don't know how big your random number is being generated but you could use CURL and get it from random.org or other site.
- If you have
rngd
installed - The hardware is actually at /dev/hwrng
cat /dev/hwrng
causes a stream of randomness for me.
I little while after I logged off from the forum, I came across that exact page. Thanks for the link and the confirmation. The command worked fine. I needed to randomize just a few numbers and the command gave me that choice. I changed all the variables to fit the rest of my script. Thanks for the advice about changing head
to -c10 or whatever is required.
I had already used this command before I logged back in to the forum. I'll toggle this as the solution. It fit right into what I was doing. Thanks to all for the rest of the advice. That will be useful to me as I write other scripts. I had a MATLAB scripting class one time in my distant past, but not BusyBox/Linux shell. The commands are a little different. As was mentioned before, embedded devices have some limitations (but they are fun!). Thanks for the help.
Thanks for the information. I learn more about the practical side of things on this type of forum than in the datasheets.
Thanks for that tip. I'll experiment with it.
Thanks. I had been doing manual random numbers, but wanted to get something self contained and automated and while offline. That's a good idea, though, and I can use the advice for another script later.
This topic was automatically closed 10 days after the last reply. New replies are no longer allowed.