Split random retrieving code into separate files.
This commit is contained in:
parent
c7c177f07f
commit
24ca45125e
7 changed files with 122 additions and 47 deletions
|
@ -34,11 +34,6 @@
|
|||
|
||||
#include <argp.h>
|
||||
|
||||
#if defined (_WIN32) || defined (__CYGWIN__)
|
||||
#include <windows.h>
|
||||
#include <wincrypt.h>
|
||||
#endif
|
||||
|
||||
#include "progname.h"
|
||||
|
||||
static struct argp_option options[] = {
|
||||
|
@ -109,48 +104,6 @@ hexify (char *hex, grub_uint8_t *bin, grub_size_t n)
|
|||
*hex = 0;
|
||||
}
|
||||
|
||||
static int
|
||||
grub_get_random (void *out, grub_size_t len)
|
||||
{
|
||||
#if ! defined (__linux__) && ! defined (__FreeBSD__) && ! defined (__OpenBSD__) && !defined (__GNU__) && ! defined (_WIN32) && !defined(__CYGWIN__)
|
||||
/* TRANSLATORS: The generator might still be secure just GRUB isn't sure about it. */
|
||||
printf ("%s", _("WARNING: your random generator isn't known to be secure\n"));
|
||||
#warning "your random generator isn't known to be secure"
|
||||
#endif
|
||||
|
||||
#if defined (_WIN32) || defined (__CYGWIN__)
|
||||
HCRYPTPROV hCryptProv;
|
||||
if (!CryptAcquireContext (&hCryptProv,
|
||||
NULL,
|
||||
MS_DEF_PROV,
|
||||
PROV_RSA_FULL,
|
||||
CRYPT_VERIFYCONTEXT))
|
||||
return 1;
|
||||
if (!CryptGenRandom (hCryptProv, len, out))
|
||||
{
|
||||
CryptReleaseContext (hCryptProv, 0);
|
||||
return 1;
|
||||
}
|
||||
|
||||
CryptReleaseContext (hCryptProv, 0);
|
||||
|
||||
return 0;
|
||||
#else
|
||||
FILE *f;
|
||||
size_t rd;
|
||||
|
||||
f = fopen ("/dev/urandom", "rb");
|
||||
if (!f)
|
||||
return 1;
|
||||
rd = fread (out, 1, len, f);
|
||||
fclose (f);
|
||||
|
||||
if (rd != len)
|
||||
return 1;
|
||||
return 0;
|
||||
#endif
|
||||
}
|
||||
|
||||
int
|
||||
main (int argc, char *argv[])
|
||||
{
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue