--- /dev/null
+# Copyright 1999-2018 Gentoo Authors
+# Distributed under the terms of the GNU General Public License v2
+
+# /etc/conf.d/rngd
+# Please see "/usr/sbin/rngd --help" and "man rngd" for more information
+
+# Space-delimited list of entropy sources to enable
+# Note that some of the entropy sources may require certain USE flags
+# to be enabled or require hardware support to function properly
+# Entropy sources not specified here (or in the exclude list below)
+# will be enabled/disabled based on rngd default behavior
+#
+# Choose from the list:
+# hwrng: Hardware RNG Device
+# tpm: TPM RNG Device (Deprecated)
+# rdrand: Intel RDRAND Instruction RNG
+# darn: Power9 DARN Instruction RNG
+# nist: NIST Network Entropy Beacon
+# (UNSAFE for cryptographic operations)
+# jitter: JITTER Entropy generator
+#
+#INCLUDE_ENTROPY_SOURCES="hwrng tpm rdrand darn nist jitter"
+
+
+# Space-delimited list of entropy sources to disable
+# This is useful for disabling certain entropy sources even
+# when they are supported on the system
+#
+#EXCLUDE_ENTROPY_SOURCES="nist tpm"
+
+
+# Entropy source specific options:
+#
+#
+# hwrng device used for random number input:
+#
+#HWRNG_DEVICE="/dev/hwrng"
+#
+#
+# rdrand options:
+# use_aes:(BOOLEAN)
+#
+#RDRAND_OPTIONS="use_aes:1"
+#
+#
+# darn options:
+# use_aes:(BOOLEAN)
+#
+#DARN_OPTIONS="use_aes:1"
+#
+#
+# jitter options:
+# thread_count:(INTEGER)
+# buffer_size:(INTEGER)
+# refill_thresh:(INTEGER)
+# retry_count:(INTEGER)
+# retry_delay:(INTEGER)
+# use_aes:(BOOLEAN)
+#
+#JITTER_OPTIONS="thread_count:4 buffer_size:16535 refill_thresh:16535"
+#JITTER_OPTIONS="${JITTER_OPTIONS} retry_count:1 retry_delay:-1 use_aes:1"
+
+
+# Kernel device used for random number output
+#
+#RANDOM_DEVICE="/dev/random"
+
+
+# Random step (Number of bytes written to random-device at a time):
+#
+#STEP=64
+
+
+# Fill watermark
+# 0 <= n <= `sysctl kernel.random.poolsize`
+#
+#WATERMARK=2048
+
+
+# Any extra arguments for rngd
+#
+#EXTRA_ARGS=""
--- /dev/null
+#!/sbin/openrc-run
+# Copyright 1999-2018 Gentoo Authors
+# Distributed under the terms of the GNU General Public License v2
+
+depend() {
+ need localmount
+ after urandom
+ provide entropy
+}
+
+command="/usr/sbin/rngd"
+description="Check and feed random data from hardware device to kernel entropy pool."
+pidfile="/var/run/${RC_SVCNAME}.pid"
+command_args=""
+command_args_background="--pid-file ${pidfile} --background"
+start_stop_daemon_args="--wait 1000"
+retry="SIGKILL/5000"
+
+
+# Parse rngd confd file for extra command line arguments
+start_pre() {
+ for entsrc in ${INCLUDE_ENTROPY_SOURCES}; do
+ command_args="${command_args} -n ${entsrc}"
+ done
+
+ for entsrc in ${EXCLUDE_ENTROPY_SOURCES}; do
+ command_args="${command_args} -x ${entsrc}"
+ done
+
+ if [ "x${HWRNG_DEVICE}" != "x" ]; then
+ command_args="${command_args} --rng-device=${HWRNG_DEVICE}"
+ fi
+
+ for entsrc_opt in ${RDRAND_OPTIONS}; do
+ command_args="${command_args} -O rdrand:${entsrc_opt}"
+ done
+
+ for entsrc_opt in ${DARN_OPTIONS}; do
+ command_args="${command_args} -O darn:${entsrc_opt}"
+ done
+
+ for entsrc_opt in ${JITTER_OPTIONS}; do
+ command_args="${command_args} -O jitter:${entsrc_opt}"
+ done
+
+ if [ "x${RANDOM_DEVICE}" != "x" ]; then
+ command_args="${command_args} --random-device=${RANDOM_DEVICE}"
+ fi
+
+ if [ "x${STEP}" != "x" ]; then
+ command_args="${command_args} --random-step=${STEP}"
+ fi
+
+ if [ "x${WATERMARK}" != "x" ]; then
+ command_args="${command_args} --fill-watermark=${WATERMARK}"
+ fi
+
+ command_args="${command_args} ${EXTRA_ARGS}"
+ return 0
+}
--- /dev/null
+# Copyright 1999-2018 Gentoo Authors
+# Distributed under the terms of the GNU General Public License v2
+
+EAPI=6
+
+inherit autotools systemd toolchain-funcs
+
+DESCRIPTION="Daemon to use hardware random number generators"
+HOMEPAGE="https://github.com/nhorman/rng-tools"
+SRC_URI="https://github.com/nhorman/${PN}/archive/v${PV}.tar.gz -> ${P}.tar.gz"
+
+LICENSE="GPL-2"
+SLOT="0"
+KEYWORDS="~alpha ~amd64 ~arm ~ia64 ~ppc ~x86"
+IUSE="jitterentropy nistbeacon selinux"
+
+DEPEND="dev-libs/libgcrypt:0
+ dev-libs/libgpg-error
+ sys-fs/sysfsutils
+ jitterentropy? (
+ app-crypt/jitterentropy:=
+ )
+ nistbeacon? (
+ net-misc/curl[ssl]
+ dev-libs/libxml2:2=
+ dev-libs/openssl:0=
+ )
+"
+RDEPEND="${DEPEND}
+ selinux? ( sec-policy/selinux-rngd )"
+DEPEND="${DEPEND}
+ nistbeacon? (
+ virtual/pkgconfig
+ )
+"
+
+PATCHES=(
+ "${FILESDIR}"/test-for-argp.patch
+ "${FILESDIR}"/${PN}-5-fix-textrels-on-PIC-x86.patch #469962
+)
+
+src_prepare() {
+ echo 'bin_PROGRAMS = randstat' >> contrib/Makefile.am || die
+ default
+
+ mv README.md README || die
+
+ eautoreconf
+
+ sed -i '/^AR /d' Makefile.in || die
+ tc-export AR
+}
+
+src_configure() {
+ local myeconfargs=(
+ $(use_with nistbeacon)
+ $(use_enable jitterentropy)
+ )
+
+ econf "${myeconfargs[@]}"
+}
+
+src_install() {
+ default
+ newinitd "${FILESDIR}"/rngd-initd-6-r1 rngd
+ newconfd "${FILESDIR}"/rngd-confd-6 rngd
+ systemd_dounit "${FILESDIR}"/rngd.service
+}