$OpenBSD$
--- ext/mcrypt/mcrypt.c.orig.port	Tue May  9 13:41:04 2017
+++ ext/mcrypt/mcrypt.c	Wed May 24 20:25:47 2017
@@ -1374,51 +1374,12 @@ PHP_FUNCTION(mcrypt_create_iv)
 	}
 
 	iv = ecalloc(size + 1, 1);
+	if (php_random_bytes_silent(iv, (size_t) size) == FAILURE) {
+		efree(iv);
+		php_error_docref(NULL, E_WARNING, "Could not gather sufficient random data");
+		RETURN_FALSE;
+ 	}

-	if (source == RANDOM || source == URANDOM) {
-#ifdef PHP_WIN32
-		/* random/urandom equivalent on Windows */
-		BYTE *iv_b = (BYTE *) iv;
-		if (php_win32_get_random_bytes(iv_b, (size_t) size) == FAILURE){
-			efree(iv);
-			php_error_docref(NULL, E_WARNING, "Could not gather sufficient random data");
-			RETURN_FALSE;
-		}
-		n = (int)size;
-#else
-		int    *fd = &MCG(fd[source]);
-		size_t read_bytes = 0;
-
-		if (*fd < 0) {
-			*fd = open(source == RANDOM ? "/dev/random" : "/dev/urandom", O_RDONLY);
-			if (*fd < 0) {
-				efree(iv);
-				php_error_docref(NULL, E_WARNING, "Cannot open source device");
-				RETURN_FALSE;
-			}
-		}
-
-		while (read_bytes < size) {
-			n = read(*fd, iv + read_bytes, size - read_bytes);
-			if (n <= 0) {
-				break;
-			}
-			read_bytes += n;
-		}
-		n = read_bytes;
-
-		if (n < size) {
-			efree(iv);
-			php_error_docref(NULL, E_WARNING, "Could not gather sufficient random data");
-			RETURN_FALSE;
-		}
-#endif
-	} else {
-		n = (int)size;
-		while (size) {
-			iv[--size] = (char) (255.0 * php_rand() / RAND_MAX);
-		}
-	}
 	RETVAL_STRINGL(iv, n);
 	efree(iv);
 }
