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