|
Packit Service |
4684c1 |
/*
|
|
Packit Service |
4684c1 |
* Copyright (C) 2016 Red Hat, Inc.
|
|
Packit Service |
4684c1 |
*
|
|
Packit Service |
4684c1 |
* Author: Nikos Mavrogiannopoulos
|
|
Packit Service |
4684c1 |
*
|
|
Packit Service |
4684c1 |
* This file is part of GnuTLS.
|
|
Packit Service |
4684c1 |
*
|
|
Packit Service |
4684c1 |
* GnuTLS is free software: you can redistribute it and/or modify it
|
|
Packit Service |
4684c1 |
* under the terms of the GNU General Public License as published by
|
|
Packit Service |
4684c1 |
* the Free Software Foundation, either version 3 of the License, or
|
|
Packit Service |
4684c1 |
* (at your option) any later version.
|
|
Packit Service |
4684c1 |
*
|
|
Packit Service |
4684c1 |
* GnuTLS is distributed in the hope that it will be useful, but
|
|
Packit Service |
4684c1 |
* WITHOUT ANY WARRANTY; without even the implied warranty of
|
|
Packit Service |
4684c1 |
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
|
|
Packit Service |
4684c1 |
* General Public License for more details.
|
|
Packit Service |
4684c1 |
*
|
|
Packit Service |
4684c1 |
* You should have received a copy of the GNU General Public License
|
|
Packit Service |
4684c1 |
* along with GnuTLS. If not, see <https://www.gnu.org/licenses/>.
|
|
Packit Service |
4684c1 |
*
|
|
Packit Service |
4684c1 |
*/
|
|
Packit Service |
4684c1 |
|
|
Packit Service |
4684c1 |
#ifdef HAVE_CONFIG_H
|
|
Packit Service |
4684c1 |
#include <config.h>
|
|
Packit Service |
4684c1 |
#endif
|
|
Packit Service |
4684c1 |
|
|
Packit Service |
4684c1 |
#include <stdlib.h>
|
|
Packit Service |
4684c1 |
|
|
Packit Service |
4684c1 |
/* This program verifies whether the low-level random functions can operate
|
|
Packit Service |
4684c1 |
* properly, even if interrupted by signals */
|
|
Packit Service |
4684c1 |
|
|
Packit Service |
4684c1 |
#if defined(HAVE_SETITIMER) && (defined(HAVE_LINUX_GETRANDOM) || defined(__linux__))
|
|
Packit Service |
4684c1 |
|
|
Packit Service |
4684c1 |
#include <stdio.h>
|
|
Packit Service |
4684c1 |
#include <unistd.h>
|
|
Packit Service |
4684c1 |
#include <sys/types.h>
|
|
Packit Service |
4684c1 |
#include <sys/time.h>
|
|
Packit Service |
4684c1 |
#include <errno.h>
|
|
Packit Service |
4684c1 |
#include <stdint.h>
|
|
Packit Service |
4684c1 |
#include "utils.h"
|
|
Packit Service |
4684c1 |
|
|
Packit Service |
4684c1 |
#define _gnutls_debug_log printf
|
|
Packit Service |
4684c1 |
#define gnutls_assert()
|
|
Packit Service |
4684c1 |
#define gnutls_assert_val(val) val
|
|
Packit Service |
4684c1 |
|
|
Packit Service |
4684c1 |
int _rnd_system_entropy_init(void);
|
|
Packit Service |
4684c1 |
int _rnd_system_entropy_check(void);
|
|
Packit Service |
4684c1 |
void _rnd_system_entropy_deinit(void);
|
|
Packit Service |
4684c1 |
|
|
Packit Service |
4684c1 |
typedef int (*get_entropy_func)(void* rnd, size_t size);
|
|
Packit Service |
4684c1 |
get_entropy_func _rnd_get_system_entropy;
|
|
Packit Service |
4684c1 |
|
|
Packit Service |
4684c1 |
#define RND_NO_INCLUDES
|
|
Packit Service |
4684c1 |
#include "../lib/nettle/sysrng-linux.c"
|
|
Packit Service |
4684c1 |
|
|
Packit Service |
4684c1 |
static volatile int stop_loop = 0;
|
|
Packit Service |
4684c1 |
|
|
Packit Service |
4684c1 |
static void sig_handler(int signo)
|
|
Packit Service |
4684c1 |
{
|
|
Packit Service |
4684c1 |
stop_loop++;
|
|
Packit Service |
4684c1 |
}
|
|
Packit Service |
4684c1 |
|
|
Packit Service |
4684c1 |
void doit(void)
|
|
Packit Service |
4684c1 |
{
|
|
Packit Service |
4684c1 |
char buf[512];
|
|
Packit Service |
4684c1 |
char empty[32];
|
|
Packit Service |
4684c1 |
int ret;
|
|
Packit Service |
4684c1 |
struct itimerval ival;
|
|
Packit Service |
4684c1 |
struct sigaction sa;
|
|
Packit Service |
4684c1 |
|
|
Packit Service |
4684c1 |
memset(&sa, 0, sizeof(sa));
|
|
Packit Service |
4684c1 |
sa.sa_handler = sig_handler;
|
|
Packit Service |
4684c1 |
sigemptyset (&sa.sa_mask);
|
|
Packit Service |
4684c1 |
sigaction(SIGALRM, &sa, NULL);
|
|
Packit Service |
4684c1 |
|
|
Packit Service |
4684c1 |
memset(&ival, 0, sizeof(ival));
|
|
Packit Service |
4684c1 |
ival.it_interval.tv_usec = 5000;
|
|
Packit Service |
4684c1 |
ival.it_value.tv_usec = 5000;
|
|
Packit Service |
4684c1 |
|
|
Packit Service |
4684c1 |
_rnd_system_entropy_init();
|
|
Packit Service |
4684c1 |
|
|
Packit Service |
4684c1 |
ret = setitimer(ITIMER_REAL, &ival, NULL);
|
|
Packit Service |
4684c1 |
if (ret < 0) {
|
|
Packit Service |
4684c1 |
fail("error in setitimer: %s\n", strerror(errno));
|
|
Packit Service |
4684c1 |
}
|
|
Packit Service |
4684c1 |
|
|
Packit Service |
4684c1 |
memset(empty, 0, sizeof(empty));
|
|
Packit Service |
4684c1 |
for (;stop_loop<1024;) {
|
|
Packit Service |
4684c1 |
memset(buf, 0, sizeof(buf));
|
|
Packit Service |
4684c1 |
ret = _rnd_get_system_entropy(buf, sizeof(buf));
|
|
Packit Service |
4684c1 |
if (ret < 0) {
|
|
Packit Service |
4684c1 |
fail("error obtaining entropy: %s\n", gnutls_strerror(ret));
|
|
Packit Service |
4684c1 |
}
|
|
Packit Service |
4684c1 |
|
|
Packit Service |
4684c1 |
if (memcmp(empty, buf+sizeof(buf)-sizeof(empty)-1, sizeof(empty)) == 0) {
|
|
Packit Service |
4684c1 |
fail("_rnd_get_system_entropy: did not fill buffer\n");
|
|
Packit Service |
4684c1 |
}
|
|
Packit Service |
4684c1 |
}
|
|
Packit Service |
4684c1 |
|
|
Packit Service |
4684c1 |
_rnd_system_entropy_deinit();
|
|
Packit Service |
4684c1 |
}
|
|
Packit Service |
4684c1 |
#else
|
|
Packit Service |
4684c1 |
void doit(void); /* prototype to avoid warning with -Wmissing-prototypes */
|
|
Packit Service |
4684c1 |
|
|
Packit Service |
4684c1 |
void doit(void)
|
|
Packit Service |
4684c1 |
{
|
|
Packit Service |
4684c1 |
exit(77);
|
|
Packit Service |
4684c1 |
}
|
|
Packit Service |
4684c1 |
|
|
Packit Service |
4684c1 |
#endif
|