How to Create/dev/random

Source: Internet
Author: User
Tags random seed
Name

Random, urandom-kernel random number source Devices

Description

The character special files/Dev/randomAnd/Dev/urandom(Present since Linux 1.3.30) provide an interface to the kernel's random number generator. File/Dev/randomHas Major device number 1 and minor device number 8. File/Dev/urandomHas 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,/Dev/randomDevice will only return random bytes within the estimated number of bits of noise in the entropy pool./Dev/randomShocould 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/randomWill block until additional environmental noise is gathered.

A read from/Dev/urandomDevice 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/randomInstead.

Processing ing

If your system does not have/Dev/randomAnd/Dev/urandomCreated already, they can be created with the following commands:

mknod -m 644 /dev/random c 1 8mknod -m 644 /dev/urandom c 1 9chown 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 operation CES 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 should SS 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/Dev/randomDevice.

The read-only fileEntropy_availGives the available entropy. Normally, this will be 4096 (BITs), a full entropy pool.

The filePoolsizeGives 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,102 4, 2048.

The fileRead_wakeup_thresholdContains the number of bits of entropy required for waking up processes that sleep waiting for entropy from/Dev/random. The default is 64. The fileWrite_wakeup_thresholdContains the number of bits of entropy below which we wake up processes that doSelect() OrPoll() For write access/Dev/random. These values can be changed by writing to the files.

The read-only filesUUIDAndBoot_idContain 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 ).

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.