]>
git.ipfire.org Git - thirdparty/rng-tools.git/blob - rngd_linux.c
2 * rngd_linux.c -- Entropy sink for the Linux Kernel (/dev/random)
4 * Copyright (C) 2001 Philipp Rumpf
6 * This program is free software; you can redistribute it and/or modify
7 * it under the terms of the GNU General Public License as published by
8 * the Free Software Foundation; either version 2 of the License, or
9 * (at your option) any later version.
11 * This program is distributed in the hope that it will be useful,
12 * but WITHOUT ANY WARRANTY; without even the implied warranty of
13 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
14 * GNU General Public License for more details.
16 * You should have received a copy of the GNU General Public License
17 * along with this program; if not, write to the Free Software
18 * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
24 #error Invalid or missing autoconf build environment
27 #include "rng-tools-config.h"
35 #include <sys/ioctl.h>
37 #include <sys/types.h>
42 #include <linux/types.h>
43 #include <linux/random.h>
49 #include "rngd_linux.h"
51 extern struct rng
*rng_list
;
53 /* Kernel output device */
58 * Initialize the interface to the Linux Kernel
59 * entropy pool (through /dev/random)
61 * randomdev is the path to the random device
63 void init_kernel_rng(const char* randomdev
)
65 random_fd
= open(randomdev
, O_RDWR
);
66 if (random_fd
== -1) {
67 message(LOG_DAEMON
|LOG_ERR
, "can't open %s: %s",
68 randomdev
, strerror(errno
));
73 void random_add_entropy(void *buf
, size_t size
)
78 unsigned char data
[size
];
81 entropy
.ent_count
= size
* 8;
83 memcpy(entropy
.data
, buf
, size
);
85 if (ioctl(random_fd
, RNDADDENTROPY
, &entropy
) != 0) {
86 message(LOG_DAEMON
|LOG_ERR
, "RNDADDENTROPY failed: %s\n",
92 void random_sleep(double poll_timeout
)
100 if (ioctl(random_fd
, RNDGETENTCNT
, &ent_count
) == 0 &&
101 ent_count
< arguments
->fill_watermark
)
104 poll(&pfd
, 1, 1000.0 * poll_timeout
);
107 void src_list_add(struct rng
*ent_src
)
116 iter
->next
= ent_src
;