diff options
| author | bcook <> | 2016-09-03 15:24:09 +0000 |
|---|---|---|
| committer | bcook <> | 2016-09-03 15:24:09 +0000 |
| commit | fc45c32b727123a9db48fbc11ff7d90f36199048 (patch) | |
| tree | a6fce36bc4d7b3eebc26d19e82b12bd3dc99f979 /src | |
| parent | 3ec8629e017a6dddd8f30a0f5fbdff47a85c8b4f (diff) | |
| download | openbsd-fc45c32b727123a9db48fbc11ff7d90f36199048.tar.gz openbsd-fc45c32b727123a9db48fbc11ff7d90f36199048.tar.bz2 openbsd-fc45c32b727123a9db48fbc11ff7d90f36199048.zip | |
add iOS support for getentropy
from Jacob Berkman, ok beck@
Diffstat (limited to 'src')
| -rw-r--r-- | src/lib/libcrypto/arc4random/getentropy_osx.c | 13 |
1 files changed, 12 insertions, 1 deletions
diff --git a/src/lib/libcrypto/arc4random/getentropy_osx.c b/src/lib/libcrypto/arc4random/getentropy_osx.c index c5bbb7e338..2a5f83f3bb 100644 --- a/src/lib/libcrypto/arc4random/getentropy_osx.c +++ b/src/lib/libcrypto/arc4random/getentropy_osx.c | |||
| @@ -1,4 +1,4 @@ | |||
| 1 | /* $OpenBSD: getentropy_osx.c,v 1.10 2016/08/07 03:27:21 tb Exp $ */ | 1 | /* $OpenBSD: getentropy_osx.c,v 1.11 2016/09/03 15:24:09 bcook Exp $ */ |
| 2 | 2 | ||
| 3 | /* | 3 | /* |
| 4 | * Copyright (c) 2014 Theo de Raadt <deraadt@openbsd.org> | 4 | * Copyright (c) 2014 Theo de Raadt <deraadt@openbsd.org> |
| @@ -20,6 +20,7 @@ | |||
| 20 | * http://man.openbsd.org/getentropy.2 | 20 | * http://man.openbsd.org/getentropy.2 |
| 21 | */ | 21 | */ |
| 22 | 22 | ||
| 23 | #include <TargetConditionals.h> | ||
| 23 | #include <sys/types.h> | 24 | #include <sys/types.h> |
| 24 | #include <sys/param.h> | 25 | #include <sys/param.h> |
| 25 | #include <sys/ioctl.h> | 26 | #include <sys/ioctl.h> |
| @@ -45,14 +46,18 @@ | |||
| 45 | #include <mach/mach_time.h> | 46 | #include <mach/mach_time.h> |
| 46 | #include <mach/mach_host.h> | 47 | #include <mach/mach_host.h> |
| 47 | #include <mach/host_info.h> | 48 | #include <mach/host_info.h> |
| 49 | #if TARGET_OS_OSX | ||
| 48 | #include <sys/socketvar.h> | 50 | #include <sys/socketvar.h> |
| 49 | #include <sys/vmmeter.h> | 51 | #include <sys/vmmeter.h> |
| 52 | #endif | ||
| 50 | #include <netinet/in.h> | 53 | #include <netinet/in.h> |
| 51 | #include <netinet/tcp.h> | 54 | #include <netinet/tcp.h> |
| 55 | #if TARGET_OS_OSX | ||
| 52 | #include <netinet/udp.h> | 56 | #include <netinet/udp.h> |
| 53 | #include <netinet/ip_var.h> | 57 | #include <netinet/ip_var.h> |
| 54 | #include <netinet/tcp_var.h> | 58 | #include <netinet/tcp_var.h> |
| 55 | #include <netinet/udp_var.h> | 59 | #include <netinet/udp_var.h> |
| 60 | #endif | ||
| 56 | #include <CommonCrypto/CommonDigest.h> | 61 | #include <CommonCrypto/CommonDigest.h> |
| 57 | #define SHA512_Update(a, b, c) (CC_SHA512_Update((a), (b), (c))) | 62 | #define SHA512_Update(a, b, c) (CC_SHA512_Update((a), (b), (c))) |
| 58 | #define SHA512_Init(xxx) (CC_SHA512_Init((xxx))) | 63 | #define SHA512_Init(xxx) (CC_SHA512_Init((xxx))) |
| @@ -207,9 +212,11 @@ nodevrandom: | |||
| 207 | return (-1); | 212 | return (-1); |
| 208 | } | 213 | } |
| 209 | 214 | ||
| 215 | #if TARGET_OS_OSX | ||
| 210 | static int tcpmib[] = { CTL_NET, AF_INET, IPPROTO_TCP, TCPCTL_STATS }; | 216 | static int tcpmib[] = { CTL_NET, AF_INET, IPPROTO_TCP, TCPCTL_STATS }; |
| 211 | static int udpmib[] = { CTL_NET, AF_INET, IPPROTO_UDP, UDPCTL_STATS }; | 217 | static int udpmib[] = { CTL_NET, AF_INET, IPPROTO_UDP, UDPCTL_STATS }; |
| 212 | static int ipmib[] = { CTL_NET, AF_INET, IPPROTO_IP, IPCTL_STATS }; | 218 | static int ipmib[] = { CTL_NET, AF_INET, IPPROTO_IP, IPCTL_STATS }; |
| 219 | #endif | ||
| 213 | static int kmib[] = { CTL_KERN, KERN_USRSTACK }; | 220 | static int kmib[] = { CTL_KERN, KERN_USRSTACK }; |
| 214 | static int hwmib[] = { CTL_HW, HW_USERMEM }; | 221 | static int hwmib[] = { CTL_HW, HW_USERMEM }; |
| 215 | 222 | ||
| @@ -229,9 +236,11 @@ getentropy_fallback(void *buf, size_t len) | |||
| 229 | pid_t pid; | 236 | pid_t pid; |
| 230 | size_t i, ii, m; | 237 | size_t i, ii, m; |
| 231 | char *p; | 238 | char *p; |
| 239 | #if TARGET_OS_OSX | ||
| 232 | struct tcpstat tcpstat; | 240 | struct tcpstat tcpstat; |
| 233 | struct udpstat udpstat; | 241 | struct udpstat udpstat; |
| 234 | struct ipstat ipstat; | 242 | struct ipstat ipstat; |
| 243 | #endif | ||
| 235 | u_int64_t mach_time; | 244 | u_int64_t mach_time; |
| 236 | unsigned int idata; | 245 | unsigned int idata; |
| 237 | void *addr; | 246 | void *addr; |
| @@ -266,6 +275,7 @@ getentropy_fallback(void *buf, size_t len) | |||
| 266 | HX(sysctl(hwmib, sizeof(hwmib) / sizeof(hwmib[0]), | 275 | HX(sysctl(hwmib, sizeof(hwmib) / sizeof(hwmib[0]), |
| 267 | &idata, &ii, NULL, 0) == -1, idata); | 276 | &idata, &ii, NULL, 0) == -1, idata); |
| 268 | 277 | ||
| 278 | #if TARGET_OS_OSX | ||
| 269 | ii = sizeof(tcpstat); | 279 | ii = sizeof(tcpstat); |
| 270 | HX(sysctl(tcpmib, sizeof(tcpmib) / sizeof(tcpmib[0]), | 280 | HX(sysctl(tcpmib, sizeof(tcpmib) / sizeof(tcpmib[0]), |
| 271 | &tcpstat, &ii, NULL, 0) == -1, tcpstat); | 281 | &tcpstat, &ii, NULL, 0) == -1, tcpstat); |
| @@ -277,6 +287,7 @@ getentropy_fallback(void *buf, size_t len) | |||
| 277 | ii = sizeof(ipstat); | 287 | ii = sizeof(ipstat); |
| 278 | HX(sysctl(ipmib, sizeof(ipmib) / sizeof(ipmib[0]), | 288 | HX(sysctl(ipmib, sizeof(ipmib) / sizeof(ipmib[0]), |
| 279 | &ipstat, &ii, NULL, 0) == -1, ipstat); | 289 | &ipstat, &ii, NULL, 0) == -1, ipstat); |
| 290 | #endif | ||
| 280 | 291 | ||
| 281 | HX((pid = getpid()) == -1, pid); | 292 | HX((pid = getpid()) == -1, pid); |
| 282 | HX((pid = getsid(pid)) == -1, pid); | 293 | HX((pid = getsid(pid)) == -1, pid); |
