1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 150 151 152 153 154 155 156 157 158 159 160 161 162 163 164 165 166 167 168 169 170 171 172 173 174 175 176 177 178 179 180 181 182 183 184 185 186 187 188 189 190 191 192 193 194 195 196 197 198 199 200 201 202 203 204 205 206 207 208 209 210 211 212 213 214 215 216 217 218 219 220 221 222 223 224 225 226 227 228 229 230 231 232 233 234 235 236 237 238 239 240 241 242 243 244 245 246 247 248 249 250 251
|
.\" Copyright (c) 1997 John S. Kallal (kallal@voicenet.com)
.\"
.\" %%%LICENSE_START(GPLv2+_DOC_ONEPARA)
.\" This is free documentation; you can redistribute it and/or
.\" modify it under the terms of the GNU General Public License as
.\" published by the Free Software Foundation; either version 2 of
.\" the License, or (at your option) any later version.
.\" %%%LICENSE_END
.\"
.\" Some changes by tytso and aeb.
.\"
.\" 2004-12-16, John V. Belmonte/mtk, Updated init and quit scripts
.\" 2004-04-08, AEB, Improved description of read from /dev/urandom
.\" 2008-06-20, George Spelvin <linux@horizon.com>,
.\" Matt Mackall <mpm@selenic.com>
.\"
.\"*******************************************************************
.\"
.\" This file was generated with po4a. Translate the source file.
.\"
.\"*******************************************************************
.\"
.\" Japanese Version Copyright (c) 1998
.\" ISHIKAWA Mutsumi, all rights reserved.
.\" Translated into Japanese Mon Jan 12 03:20:27 JST 1998
.\" by ISHIKAWA Mutsumi <ishikawa@linux.or.jp>
.\" Japanese Version Last Modified Thu Feb 5 21:08:33 JST 1998
.\" by ISHIKAWA Mutsumi <ishikawa@linux.or.jp>
.\" Updated & Modified Sun Jun 6 14:48:03 JST 2004
.\" by Yuichi SATO <ysato444@yahoo.co.jp>
.\" Updated & Modified Tue Jan 18 04:21:16 JST 2005 by Yuichi SATO
.\" Updated & Modified Fri Apr 22 03:44:01 JST 2005 by Yuichi SATO
.\" Updated 2008-08-13, Akihiro MOTOKI <amotoki@dd.iij4u.or.jp>, LDP v3.05
.\" Updated 2013-05-07, Akihiro MOTOKI <amotoki@gmail.com>
.\"
.TH RANDOM 4 " 2017\-09\-15" Linux "Linux Programmer's Manual"
.SH 名前
random, urandom \- カーネル乱数ソースデバイス
.SH 書式
#include <linux/random.h>
.PP
\fBint ioctl(\fP\fIfd\fP\fB, RND\fP\fIrequest\fP\fB, \fP\fIparam\fP\fB);\fP
.SH 説明
(Linux 1.3.30 から提供されている) \fI/dev/random\fP 、 \fI/dev/urandom\fP キャラクタースペシャルファイルは
カーネル乱数ジェネレーターへのインターフェースを提供する。 \fI/dev/random\fP ファイルはメジャーデバイス番号 1 マイナーデバイス番号 8
である。 \fI/dev/urandom\fP ファイルはメジャーデバイス番号 1 マイナーデバイス番号 9 である。
.PP
乱数ジェネレーターはデバイスドライバやその他の源からの環境ノイズを エントロピープールへ集める。
また、ジェネレーターはエントロピープール内のノイズのビット数の推定値を 保持する。 このエントロピープールから乱数が生成される。
.PP
Linux 3.17 and later provides the simpler and safer \fBgetrandom\fP(2)
interface which requires no special files; see the \fBgetrandom\fP(2) manual
page for details.
.PP
When read, the \fI/dev/urandom\fP device returns random bytes using a
pseudorandom number generator seeded from the entropy pool. Reads from this
device do not block (i.e., the CPU is not yielded), but can incur an
appreciable delay when requesting large amounts of data.
.PP
.\" This is a real problem; see
.\" commit 9b4d008787f864f17d008c9c15bbe8a0f7e2fc24
When read during early boot time, \fI/dev/urandom\fP may return data prior to
the entropy pool being initialized. If this is of concern in your
application, use \fBgetrandom\fP(2) or \fI/dev/random\fP instead.
.PP
The \fI/dev/random\fP device is a legacy interface which dates back to a time
where the cryptographic primitives used in the implementation of
\fI/dev/urandom\fP were not widely trusted. It will return random bytes only
within the estimated number of bits of fresh noise in the entropy pool,
blocking if necessary. \fI/dev/random\fP is suitable for applications that
need high quality randomness, and can afford indeterminate delays.
.PP
エントロピープールが空の時は、\fI/dev/random\fP からの読み出しは、 更なる環境ノイズが得られるまで、ブロックされる。 \fBopen\fP(2)
が \fI/dev/random\fP に対して \fBO_NONBLOCK\fP フラグ付きで呼ばれると、 それ以降の \fBread\fP(2)
は要求したバイト数のデータが利用可能になるまで停止しない。 その代わり、 利用可能なデータが返される。 利用可能なバイトが全くない場合、
\fBread\fP(2) は \-1 を返し、 \fIerrno\fP に \fBEAGAIN\fP が設定される。
.PP
The \fBO_NONBLOCK\fP flag has no effect when opening \fI/dev/urandom\fP. When
calling \fBread\fP(2) for the device \fI/dev/urandom\fP, reads of up to 256 bytes
will return as many bytes as are requested and will not be interrupted by a
signal handler. Reads with a buffer over this limit may return less than
the requested number of bytes or fail with the error \fBEINTR\fP, if
interrupted by a signal handler.
.PP
.\" commit 79a8468747c5f95ed3d5ce8376a3e82e0c5857fc
.\" SEC_XFER_SIZE in drivers/char/random.c
Since Linux 3.16, a \fBread\fP(2) from \fI/dev/urandom\fP will return at most 32\ MB. A \fBread\fP(2) from \fI/dev/random\fP will return at most 512 bytes (340
bytes on Linux kernels before version 2.6.12).
.PP
\fI/dev/random\fP や \fI/dev/urandom\fP に書き込みを行うと、 書き込まれたデータでエントロピープールが更新される。 しかし、
エントロピーカウントが増えるわけではない。 つまり、 \fI/dev/random\fP と \fI/dev/urandom\fP
の両方のファイルから読み出される内容に影響があるが、 \fI/dev/random\fP からの読み出しが早くなるわけではないということだ。
.SS 使い方
The \fI/dev/random\fP interface is considered a legacy interface, and
\fI/dev/urandom\fP is preferred and sufficient in all use cases, with the
exception of applications which require randomness during early boot time;
for these applications, \fBgetrandom\fP(2) must be used instead, because it
will block until the entropy pool is initialized.
.PP
.\"
下記で推奨しているように再起動の前後で乱数種ファイルが保存される場合、起動シーケンスにおいて乱数種が
再ロードされた直後から、その出力はローカルのルートアクセスができない
攻撃者に対して暗号的に安全なものとなり、ネットワーク暗号化のセッションキーとして使うには完全に最適なものとなる。 (すべての主な Linux
のディストリビューションは少なくとも 2000 年以降はリブートの前後で乱数種のファイルを保存するようになっている。) \fI/dev/random\fP
からの読み出しは停止 (block) する可能性があるので、ユーザーは普通 このファイルを非停止 (nonblocking) モードで開こうとし
(もしくはタイムアウトを指定して読み出しを実行し)、希望するレベルの エントロピーはすぐには利用できない場合には、何らかの通知を行うことだろう。
.SS Configuration
システムにあらかじめ作成された \fI/dev/random\fP と \fI/dev/urandom\fP が存在しないなら、次のようなコマンドで作成できる。
.PP
.in +4n
.EX
mknod \-m 666 /dev/random c 1 8
mknod \-m 666 /dev/urandom c 1 9
chown root:root /dev/random /dev/urandom
.EE
.in
.PP
オペレータの操作なしに Linux システムが起動した直後は、 エントロピープールは意外性の乏しい均一な状態にあるだろう。
これにより、エントロピープールの実際のノイズ量は評価値より少なくなる。 この効果を打ち消すために、シャットダウンから (次の) 起動時まで持ち越した
エントロピープールの情報が助けになる。 エントロピープールを持ち越すためには、 Linux システムの起動時に実行される適切なスクリプトに、
以下の行を追加すればよい:
.PP
.in +4n
.EX
echo "Initializing random number generator..."
random_seed=/var/run/random\-seed
# 乱数種を今回のスタートアップから次回のスタートアップまで持ち越す。
# ロードを行い、その後、全てのエントロピープールを保存する。
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 ] && bits=$(cat $poolfile) || bits=4096
bytes=$(expr $bits / 8)
dd if=/dev/urandom of=$random_seed count=1 bs=$bytes
.EE
.in
.PP
また、Linux システムのシャットダウン時に実行される適切なスクリプトに、 以下の行を追加すればよい:
.PP
.in +4n
.EX
# 乱数種を今回のシャットダウンから次回のスタートアップまで持ち越す。
# 全てのエントロピープールを保存する。
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 ] && bits=$(cat $poolfile) || bits=4096
bytes=$(expr $bits / 8)
dd if=/dev/urandom of=$random_seed count=1 bs=$bytes
.EE
.in
.PP
.\"
In the above examples, we assume Linux 2.6.0 or later, where
\fI/proc/sys/kernel/random/poolsize\fP returns the size of the entropy pool in
bits (see below).
.SS "/proc インターフェース"
ディレクトリ \fI/proc/sys/kernel/random\fP にあるファイル (2.3.16 以降で存在する) で、 \fI/dev/random\fP
デバイスに関する追加の情報を参照できる。
.TP
\fIentropy_avail\fP
この読み込み専用のファイルは使用可能なエントロピーをビット単位で表示する。値は 0 から 4096 までの範囲の数字である。
.TP
\fIpoolsize\fP
このファイルはエントロピープールのサイズを示す。 このファイルの意味はカーネルバージョンにより異なる。
.RS
.TP
Linux 2.4:
このファイルはエントロピープールのサイズを「バイト」単位で規定する。 通常、このファイルの値は 512 になるが、書き込み可能であり、
アルゴリズムで利用可能な任意の値に変更できる。 選択可能な値は 32, 64, 128, 256, 512, 1024, 2048 である。
.TP
Linux 2.6 以降:
このファイルは読み出し専用であり、 エントロピープールのサイズを「ビット」単位で規定する。 値は 4096 である。
.RE
.TP
\fIread_wakeup_threshold\fP
This file contains the number of bits of entropy required for waking up
processes that sleep waiting for entropy from \fI/dev/random\fP. The default
is 64.
.TP
\fIwrite_wakeup_threshold\fP
ファイル \fIwrite_wakeup_threshold\fP はエントロピーのビット数を保持しており、この値以下になったら \fI/dev/random\fP
への書き込みアクセスのために \fBselect\fP(2) または \fBpoll\fP(2) を実行するプロセスを起こす。
この値はファイルに書き込みを行うことによって変更できる。
.TP
\fIuuid\fP and \fIboot_id\fP
.\"
これらの読み込み専用のファイルは 6fd5a44b\-35f4\-4ad4\-a9b9\-6b9be13e1fe9 のような ランダムな文字列を保持している。
前者は読み込みの度に新たに生成され、 後者は 1 度だけ生成される。
.SS "ioctl(2) インターフェース"
以下の \fBioctl\fP(2) 要求が \fI/dev/random\fP や \fI/dev/urandom\fP
に接続されたファイルディスクリプターに対して定義されている。 実行されたすべての要求は、 \fI/dev/random\fP と
\fI/dev/urandom\fP に影響を与える入力エントロピープールとやり取りを行う。 \fBRNDGETENTCNT\fP 以外のすべての要求には
\fBCAP_SYS_ADMIN\fP ケーパビリティが必要である。
.TP
\fBRNDGETENTCNT\fP
入力エントロピープールのカウントを取得する。 取得される内容は proc の \fIentropy_avail\fP ファイルと同じである。
結果は引数が指す整数 (int) に格納される。
.TP
\fBRNDADDTOENTCNT\fP
入力エントロピープールのカウントを引数が指す値だけ加算または減算する。
.TP
\fBRNDGETPOOL\fP
Linux 2.6.9 で削除された。
.TP
\fBRNDADDENTROPY\fP
入力プールに追加のエントロピーを追加し、エントロピーカウントを増やす。 この要求は \fI/dev/random\fP や \fI/dev/urandom\fP
への書き込みとは異なる。 \fI/dev/random\fP や \fI/dev/urandom\fP への書き込みでは、 何らかのデータが追加されるだけで、
エントロピーカウントは増やされない。 以下の構造体が使用される。
.IP
.in +4n
.EX
struct rand_pool_info {
int entropy_count;
int buf_size;
__u32 buf[0];
};
.EE
.in
.IP
\fIentropy_count\fP はエントロピーカウントに加算 (または減算) する値である。 \fIbuf\fP は大きさが \fIbuf_size\fP
のバッファーで、この内容がエントロピープールに追加される。
.TP
\fBRNDZAPENTCNT\fP, \fBRNDCLEARPOOL\fP
すべてのプールのエントロピーカウントを 0 にし、何らかのシステムデータ (現在の時刻など) をプールに追加する。
.SH ファイル
\fI/dev/random\fP
.br
\fI/dev/urandom\fP
.SH 注意
For an overview and comparison of the various interfaces that can be used to
obtain randomness, see \fBrandom\fP(7).
.SH バグ
.\" .SH AUTHOR
.\" The kernel's random number generator was written by
.\" Theodore Ts'o (tytso@athena.mit.edu).
During early boot time, reads from \fI/dev/urandom\fP may return data prior to
the entropy pool being initialized.
.SH 関連項目
\fBmknod\fP(1), \fBgetrandom\fP(2), \fBrandom\fP(7)
.PP
RFC\ 1750, "Randomness Recommendations for Security"
.SH この文書について
この man ページは Linux \fIman\-pages\fP プロジェクトのリリース 5.10 の一部である。プロジェクトの説明とバグ報告に関する情報は
\%https://www.kernel.org/doc/man\-pages/ に書かれている。
|