poser
A C framework for POsix SERvices
|
Get some random data. More...
#include <poser/core/random.h>
Static Public Member Functions | |
size_t | PSC_Random_bytes (uint8_t *buf, size_t count, PSC_RandomFlags flags) |
Fill a buffer with random bytes. | |
size_t | PSC_Random_string (char *str, size_t size, PSC_RandomFlags flags) |
Fill a buffer with a random string. | |
char * | PSC_Random_createStr (size_t count, PSC_RandomFlags flags) |
Create a newly allocated random string. | |
Get some random data.
Provides static methods to obtain random bytes and random strings. If available, arc4random() is used for that, which is expected to never block, never fail and return cryptographically secure random data.
If arc4random is not available, several other methods are tried.
|
static |
Fill a buffer with random bytes.
This never fails unless PSC_RF_SECURE is given and arc4random() is not available.
buf | the buffer to fill |
count | the number of random bytes put into buf |
flags | flags controlling methods used |
count
on error
|
static |
Create a newly allocated random string.
The string is constructed by base64-encoding random bytes. Memory for the new string is allocated, so the caller has to free() it later. This never fails unless PSC_RF_SECURE is given and arc4random() is not available.
count | use this many random bytes to construct the string |
flags | flags controlling methods used |
|
static |
Fill a buffer with a random string.
The string is constructed by base64-encoding random bytes. This never fails unless PSC_RF_SECURE is given and arc4random() is not available.
str | the buffer to put the string into |
size | the length of the string, including a terminating NUL |
flags | flags controlling methods used |
size
on error