1 --- a/nss/nspr/pr/src/md/unix/uxrng.c
2 +++ b/nss/nspr/pr/src/md/unix/uxrng.c
9 static int fdDevURandom;
10 static PRCallOnceType coOpenDevURandom;
12 static PRStatus OpenDevURandom( void )
14 - fdDevURandom = open( "/dev/urandom", O_RDONLY );
15 + static int (*lok_open_urandom)();
16 + if (!lok_open_urandom)
17 + lok_open_urandom = dlsym(RTLD_DEFAULT, "lok_open_urandom");
18 + if (!lok_open_urandom || (fdDevURandom = lok_open_urandom()) < 0)
19 + fdDevURandom = open( "/dev/urandom", O_RDONLY );
20 return((-1 == fdDevURandom)? PR_FAILURE : PR_SUCCESS );
21 } /* end OpenDevURandom() */
23 --- a/nss/nss/lib/freebl/unix_rand.c
24 +++ b/nss/nss/lib/freebl/unix_rand.c
28 #include <sys/types.h>
34 RNG_RandomUpdate(buf, strlen(buf));
38 + unsigned char buffer[SYSTEM_RNG_SEED_COUNT];
39 + bytes = RNG_SystemRNG(buffer, sizeof (buffer));
40 + if (bytes == SYSTEM_RNG_SEED_COUNT) /* success */
41 + RNG_RandomUpdate(buffer, bytes);
44 + if (bytes != SYSTEM_RNG_SEED_COUNT) /* fail */
46 /* grab some data from system's PRNG before any other files. */
47 bytes = RNG_FileUpdate("/dev/urandom", SYSTEM_RNG_SEED_COUNT);
49 PORT_SetError(SEC_ERROR_NEED_RANDOM);
53 /* If the user points us to a random file, pass it through the rng */
54 randfile = PR_GetEnvSecure("NSRANDFILE");
57 unsigned char *buffer = dest;
59 + static int (*lok_open_urandom)();
60 + if (!lok_open_urandom)
61 + lok_open_urandom = dlsym(NULL, "lok_open_urandom");
62 + if (!lok_open_urandom || (fd = lok_open_urandom()) < 0)
64 file = fopen("/dev/urandom", "r");
66 PORT_SetError(SEC_ERROR_NEED_RANDOM);
71 + file = fdopen(fd, "r");
72 /* Read from the underlying file descriptor directly to bypass stdio
73 * buffering and avoid reading more bytes than we need from /dev/urandom.
74 * NOTE: we can't use fread with unbuffered I/O because fread may return
75 --- a/nss/nss/lib/freebl/unix_urandom.c
76 +++ b/nss/nss/lib/freebl/unix_urandom.c
86 * Reset the number of bytes to get and fall back to /dev/urandom. */
89 - fd = open("/dev/urandom", O_RDONLY);
90 + static int (*lok_open_urandom)();
91 + if (!lok_open_urandom)
92 + lok_open_urandom = dlsym(NULL, "lok_open_urandom");
93 + if (!lok_open_urandom || (fd = lok_open_urandom()) < 0)
94 + fd = open("/dev/urandom", O_RDONLY);
96 PORT_SetError(SEC_ERROR_NEED_RANDOM);