/*
* cryptsetup kernel RNG access functions
*
- * Copyright (C) 2010-2012, Red Hat, Inc. All rights reserved.
+ * Copyright (C) 2010-2021 Red Hat, Inc. All rights reserved.
*
* This program is free software; you can redistribute it and/or
* modify it under the terms of the GNU General Public License
- * version 2 as published by the Free Software Foundation.
+ * as published by the Free Software Foundation; either version 2
+ * of the License, or (at your option) any later version.
*
* This program is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
#include <stdlib.h>
#include <string.h>
-#include <fcntl.h>
#include <errno.h>
#include <assert.h>
+#include <sys/select.h>
#include "libcryptsetup.h"
#include "internal.h"
/* Used for CRYPT_RND_NORMAL */
if(urandom_fd == -1)
- urandom_fd = open(URANDOM_DEVICE, O_RDONLY);
+ urandom_fd = open(URANDOM_DEVICE, O_RDONLY | O_CLOEXEC);
if(urandom_fd == -1)
goto fail;
/* Used for CRYPT_RND_KEY */
if(random_fd == -1)
- random_fd = open(RANDOM_DEVICE, O_RDONLY | O_NONBLOCK);
+ random_fd = open(RANDOM_DEVICE, O_RDONLY | O_NONBLOCK | O_CLOEXEC);
if(random_fd == -1)
goto fail;
+ if (crypt_fips_mode())
+ log_verbose(ctx, _("Running in FIPS mode."));
+
random_initialised = 1;
return 0;
fail:
crypt_random_exit();
- log_err(ctx, _("Fatal error during RNG initialisation.\n"));
+ log_err(ctx, _("Fatal error during RNG initialisation."));
return -ENOSYS;
}
}
break;
default:
- log_err(ctx, _("Unknown RNG quality requested.\n"));
+ log_err(ctx, _("Unknown RNG quality requested."));
return -EINVAL;
}
if (status)
- log_err(ctx, _("Error %d reading from RNG: %s\n"),
- errno, strerror(errno));
+ log_err(ctx, _("Error reading from RNG."));
return status;
}
int crypt_random_default_key_rng(void)
{
+ /* coverity[pointless_string_compare] */
if (!strcmp(DEFAULT_RNG, RANDOM_DEVICE))
return CRYPT_RNG_RANDOM;
+ /* coverity[pointless_string_compare] */
if (!strcmp(DEFAULT_RNG, URANDOM_DEVICE))
return CRYPT_RNG_URANDOM;