File tree Expand file tree Collapse file tree 1 file changed +15
-9
lines changed
Expand file tree Collapse file tree 1 file changed +15
-9
lines changed Original file line number Diff line number Diff line change 3737# pragma comment(lib, "Bcrypt")
3838#else
3939# include <stdlib.h>
40- # include <time.h>
40+ # ifndef __APPLE__
41+ # include <time.h>
42+ # endif
4143#endif
4244
4345typedef unsigned char byte ;
@@ -80,28 +82,32 @@ const char * GenSecureCSPNonce(const request_rec * r)
8082 // depending on the system. With modern kernels this
8183 // will be true.
8284 // https://man7.org/linux/man-pages/man3/random.3.html
83- int r ;
85+ int h ;
8486
87+ // Seed the PRNG
88+ # ifdef __APPLE__
89+ srandomdev ();
90+ # else
8591 struct timespec ts ;
8692 if (timespec_get (& ts , TIME_UTC ) == 0 )
8793 return NULL ;
8894
89- // Seed the PRNG
9095 srandom (ts .tv_nsec ^ ts .tv_sec );
96+ # endif
9197
9298 // Generate a random integer
9399 // fill up bytes 0,1,2,3
94- r = random ();
95- memcpy (random_bytes , & r , 4 );
100+ h = random ();
101+ memcpy (random_bytes , & h , 4 );
96102
97103 // fill up bytes 4,5,6,7
98- r = random ();
99- memcpy (random_bytes + 4 , & r , 4 );
104+ h = random ();
105+ memcpy (random_bytes + 4 , & h , 4 );
100106
101107 // fill up bytes 5,6,7,8
102108 // Yes, there's overlap.
103- r = random ();
104- memcpy (random_bytes + 5 , & r , 4 );
109+ h = random ();
110+ memcpy (random_bytes + 5 , & h , 4 );
105111#endif
106112
107113 char * cspNonce ;
You can’t perform that action at this time.
0 commit comments