What is entropy pool in linux and how to generate and see the entropy pool data ?

I. Introduction
Entropy pool is a large number (typically around 4096 bits) stored in a memory location which can be read by programs.

This large number is a random number generated by the actual hardware noise received by various hardware devices like mouse, keyboard, etc.

Interesting feature is that the randomness of this pool varies each time when its read w.r.t. different hardware devices.

/dev/random and /dev/urandom difference
/dev/random uses so-called entropy pool and hence takes a bit more time, also sometimes no random data is available.
/dev/urandom returns any number of random data quickly as requested by the user and is not dependent on entropy pool, hence it is less random than /dev/random.

 

II. How to use this entropy pool to get random data ?

-bash-4.1# date; dd if=/dev/random of=random_test count=4 bs=512; date
Tue Jun 25 04:15:40 PDT 2019


^C0+0 records in
0+0 records out
0 bytes (0 B) copied, 17.4556 s, 0.0 kB/s

-bash-4.1# du -sh random_test 
0	random_test

We can see above no data in the random file as the entropy pool is empty.

To quickly generate data, lets see the usage of urandom.

-bash-4.1# date; dd if=/dev/urandom of=random_test count=4 bs=512; date
Tue Jun 25 04:16:13 PDT 2019
4+0 records in
4+0 records out
2048 bytes (2.0 kB) copied, 0.00039823 s, 5.1 MB/s
Tue Jun 25 04:16:13 PDT 2019
-bash-4.1# 

-bash-4.1# head random_test 
??M\??6AX???????+?,?F???fI?R?E
                              ?e?`Y:(?wB?;-	'?


III. See entropy pool configuration

### Pool data size
-bash-4.1# cat /proc/sys/kernel/random/poolsize 
4096

### Input pool entropy count
-bash-4.1# cat /proc/sys/kernel/random/entropy_avail 
2531
-bash-4.1# 

 

IV. Read random number data from /dev/random and /dev/urandom files.
od generates the octal, decimal, hex, ASCII dump, “-d” is to get only signed decimal data.

-bash-4.1# od -d /dev/urandom | head
0000000 40451 59532 29653 61171 50133  4667 40269 39364
0000020  2582 61849 22404 21982   733 38884 33145 50113
0000040 31066 38620 36771 41443 48151 30907 11008 39348
0000060 21674 55378 26910 16485 56464 17535 42537 58337
0000100 51681 24647 64184 61225 32217 18833 43709 15156
0000120 28104 25262 20084  9476 61609 46824  1700 32209
0000140  1449 17641  1065 13468 19949 12327 40879 64325
0000160 45299 46966 55111 16023  3964 43137  1450 50320
0000200 19060  3414  4812 56252 38964 18704 33070 59492
0000220 39810 27690 12853 45599 30668 29172 35796 16358


-bash-4.1# od -d /dev/random | head


CPU Time Jitter

We can still see the entropy data generated is none, and is very slow.

Leave a Reply

avatar
  Subscribe  
Notify of