DDraceNetwork Docs
Secure-Random

Functions

void generate_password (char *buffer, unsigned length, const unsigned short *random, unsigned random_length)
 
int secure_random_init ()
 
int secure_random_uninit ()
 
void secure_random_password (char *buffer, unsigned length, unsigned pw_length)
 
void secure_random_fill (void *bytes, unsigned length)
 
int secure_rand ()
 
int secure_rand_below (int below)
 

Detailed Description

Secure random number generation.

Function Documentation

◆ generate_password()

void generate_password ( char *  buffer,
unsigned  length,
const unsigned short *  random,
unsigned  random_length 
)

Generates a null-terminated password of length 2 * random_length.

Parameters
bufferPointer to the start of the output buffer.
lengthLength of the buffer.
randomPointer to a randomly-initialized array of shorts.
random_lengthLength of the short array.

◆ secure_rand()

int secure_rand ( )

Returns random int.

Returns
Random int.
Remarks
Can be used as a replacement for the rand function.

◆ secure_rand_below()

int secure_rand_below ( int  below)

Returns a random nonnegative integer below the given number, with a uniform distribution.

Parameters
belowUpper limit (exclusive) of integers to return.
Returns
Random nonnegative below the given number.

◆ secure_random_fill()

void secure_random_fill ( void *  bytes,
unsigned  length 
)

Fills the buffer with the specified amount of random bytes.

Parameters
bufferPointer to the start of the buffer.
lengthLength of the buffer.

◆ secure_random_init()

int secure_random_init ( )

Initializes the secure random module. You MUST check the return value of this function.

Returns
0 on success.

◆ secure_random_password()

void secure_random_password ( char *  buffer,
unsigned  length,
unsigned  pw_length 
)

Fills the buffer with the specified amount of random password characters.

Parameters
bufferPointer to the start of the buffer.
lengthLength of the buffer.
pw_lengthLength of the desired password.
Remarks
The desired password length must be greater or equal to 6, even and smaller or equal to 128.

◆ secure_random_uninit()

int secure_random_uninit ( )

Uninitializes the secure random module.

Returns
0 on success.