static int unix_bytes(unsigned char *outdata, int size) { ssize_t count; int fd; if (size < 0) return 0; else if (size == 0) return 1; fd = _hc_unix_device_fd(O_RDONLY, NULL); if (fd < 0) return 0; while (size > 0) { count = read(fd, outdata, size); if (count < 0 && errno == EINTR) continue; else if (count <= 0) { close(fd); return 0; } outdata += count; size -= count; } close(fd); return 1; }
const char * RAND_file_name(char *filename, size_t size) { const char *e = NULL; int pathp = 0, ret; if (!issuid()) { e = getenv("RANDFILE"); if (e == NULL) e = getenv("HOME"); if (e) pathp = 1; } #ifndef _WIN32 /* * Here we really want to call getpwuid(getuid()) but this will * cause recursive lookups if the nss library uses * gssapi/krb5/hcrypto to authenticate to the ldap servers. * * So at least return the unix /dev/random if we have one */ if (e == NULL) { int fd; fd = _hc_unix_device_fd(O_RDONLY, &e); if (fd >= 0) close(fd); } #else /* Win32 */ if (e == NULL) { char profile[MAX_PATH]; if (SHGetFolderPath(NULL, CSIDL_LOCAL_APPDATA, NULL, SHGFP_TYPE_CURRENT, profile) == S_OK) { ret = snprintf(filename, size, "%s\\.rnd", profile); if (ret > 0 && ret < size) return filename; } } #endif if (e == NULL) return NULL; if (pathp) ret = snprintf(filename, size, "%s/.rnd", e); else ret = snprintf(filename, size, "%s", e); if (ret <= 0 || ret >= size) return NULL; return filename; }
static int unix_status(void) { int fd; fd = _hc_unix_device_fd(O_RDONLY, NULL); if (fd < 0) return 0; close(fd); return 1; }
static void unix_seed(const void *indata, int size) { int fd; if (size <= 0) return; fd = _hc_unix_device_fd(O_WRONLY, NULL); if (fd < 0) return; write(fd, indata, size); close(fd); }