Rizin
unix-like reverse engineering framework and cli tools
zip_random_unix.c File Reference
#include "zipint.h"
#include <fcntl.h>
#include <unistd.h>
#include <stdlib.h>

Go to the source code of this file.

Functions

ZIP_EXTERN bool zip_secure_random (zip_uint8_t *buffer, zip_uint16_t length)
 
zip_uint32_t zip_random_uint32 (void)
 

Function Documentation

◆ zip_random_uint32()

zip_uint32_t zip_random_uint32 ( void  )

Definition at line 87 of file zip_random_unix.c.

87  {
88  static bool seeded = false;
89 
91 
92  if (zip_secure_random((zip_uint8_t *)&value, sizeof(value))) {
93  return value;
94  }
95 
96  if (!seeded) {
97  srandom((unsigned int)time(NULL));
98  }
99 
100  return (zip_uint32_t)random();
101 }
static int value
Definition: cmd_api.c:93
#define NULL
Definition: cris-opc.c:27
static static fork const void static count static fd const char const char static newpath char char char static envp time
Definition: sflib.h:42
ZIP_EXTERN bool zip_secure_random(zip_uint8_t *buffer, zip_uint16_t length)
uint32_t zip_uint32_t
Definition: zipconf.h:37
uint8_t zip_uint8_t
Definition: zipconf.h:33

References NULL, time, value, and zip_secure_random().

Referenced by create_temp_file().

◆ zip_secure_random()

ZIP_EXTERN bool zip_secure_random ( zip_uint8_t buffer,
zip_uint16_t  length 
)

Definition at line 66 of file zip_random_unix.c.

66  {
67  int fd;
68 
69  if ((fd = open("/dev/urandom", O_RDONLY)) < 0) {
70  return false;
71  }
72 
73  if (read(fd, buffer, length) != length) {
74  close(fd);
75  return false;
76  }
77 
78  close(fd);
79  return true;
80 }
static static fork const void static count close
Definition: sflib.h:33
static static sync static getppid static getegid const char static filename char static len const char char static bufsiz static mask static vfork const void static prot static getpgrp const char static swapflags static arg static fd static protocol static who struct sockaddr static addrlen static backlog struct timeval struct timezone static tz const struct iovec static count static mode const void const struct sockaddr static tolen const char static pathname void static offset struct stat static buf void long static basep static whence static length const void static len static semflg const void static shmflg const struct timespec struct timespec static rem const char static group const void length
Definition: sflib.h:133
#define O_RDONLY
Definition: sftypes.h:486
Definition: buffer.h:15
static const z80_opcode fd[]
Definition: z80_tab.h:997
int read(izstream &zs, T *x, Items items)
Definition: zstream.h:115

References close, fd, length, O_RDONLY, and read().

Referenced by zip_random_uint32().