PostgreSQL Source Code  git master
pg_strong_random.c File Reference
#include "c.h"
#include <fcntl.h>
#include <unistd.h>
#include <sys/time.h>
Include dependency graph for pg_strong_random.c:

Go to the source code of this file.

Functions

void pg_strong_random_init (void)
 
bool pg_strong_random (void *buf, size_t len)
 

Function Documentation

◆ pg_strong_random()

bool pg_strong_random ( void *  buf,
size_t  len 
)

Definition at line 153 of file pg_strong_random.c.

References buf, close, EINTR, and read.

Referenced by build_client_first_message(), build_server_first_message(), CheckMD5Auth(), drandom(), gen_random_uuid(), init_sess_key(), InitControlFile(), InitProcessGlobals(), mp_px_rand(), pad_eme_pkcs1_v15(), PerformRadiusTransaction(), pg_be_scram_build_secret(), pg_fe_scram_build_secret(), pg_random_bytes(), pgp_s2k_fill(), px_gen_salt(), RandomCancelKey(), set_random_seed(), and write_prefix().

154 {
155  int f;
156  char *p = buf;
157  ssize_t res;
158 
159  f = open("/dev/urandom", O_RDONLY, 0);
160  if (f == -1)
161  return false;
162 
163  while (len)
164  {
165  res = read(f, p, len);
166  if (res <= 0)
167  {
168  if (errno == EINTR)
169  continue; /* interrupted by signal, just retry */
170 
171  close(f);
172  return false;
173  }
174 
175  p += res;
176  len -= res;
177  }
178 
179  close(f);
180  return true;
181 }
static char * buf
Definition: pg_test_fsync.c:68
#define close(a)
Definition: win32.h:12
#define EINTR
Definition: win32_port.h:343
#define read(a, b, c)
Definition: win32.h:13

◆ pg_strong_random_init()

void pg_strong_random_init ( void  )

Definition at line 147 of file pg_strong_random.c.

Referenced by fork_process().

148 {
149  /* No initialization needed */
150 }