Browse Source

only build the getrandom path if SYS_getrandom is defined.

like the sysctl path
OPENBSD_5_7
bcook 10 years ago
parent
commit
5fc23a1e55
2 changed files with 14 additions and 6 deletions
  1. +7
    -3
      src/lib/libcrypto/arc4random/getentropy_linux.c
  2. +7
    -3
      src/lib/libcrypto/crypto/getentropy_linux.c

+ 7
- 3
src/lib/libcrypto/arc4random/getentropy_linux.c View File

@ -1,4 +1,4 @@
/* $OpenBSD: getentropy_linux.c,v 1.33 2014/08/16 17:21:56 bcook Exp $ */
/* $OpenBSD: getentropy_linux.c,v 1.34 2014/08/16 18:42:41 bcook Exp $ */
/* /*
* Copyright (c) 2014 Theo de Raadt <deraadt@openbsd.org> * Copyright (c) 2014 Theo de Raadt <deraadt@openbsd.org>
@ -74,7 +74,9 @@
int getentropy(void *buf, size_t len); int getentropy(void *buf, size_t len);
static int gotdata(char *buf, size_t len); static int gotdata(char *buf, size_t len);
#ifdef SYS_getrandom
static int getentropy_getrandom(void *buf, size_t len); static int getentropy_getrandom(void *buf, size_t len);
#endif
static int getentropy_urandom(void *buf, size_t len); static int getentropy_urandom(void *buf, size_t len);
#ifdef SYS__sysctl #ifdef SYS__sysctl
static int getentropy_sysctl(void *buf, size_t len); static int getentropy_sysctl(void *buf, size_t len);
@ -92,6 +94,7 @@ getentropy(void *buf, size_t len)
return -1; return -1;
} }
#ifdef SYS_getrandom
/* /*
* Try descriptor-less getrandom() * Try descriptor-less getrandom()
*/ */
@ -100,6 +103,7 @@ getentropy(void *buf, size_t len)
return (ret); return (ret);
if (errno != ENOSYS) if (errno != ENOSYS)
return (-1); return (-1);
#endif
/* /*
* Try to get entropy with /dev/urandom * Try to get entropy with /dev/urandom
@ -186,10 +190,10 @@ gotdata(char *buf, size_t len)
return 0; return 0;
} }
#ifdef SYS_getrandom
static int static int
getentropy_getrandom(void *buf, size_t len) getentropy_getrandom(void *buf, size_t len)
{ {
#ifdef SYS_getrandom
int ret; int ret;
if (len > 256) if (len > 256)
return (-1); return (-1);
@ -199,9 +203,9 @@ getentropy_getrandom(void *buf, size_t len)
if (ret == len) if (ret == len)
return (0); return (0);
#endif
return (-1); return (-1);
} }
#endif
static int static int
getentropy_urandom(void *buf, size_t len) getentropy_urandom(void *buf, size_t len)


+ 7
- 3
src/lib/libcrypto/crypto/getentropy_linux.c View File

@ -1,4 +1,4 @@
/* $OpenBSD: getentropy_linux.c,v 1.33 2014/08/16 17:21:56 bcook Exp $ */
/* $OpenBSD: getentropy_linux.c,v 1.34 2014/08/16 18:42:41 bcook Exp $ */
/* /*
* Copyright (c) 2014 Theo de Raadt <deraadt@openbsd.org> * Copyright (c) 2014 Theo de Raadt <deraadt@openbsd.org>
@ -74,7 +74,9 @@
int getentropy(void *buf, size_t len); int getentropy(void *buf, size_t len);
static int gotdata(char *buf, size_t len); static int gotdata(char *buf, size_t len);
#ifdef SYS_getrandom
static int getentropy_getrandom(void *buf, size_t len); static int getentropy_getrandom(void *buf, size_t len);
#endif
static int getentropy_urandom(void *buf, size_t len); static int getentropy_urandom(void *buf, size_t len);
#ifdef SYS__sysctl #ifdef SYS__sysctl
static int getentropy_sysctl(void *buf, size_t len); static int getentropy_sysctl(void *buf, size_t len);
@ -92,6 +94,7 @@ getentropy(void *buf, size_t len)
return -1; return -1;
} }
#ifdef SYS_getrandom
/* /*
* Try descriptor-less getrandom() * Try descriptor-less getrandom()
*/ */
@ -100,6 +103,7 @@ getentropy(void *buf, size_t len)
return (ret); return (ret);
if (errno != ENOSYS) if (errno != ENOSYS)
return (-1); return (-1);
#endif
/* /*
* Try to get entropy with /dev/urandom * Try to get entropy with /dev/urandom
@ -186,10 +190,10 @@ gotdata(char *buf, size_t len)
return 0; return 0;
} }
#ifdef SYS_getrandom
static int static int
getentropy_getrandom(void *buf, size_t len) getentropy_getrandom(void *buf, size_t len)
{ {
#ifdef SYS_getrandom
int ret; int ret;
if (len > 256) if (len > 256)
return (-1); return (-1);
@ -199,9 +203,9 @@ getentropy_getrandom(void *buf, size_t len)
if (ret == len) if (ret == len)
return (0); return (0);
#endif
return (-1); return (-1);
} }
#endif
static int static int
getentropy_urandom(void *buf, size_t len) getentropy_urandom(void *buf, size_t len)


Loading…
Cancel
Save