如何安装 pandom:Linux 的真随机数生成器
在此页
- 介绍
- 1 安装pandom
- 1.1 获得root权限
- 1.2 安装构建依赖
- 基于 Arch 的系统
- 基于 Debian 的系统
- 基于 Red Hat 的系统
- 基于 SUSE 的系统
- 1.3 下载并提取源
- 1.4 安装前测试(推荐)
- 1.5 确定初始化系统
- 1.6 安装pandom
- 基于 init.d 的初始化系统(例如:upstart、sysvinit)
- systemd 作为初始化系统
- 2.1 获得root权限
- 2.2 安装构建依赖
- 基于 Arch 的系统
- 基于 Debian 的系统
- 基于 Red Hat 的系统
- 基于 SUSE 的系统
- 2.3 下载并提取源
- 2.4 安装熵数组
- 2.5 分析checkme文件
- 2.6 卸载 entropyarray(可选)
- 3.1 获得root权限
- 3.2 安装密钥环
- 3.3 安装源列表
- 喘息
- 杰西
- 拉伸
- 3.4 更新来源列表
- 3.5 测试 pandom
- 3.6 安装pandom
- 4.1 性能测试
- 4.2 熵与序列相关检验
- 4.3 系统服务
- 基于 init.d 的初始化系统(例如:upstart、sysvinit)
- systemd 作为初始化系统
- 5.1 编辑源文件
- 5.2 测试不可预测性
- 5.3 安装个性化pandom
本教程适用于 amd64/x86_64 linux 内核版本大于等于 2.6.9。它解释了如何安装 pandom:由 ncomputers.org
介绍
内置的 Linux 内核真随机数生成器在现代环境下提供低吞吐量,例如:具有固态驱动器 (SSD) 和虚拟专用服务器 (VPS) 的个人计算机。
这个问题在 linux 实现中越来越流行,因为对真正的随机数的需求不断增加,主要是出于不同的加密目的。
Pandom 输出大约 8 KiB/s 的 64 位/64 位熵,与物理和虚拟环境兼容,并假设没有其他以 root 用户身份运行的进程写入 /dev/random。
1 安装pandom
1.1 获得root权限
Pandom 必须以 root 身份安装,如果需要请运行此命令。
su -
1.2 安装构建依赖
为了下载和安装 pandom,您需要:GNU assembler、GNU make、GNU tar 和 GNU wget(通常已经安装了最后两个)。您可以稍后随意卸载它们。
基于 Arch 的系统
pacman -S binutils make
基于 Debian 的系统
apt-get install binutils make
基于 Red Hat 的系统
dnf install binutils make
yum install binutils make
基于 SUSE 的系统
zypper install binutils make
1.3 下载并解压源
这些命令使用 wget 和 tar 从 ncomputers.org 下载并提取 pandom 的源代码。
wget http://ncomputers.org/pandom.tar.gz
tar xf pandom.tar.gz
cd pandom/amd64-linux1.4 安装前测试(推荐)
这个推荐的测试大约需要 8 分钟。它检查内核支持并生成一个名为 checkme 的文件(在下一节中分析)。
make check
1.5 确定init系统
在安装 pandom 之前,您需要知道您的系统使用哪个初始化软件。如果以下命令输出单词 running,则表示您的系统正在使用 systemd,否则您的系统很可能正在使用 init.d 实现(例如:upstart、sysvinit)。可能会有一些例外,这些 unix.stackexchange.com 答案中的更多信息。
systemctl is-system-running
running
1.6 安装pandom
一旦你知道你的 linux 实现使用哪个系统,那么你可以相应地安装 pandom。
基于 init.d 的初始化系统(例如:upstart、sysvinit)
如果您的系统正在使用 init.d 实现(例如:upstart、sysvinit),请运行此命令安装 pandom。
make install-init.d
systemd 作为初始化系统
如果您的系统正在使用 systemd,请运行此命令安装 pandom。
make install-systemd
2 checkme文件分析
在将 pandom 用于加密目的之前,强烈建议分析本教程上一节中安装过程中生成的 checkme 文件。此任务对于了解数字是否真正随机很有用。本节介绍如何使用 ncomputers.org/entropyarray 分析 checkme 文件:一个 shell 脚本,用于测试其输入的熵和序列相关性。
注意:此分析可能在另一台计算机上运行,例如笔记本电脑或台式电脑。例如:如果您在资源受限的虚拟专用服务器 (VPS) 中安装 pandom,您可能会选择将 checkme 文件复制到您的个人计算机,以便在那里进行分析。
您也可以使用 Entropy Online Tester。2.1 获得root权限
Entropyarray 必须以 root 身份安装,如果需要请运行此命令。
su -
2.2 安装构建依赖
为了下载和安装 entropyarray,您需要:GNU g++ 编译器、GNU make、GNU tar 和 GNU wget(最后两个通常已经安装)。您可以稍后随意卸载它们。
基于 Arch 的系统
pacman -S gcc make
基于 Debian 的系统
apt-get install g++ make
基于 Red Hat 的系统
dnf install gcc-c++ make
yum install gcc-c++ make
基于 SUSE 的系统
zypper install gcc-c++ make
2.3 下载并解压源
这些命令使用 wget 和 tar 从 ncomputers.org 下载并提取 entropyarray 的源代码。
wget http://ncomputers.org/entropyarray.tar.gz
tar xf entropy.tar.gz
tar xf rearray.tar.gz
tar xf entropyarray.tar.gz2.4 安装entropyarray
注意:有关 -std=c++11 的错误意味着 GNU g++ 编译器版本不支持 ISO C++ 2011 标准。您可以尝试在另一个支持它的系统中编译 ncomputers.org/entropy 和 ncomputers.org/rearray(例如:GNU g++ 在您最喜欢的 linux 发行版的较新版本中),然后使用 make install 在您的系统中安装编译的二进制文件想要运行 entropyarray,或跳过此步骤,尽管强烈建议您在将 pandom 用于任何加密目的之前分析 checkme 文件。
cd rearray; make install; cd ..
cd entropy; make install; cd ..
cd entropyarray; make install; cd ..2.5 分析checkme文件
注:64位伪随机数序列测试。
entropyarray checkme
entropyarray in /tmp/tmp.mbCopmzqsg
15.977339
min:12
med:32
max:56
15.977368
min:11
med:32
max:58
15.977489
min:11
med:32
max:59
15.977077
min:12
med:32
max:60
15.977439
min:8
med:32
max:59
15.977374
min:13
med:32
max:60
15.977312
min:12
med:32
max:672.6 卸载 entropyarray(可选)
如果您打算不再使用 entropyarray,那么您可能想要随意卸载它。
cd entropyarray; make uninstall; cd ..
cd entropy; make uninstall; cd ..
cd rearray; make uninstall; cd ..3 使用 debian 仓库安装
如果您想在基于 debian 的系统上保持 pandom 更新,您可以选择使用 ncomputers.org debian 存储库安装/重新安装它。
3.1 获得root权限
下面的 debian 软件包必须以 root 身份安装,如果需要请运行此命令。
su -
3.2 安装密钥环
这个 debian 软件包包含 ncomputers.org debian 存储库的公钥。
wget http://ncomputers.org/debian/keyring.deb
dpkg -i keyring.deb
rm keyring.deb3.3 安装源列表
根据最新的 debian 发行版(2017 年),这些 debian 软件包包括 ncomputers.org debian 存储库的源列表。
注意:也可以在 /etc/apt/sources.list 中写入下面的注释行,而不是为您的 debian 发行版安装相应的 debian 软件包,但是如果这些源在将来发生变化,那么您将需要更新它们手动。
气喘吁吁
#deb http://ncomputers.org/debian/wheezy.deb
dpkg -i wheezy.deb
rm wheezy.deb洁西
#deb http://ncomputers.org/debian/jessie.deb
dpkg -i jessie.deb
rm jessie.deb拉紧
#deb http://ncomputers.org/debian/stretch.deb
dpkg -i stretch.deb
rm stretch.deb3.4 更新源列表
安装密钥环和源列表后。
apt-get update
3.5 测试pandom
经测试,您可以随意卸载以下软件包。
注意:如果你已经在你的 linux 实现中测试过 pandom,你可以跳过这一步。
apt-get install pandom-test
pandom-testgenerating checkme file, please wait around 8 minutes ...
entropyarray in /tmp/tmp.5SkiYsYG3h
15.977366
min:12
med:32
max:57
15.977367
min:13
med:32
max:57
15.977328
min:12
med:32
max:61
15.977431
min:12
med:32
max:59
15.977437
min:11
med:32
max:57
15.977298
min:11
med:32
max:59
15.977196
min:10
med:32
max:573.6 安装pandom
apt-get install pandom
4 管理 pandom
安装 pandom 后,您可能想要管理它。
4.1 性能测试
Pandom 提供大约每秒 8 KB 的速度,但其性能可能因环境而异。
dd if=/dev/random of=/dev/null bs=8 count=512
512+0 records in
512+0 records out
4096 bytes (4.1 kB, 4.0 KiB) copied, 0.451253 s, 9.1 kB/s4.2 熵与序列相关检验
除了 ncomputers.org/entropyarray,还有更多测试,例如 Ilja Gerhardt 的 NIST 测试套件。
entropyarray /dev/random 1M
4.3 系统服务
Pandom 作为系统服务运行。
基于 init.d 的初始化系统(例如:upstart、sysvinit)
/etc/init.d/random status
/etc/init.d/random start
/etc/init.d/random stop
/etc/init.d/random restartsystemd 作为初始化系统
systemctl status random
systemctl start random
systemctl stop random
systemctl restart random5 增加不可预测性或性能
如果您想尝试增加 pandom 实现的不可预测性或性能,您可以尝试添加或删除 CPU 时间测量。
5.1 编辑源文件
在源文件 test.s 和 tRNG.s 中随意添加或删除测量块。
#measurement block
mov $35,%rax
syscall
rdtsc
[...]
#measurement block
mov $35,%rax
syscall
rdtsc
[...]5.2 测试不可预测性
我们建议在将其用于加密目的之前始终测试任何个性化的 pandom 实现。
make check
5.3 安装个性化pandom
如果您对结果满意,那么您可以安装您的个性化 pandom 实施。
make install
其他信息和更新:http://ncomputers.org/pandom