Name
random, urandom - kernel
random number source devices
Description
<!--
google_ad_client = "pub-5823754184406795";
google_ad_slot = "5992934909";
google_ad_width = 300;
google_ad_height = 250;
//-->
<iframe name="google_ads_frame" marginwidth="0" marginheight="0" src="http://pagead2.googlesyndication.com/pagead/ads?client=ca-pub-5823754184406795&dt=1205818900718&lmt=1205818900&output=html&slotname=5992934909&correlator=1205818900500&url=http%3A%2F%2Flinux.die.net%2Fman%2F4%2Frandom&ref=http%3A%2F%2Fwww.google.cn%2Fsearch%3Fcomplete%3D1%26hl%3Dzh-CN%26newwindow%3D1%26rlz%3D1T4SHCN_zh-CNCN264CN266%26q%3Dmknod%2B%252Fdev%252Frandom%26meta%3D%26aq%3Df&frm=0&cc=302&ga_vid=1466898322.1205818901&ga_sid=1205818901&ga_hid=1407481144&flash=9.0.115.0&u_h=768&u_w=1024&u_ah=738&u_aw=1024&u_cd=32&u_tz=480&u_java=true" frameborder="0" width="300" scrolling="no" height="250" allowtransparency="allowtransparency"></iframe>
The character special files
/dev/random and
/dev/urandom (present since Linux 1.3.30) provide an interface to the kernel's
random number generator. File
/dev/random has major device number 1 and minor device number 8. File
/dev/urandom has major device number 1 and minor device number 9.
The random number generator gathers environmental noise from device drivers and other sources into an entropy pool. 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.
When read, the /dev/random device will only return random bytes within the estimated number of bits of noise in the entropy pool. /dev/random should be suitable for uses that need very high quality randomness such as one-time pad or key generation. When the entropy pool is empty, reads from /dev/random will block until additional environmental noise is gathered.
A read from the /dev/urandom device will not block waiting for more entropy. As a result, if there is not sufficient entropy in the entropy pool, the returned values are theoretically vulnerable to a cryptographic attack on the algorithms used by the driver. Knowledge of how to do this is not available in the current non-classified literature, but it is theoretically possible that such an attack may exist. If this is a concern in your application, use /dev/random instead.
Configuring
If your system does not have
/dev/random and
/dev/urandom created already, they can be created with the following commands:
mknod -m 644 /dev/random c 1 8
mknod -m 644 /dev/urandom c 1 9
chown root:root /dev/random /dev/urandom
When a Linux system starts up without much operator interaction, the entropy pool may be in a fairly predictable state. This reduces the actual amount of noise in the entropy pool below the estimate. In order to counteract this effect, it helps to carry entropy pool information across shut-downs and start-ups. To do this, add the following lines to an appropriate script which is run during the Linux system start-up sequence:
echo "Initializing random number generator..."
random_seed=/var/run/random-seed
# Carry a random seed from start-up to start-up
# Load and then save the whole entropy pool
if [ -f $random_seed ]; then
cat $random_seed >/dev/urandom
else
touch $random_seed
fi
chmod 600 $random_seed
poolfile=/proc/sys/kernel/random/poolsize
[ -r $poolfile ] && bytes='cat $poolfile' || bytes=512
dd if=/dev/urandom of=$random_seed count=1 bs=$bytes
Also, add the following lines in an appropriate script which is run during the Linux system shutdown:
# Carry a random seed from shut-down to start-up
# Save the whole entropy pool
echo "Saving random seed..."
random_seed=/var/run/random-seed
touch $random_seed
chmod 600 $random_seed
poolfile=/proc/sys/kernel/random/poolsize
[ -r $poolfile ] && bytes='cat $poolfile' || bytes=512
dd if=/dev/urandom of=$random_seed count=1 bs=$bytes
Proc Interface
The files in the directory
/proc/sys/kernel/random (present since 2.3.16) provide an additional interface to the
/dev/random device.
The read-only file entropy_avail gives the available entropy. Normally, this will be 4096 (bits), a full entropy pool.
The file poolsize gives the size of the entropy pool. Normally, this will be 512 (bytes). It can be changed to any value for which an algorithm is available. Currently the choices are 32, 64, 128, 256, 512, 1024, 2048.
The file read_wakeup_threshold contains the number of bits of entropy required for waking up processes that sleep waiting for entropy from /dev/random. The default is 64. The file write_wakeup_threshold contains the number of bits of entropy below which we wake up processes that do a select() or poll() for write access to /dev/random. These values can be changed by writing to the files.
The read-only files uuid and boot_id contain random strings like 6fd5a44b-35f4-4ad4-a9b9-6b9be13e1fe9. The former is generated afresh for each read, the latter was generated once.
Files
/
dev/
random/
dev/urandom
Author
The kernel's
random number generator was written by Theodore Ts'o (
tytso@athena.mit.edu).
分享到:
相关推荐
在Linux操作系统中,`/dev/random`是一个非常重要的特殊设备文件,它被设计用来提供真正的随机数据流。这个设备是基于熵池(entropy pool)的,熵池收集系统中的不可预测事件,如用户键盘敲击、网络包到达时间等,...
ln /dev/urandom /dev/random”,这样可以将 /dev/random 链接到 /dev/urandom,从而解决随机数生成的延迟问题。 ### 方法三:修改 JDK 的安全配置文件 可以修改 Linux 上 Weblogic 使用的 JDK 的安全配置文件 $...
这些工具利用/dev/hw_random来填充内核熵池,熵池被内核内部使用,并通过/dev/urandom和/dev/random特殊文件对外导出。 **工作原理** 1. **字符设备** 通过标准的open()和read()系统调用,可以直接从硬件RNG设备...
[2023-06-21 14:30:31] # random: Got 5/5 bytes from /dev/random
* /dev/random:随机数设备 * /dev/urandom:随机数设备 这些设备文件可以让用户方便地访问外部设备,就像访问一个文件一样。/dev 目录下的节点是怎么创建的?devfs 或者 udev 会自动帮你创建的。kobject 是 sysfs ...
在给定的“rand_source.rar_random”压缩包中,包含两个关键文件:rand_source.c 和 rand_source.h,它们是实现一个基于/dev/random的随机源的源代码和头文件。 首先,让我们详细了解一下/dev/random。在Unix-like...
/dev/random 即服务 大WaSP /dev/random作为服务。 入门 ... curl "http://dev-random-as-a-service.appspot.com/proc/sys/kernel/random/entropy_avail" 新增内容:对于我们的实验性/dev/full 、 /de
* /dev/random:随机数设备,提供了一个随机数生成器。 * /dev/urandom:随机数设备,提供了一个随机数生成器。 这些设备节点都是通过udev或devf自动创建的,udev会监测sysfs文件系统,获取新创建的设备的信息,...
尽管使用`/dev/urandom`代替`/dev/random`可能会降低系统的理论安全性,但在大多数实际应用环境中,这种方式已经足够安全。此外,增加系统的噪声也是一种可行的解决方案,可以在不牺牲安全性的情况下提高启动速度。
1. 使用 mknod 命令创建块/字符特殊文件,例如 mknod /dev/mydevice b 1 0。 2. 使用 kudzu 命令侦测和配置新硬件,例如 kudzu -p /dev/sda。 3. 使用 dislocate 命令使进程和终端断开连接或重新连接,例如 ...
具体来说,它依赖于两个设备文件:`/dev/random` 和 `/dev/urandom`。 - `/dev/random` 和 `/dev/urandom` 的工作原理有所不同: - `/dev/random` 设备文件提供真正随机的数据流,当熵池中的随机性不足以满足请求...
- /dev/random:提供非确定性的随机数生成,基于系统熵,安全性较高。 - /dev/urandom:更快但略低安全性的随机数生成器,用于需要大量随机数的情况。 5. 异步I/O接口 - /dev/aio:异步I/O通知接口,用于进行非...
- `/dev/random` 和 `/dev/urandom` 是随机数生成器,前者更安全但速度较慢,后者更快但可能不够随机。 - `/dev/ram0` 到 `/dev/ram200` 是RAM磁盘,用于临时存储。 - `/dev/tty0` 至 `/dev/tty63` 是虚拟控制台设备...
`/dev/random`生成真正的随机数流,可能阻塞直到有足够的熵可供生成;`/dev/urandom`则提供非阻塞的伪随机数流。 创建和管理设备节点主要依赖于系统调用,如`mknod`用于创建设备文件,而`rename`和`unlink`则分别...
`/dev/random` 提供的是真正的随机数,而 `/dev/urandom` 是一个伪随机数生成器,它从`/dev/random`中获取种子并进行扩展。在源码层面,这两个设备的实现位于内核的`drivers/char/random.c`文件中。 在`main.c`文件...
$ sudo docker run --rm --net= " host " -v /dev/urandom:/dev/urandom -v /dev/random:/dev/random -p 50500:50500 chimeracoder/mediatomb 当然,您将需要挂载包含您要共享的媒体的目录。 例如: $ sudo docker ...
- `/dev/random`:随机数生成器。 - `/dev/sda`:SCSI磁盘及其分区设备。 - `/dev/shm`:共享内存设备。 - `/dev/systty`:指向系统tty设备的符号链接。 - `/dev/tty`:当前TTY设备。 - `/dev/tty[0-7]`:虚拟...
这个设备通常指的是非易失性随机存取存储器(Non-Volatile Random Access Memory),它是一种在断电后仍能保留数据的内存。 在Linux中,/dev/nvram是一个字符设备,它允许用户空间程序直接访问系统上的NV RAM区域。...
实验内容还涉及了几种典型的设备文件,如`/dev/null`用于丢弃输出,`/dev/zero`提供无限的零流,`/dev/random`和`/dev/urandom`提供随机数,`/dev/ttyS*`对应串口,`/dev/lp*`代表并口,`/dev/psaux`为PS/2鼠标,`/...