diff options
Diffstat (limited to 'src/lib/libcrypto/rand/rand_egd.c')
| -rw-r--r-- | src/lib/libcrypto/rand/rand_egd.c | 57 |
1 files changed, 57 insertions, 0 deletions
diff --git a/src/lib/libcrypto/rand/rand_egd.c b/src/lib/libcrypto/rand/rand_egd.c index 380c7828c3..02a0d86fa3 100644 --- a/src/lib/libcrypto/rand/rand_egd.c +++ b/src/lib/libcrypto/rand/rand_egd.c | |||
| @@ -64,6 +64,11 @@ int RAND_egd(const char *path) | |||
| 64 | { | 64 | { |
| 65 | return(-1); | 65 | return(-1); |
| 66 | } | 66 | } |
| 67 | |||
| 68 | int RAND_egd_bytes(const char *path,int bytes) | ||
| 69 | { | ||
| 70 | return(-1); | ||
| 71 | } | ||
| 67 | #else | 72 | #else |
| 68 | #include <openssl/opensslconf.h> | 73 | #include <openssl/opensslconf.h> |
| 69 | #include OPENSSL_UNISTD | 74 | #include OPENSSL_UNISTD |
| @@ -107,4 +112,56 @@ int RAND_egd(const char *path) | |||
| 107 | if (fd != -1) close(fd); | 112 | if (fd != -1) close(fd); |
| 108 | return(ret); | 113 | return(ret); |
| 109 | } | 114 | } |
| 115 | |||
| 116 | int RAND_egd_bytes(const char *path,int bytes) | ||
| 117 | { | ||
| 118 | int ret = 0; | ||
| 119 | struct sockaddr_un addr; | ||
| 120 | int len, num; | ||
| 121 | int fd = -1; | ||
| 122 | unsigned char buf[255]; | ||
| 123 | |||
| 124 | memset(&addr, 0, sizeof(addr)); | ||
| 125 | addr.sun_family = AF_UNIX; | ||
| 126 | if (strlen(path) > sizeof(addr.sun_path)) | ||
| 127 | return (-1); | ||
| 128 | strcpy(addr.sun_path,path); | ||
| 129 | len = offsetof(struct sockaddr_un, sun_path) + strlen(path); | ||
| 130 | fd = socket(AF_UNIX, SOCK_STREAM, 0); | ||
| 131 | if (fd == -1) return (-1); | ||
| 132 | if (connect(fd, (struct sockaddr *)&addr, len) == -1) goto err; | ||
| 133 | |||
| 134 | while(bytes > 0) | ||
| 135 | { | ||
| 136 | buf[0] = 1; | ||
| 137 | buf[1] = bytes < 255 ? bytes : 255; | ||
| 138 | write(fd, buf, 2); | ||
| 139 | if (read(fd, buf, 1) != 1) | ||
| 140 | { | ||
| 141 | ret=-1; | ||
| 142 | goto err; | ||
| 143 | } | ||
| 144 | if(buf[0] == 0) | ||
| 145 | goto err; | ||
| 146 | num = read(fd, buf, buf[0]); | ||
| 147 | if (num < 1) | ||
| 148 | { | ||
| 149 | ret=-1; | ||
| 150 | goto err; | ||
| 151 | } | ||
| 152 | RAND_seed(buf, num); | ||
| 153 | if (RAND_status() != 1) | ||
| 154 | { | ||
| 155 | ret=-1; | ||
| 156 | goto err; | ||
| 157 | } | ||
| 158 | ret += num; | ||
| 159 | bytes-=num; | ||
| 160 | } | ||
| 161 | err: | ||
| 162 | if (fd != -1) close(fd); | ||
| 163 | return(ret); | ||
| 164 | } | ||
| 165 | |||
| 166 | |||
| 110 | #endif | 167 | #endif |
