Rizin
unix-like reverse engineering framework and cli tools
zip_random_uwp.c File Reference
#include "zipint.h"
#include <windows.h>
#include <bcrypt.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 66 of file zip_random_uwp.c.

66  {
67  static bool seeded = false;
68 
70 
71  if (zip_secure_random((zip_uint8_t *)&value, sizeof(value))) {
72  return value;
73  }
74 
75  if (!seeded) {
76  srand((unsigned int)time(NULL));
77  }
78 
79  return (zip_uint32_t)rand();
80 }
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().

◆ zip_secure_random()

ZIP_EXTERN bool zip_secure_random ( zip_uint8_t buffer,
zip_uint16_t  length 
)

Definition at line 46 of file zip_random_uwp.c.

46  {
47  BCRYPT_ALG_HANDLE hAlg = NULL;
48  NTSTATUS hr = BCryptOpenAlgorithmProvider(&hAlg, BCRYPT_RNG_ALGORITHM, MS_PRIMITIVE_PROVIDER, 0);
49  if (!BCRYPT_SUCCESS(hr) || hAlg == NULL) {
50  return false;
51  }
52  hr = BCryptGenRandom(&hAlg, buffer, length, 0);
53  BCryptCloseAlgorithmProvider(&hAlg, 0);
54  if (!BCRYPT_SUCCESS(hr)) {
55  return false;
56  }
57  return true;
58 }
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
Definition: buffer.h:15
LONG NTSTATUS
Definition: win.h:198

References length, and NULL.

Referenced by zip_random_uint32().