@@ -90,7 +90,7 @@ static ssize_t getrandom(void *buf, size_t buflen, unsigned int flags)
90
90
}
91
91
#endif
92
92
93
- static int randombytes_linux_randombytes_getrandom (void * buf , size_t n )
93
+ static int linux_getrandom (void * buf , size_t n )
94
94
{
95
95
size_t offset = 0 ;
96
96
int ret ;
@@ -114,12 +114,12 @@ static int randombytes_linux_randombytes_getrandom(void *buf, size_t n)
114
114
#if defined(__linux__ ) && !defined(SYS_getrandom )
115
115
116
116
#if defined(__linux__ )
117
- static inline int randombytes_linux_read_entropy_ioctl (int device , int * entropy )
117
+ static inline int linux_read_entropy_ioctl (int device , int * entropy )
118
118
{
119
119
return ioctl (device , RNDGETENTCNT , entropy );
120
120
}
121
121
122
- static int randombytes_linux_read_entropy_proc (FILE * stream , int * entropy )
122
+ static int linux_read_entropy_proc (FILE * stream , int * entropy )
123
123
{
124
124
int retcode ;
125
125
do {
@@ -131,7 +131,7 @@ static int randombytes_linux_read_entropy_proc(FILE *stream, int *entropy)
131
131
return 0 ;
132
132
}
133
133
134
- static int randombytes_linux_wait_for_entropy (int device )
134
+ static int linux_wait_for_entropy (int device )
135
135
{
136
136
/* We will block on /dev/random, because any increase in the OS' entropy
137
137
* level will unblock the request. I use poll here (as does libsodium),
@@ -144,7 +144,7 @@ static int randombytes_linux_wait_for_entropy(int device)
144
144
int entropy = 0 ;
145
145
146
146
/* If the device has enough entropy already, we will want to return early */
147
- int retcode = randombytes_linux_read_entropy_ioctl (device , & entropy );
147
+ int retcode = linux_read_entropy_ioctl (device , & entropy );
148
148
if (retcode != 0 && (errno == ENOTTY || errno == ENOSYS )) {
149
149
/* The ioctl call on /dev/urandom has failed due to a
150
150
* - ENOTTY (unsupported action), or
@@ -184,11 +184,9 @@ static int randombytes_linux_wait_for_entropy(int device)
184
184
continue ;
185
185
} else if (retcode == 1 ) {
186
186
if (strategy == IOCTL ) {
187
- retcode =
188
- randombytes_linux_read_entropy_ioctl (device , & entropy );
187
+ retcode = linux_read_entropy_ioctl (device , & entropy );
189
188
} else if (strategy == PROC ) {
190
- retcode =
191
- randombytes_linux_read_entropy_proc (proc_file , & entropy );
189
+ retcode = linux_read_entropy_proc (proc_file , & entropy );
192
190
} else {
193
191
return -1 ; /* Unreachable */
194
192
}
@@ -220,7 +218,7 @@ static int randombytes_linux_wait_for_entropy(int device)
220
218
}
221
219
#endif /* defined(__linux__) */
222
220
223
- static int randombytes_linux_randombytes_urandom (void * buf , size_t n )
221
+ static int linux_urandom (void * buf , size_t n )
224
222
{
225
223
int fd ;
226
224
do {
@@ -229,7 +227,7 @@ static int randombytes_linux_randombytes_urandom(void *buf, size_t n)
229
227
if (fd == -1 )
230
228
return -1 ;
231
229
#if defined(__linux__ )
232
- if (randombytes_linux_wait_for_entropy (fd ) == -1 )
230
+ if (linux_wait_for_entropy (fd ) == -1 )
233
231
return -1 ;
234
232
#endif
235
233
@@ -259,7 +257,7 @@ static int randombytes_linux_randombytes_urandom(void *buf, size_t n)
259
257
#include <CommonCrypto/CommonRandom.h>
260
258
#endif
261
259
#endif
262
- static int randombytes_bsd_randombytes (void * buf , size_t n )
260
+ static int bsd_randombytes (void * buf , size_t n )
263
261
{
264
262
#if defined(MAC_OS_X_VERSION_10_15 ) && \
265
263
MAC_OS_X_VERSION_MAX_ALLOWED >= MAC_OS_X_VERSION_10_15
@@ -279,16 +277,16 @@ int randombytes(uint8_t *buf, size_t n)
279
277
#if defined(__linux__ ) || defined(__GNU__ )
280
278
#if defined(USE_GLIBC )
281
279
/* Use getrandom system call */
282
- return randombytes_linux_randombytes_getrandom (buf , n );
280
+ return linux_getrandom (buf , n );
283
281
#elif defined(SYS_getrandom )
284
282
/* Use getrandom system call */
285
- return randombytes_linux_randombytes_getrandom (buf , n );
283
+ return linux_getrandom (buf , n );
286
284
#else
287
285
/* When we have enough entropy, we can read from /dev/urandom */
288
- return randombytes_linux_randombytes_urandom (buf , n );
286
+ return linux_urandom (buf , n );
289
287
#endif
290
288
#elif defined(BSD )
291
- return randombytes_bsd_randombytes (buf , n );
289
+ return bsd_randombytes (buf , n );
292
290
#else
293
291
#error "randombytes(...) is not supported on this platform"
294
292
#endif
0 commit comments