Why does dd only copy 128 bytes from /dev/random when I request more?
Rise to the top 3% as a developer or hire one of them at Toptal: https://topt.al/25cXVn
--------------------------------------------------
Music by Eric Matyas
https://www.soundimage.org
Track title: Beneath the City Looping
--
Chapters
00:00 Why Does Dd Only Copy 128 Bytes From /Dev/Random When I Request More?
00:50 Accepted Answer Score 8
01:50 Answer 2 Score 3
02:31 Thank you
--
Full question
https://superuser.com/questions/520601/w...
--
Content licensed under CC BY-SA
https://meta.stackexchange.com/help/lice...
--
Tags
#linux #commandline
#avk47
ACCEPTED ANSWER
Score 8
You need to use /dev/urandom
, or the "unblocking" random source.
/dev/random
uses a kind of entropy pool to increase the randomness of the bit source. This method will only return as many random bits/bytes as can be returned based on the entropy pool's state at the time, so if a hardware random number generator is used, this can sometimes be a constant. From the Linux manpage:
The generator also keeps an estimate of the number of bits of noise in the entropy pool. From this entropy pool random numbers are created.
The /dev/urandom
file keeps reusing the internal pool as-is to generate a number as long as you need. The side-effect of this is: do not use /dev/urandom
for cryptographic purposes, as it is less random than the bits produced by /dev/random
. See the manpage link above for details.
ANSWER 2
Score 3
Since reading /dev/random
returns only the amount of bytes that is available, you have to specify block size 1. In your example, you set block size to 512 which fails after the first read.
Therefore, the correct arguments that reads exactly 512 bytes is:
dd if=/dev/random of=filename bs=1 count=512
Note the command will block until there's enough entropy in the system to generate all the data. That's how /dev/random
works. If you don't want to wait and you are fine with less entropy, use /dev/urandom
instead. In vast majority of cases using /dev/urandom
is preferred.