mirror of
https://gitlab.alpinelinux.org/alpine/aports.git
synced 2026-03-29 10:21:38 +02:00
39 lines
946 B
Diff
39 lines
946 B
Diff
--- a/bcrypt/crypt-blowfish.c 2018-10-13 22:05:57.000000000 -0400
|
|
+++ b/bcrypt/crypt-blowfish.c 2025-11-12 22:21:08.564339885 -0500
|
|
@@ -79,6 +79,35 @@
|
|
#include "crypt.h"
|
|
#endif
|
|
|
|
+/* Musl libc compatibility - arc4random() implementation using /dev/urandom */
|
|
+#include <fcntl.h>
|
|
+#include <unistd.h>
|
|
+
|
|
+static u_int32_t arc4random(void)
|
|
+{
|
|
+ static int fd = -1;
|
|
+ u_int32_t val;
|
|
+ ssize_t n;
|
|
+
|
|
+ if (fd < 0) {
|
|
+ fd = open("/dev/urandom", O_RDONLY | O_CLOEXEC);
|
|
+ if (fd < 0) {
|
|
+ /* Fallback to less secure method if /dev/urandom unavailable */
|
|
+ return (u_int32_t)random();
|
|
+ }
|
|
+ }
|
|
+
|
|
+ n = read(fd, &val, sizeof(val));
|
|
+ if (n != sizeof(val)) {
|
|
+ /* If read fails, close fd and try again next time */
|
|
+ close(fd);
|
|
+ fd = -1;
|
|
+ return (u_int32_t)random();
|
|
+ }
|
|
+
|
|
+ return val;
|
|
+}
|
|
+
|
|
/* This implementation is adaptable to current computing power.
|
|
* You can have up to 2^31 rounds which should be enough for some
|
|
* time to come.
|