lcx_rng.h | Developers

lcx_rng.h

Back to the files list

Random Number Generation. More...

Typedefs

typedef uint32_t(* cx_rng_u32_range_randfunc_t) (void)

Functions

void cx_rng_no_throw (uint8_t *buffer, size_t len)
 Generates a random buffer such that each byte is between 0 and 255. More...
static unsigned char * cx_rng (uint8_t *buffer, size_t len)
 Generates a random buffer such that each byte is between 0 and 255. More...
static uint32_t cx_rng_u32 (void)
 Returns 32 random bits. More...
static uint8_t cx_rng_u8 (void)
 Returns 8 random bits. More...
uint32_t cx_rng_u32_range_func (uint32_t a, uint32_t b, cx_rng_u32_range_randfunc_t randfunc)
 Generates a random 32-bit unsigned integer with a specified function. More...
static uint32_t cx_rng_u32_range (uint32_t a, uint32_t b)
 Generates a random 32-bit unsigned integer. More...
cx_err_t cx_rng_rfc6979 (cx_md_t hash_id, const uint8_t *x, size_t x_len, const uint8_t *h1, size_t h1_len, const uint8_t *q, size_t q_len, uint8_t *out, size_t out_len)
 Generates a random buffer according to RFC6979 . More...

Detailed Description

Random Number Generation.

Random numbers with different sizes can be generated: a 8-bit random number, a 32-bit random number or a random number of arbitrary size. In this case, the number is returned as a buffer of random bytes. The random number can also be generated within a specific range.

Typedef Documentation

cx_rng_u32_range_randfunc_t

typedef uint32_t(* cx_rng_u32_range_randfunc_t) (void)

Function Documentation

cx_rng()

static unsigned char* cx_rng ( uint8_t *  buffer,
size_t  len 
)

Generates a random buffer such that each byte is between 0 and 255.

Parameters
[out]bufferBuffer to hold the random data.
[in]lenLength of the buffer i.e. number of random bytes to put into the buffer.
Returns
Pointer to the buffer.

cx_rng_no_throw()

void cx_rng_no_throw ( uint8_t *  buffer,
size_t  len 
)

Generates a random buffer such that each byte is between 0 and 255.

Parameters
[out]bufferBuffer to hold the random data.
[in]lenLength of the buffer i.e. number of random bytes to put into the buffer.

cx_rng_rfc6979()

cx_err_t cx_rng_rfc6979 ( cx_md_t  hash_id,
const uint8_t *  x,
size_t  x_len,
const uint8_t *  h1,
size_t  h1_len,
const uint8_t *  q,
size_t  q_len,
uint8_t *  out,
size_t  out_len 
)

Generates a random buffer according to RFC6979 .

Parameters
[in]hash_idMessage digest algorithm identifier.
[in]xECDSA private key.
[in]x_lenLength of the key.
[in]h1Hash of the message.
[in]h1_lenLength of the hash.
[in]qPrime number that is a divisor of the curve order.
[in]q_lenLength of the prime number q.
[out]outBuffer for the output.
[in]out_lenLength of the output.
Returns
Error code:
  • CX_OK on success
  • CX_INVALID_PARAMETER

cx_rng_u32()

static uint32_t cx_rng_u32 ( void  )

Returns 32 random bits.

Returns
A 32-bit random number.

cx_rng_u32_range()

static uint32_t cx_rng_u32_range ( uint32_t  a,
uint32_t  b 
)

Generates a random 32-bit unsigned integer.

The generated number is taken in the range [a;b[ with uniform distribution.

Parameters
[in]aInclusive low bound.
[in]bExclusive high bound.
Returns
A 32-bit random number.

cx_rng_u32_range_func()

uint32_t cx_rng_u32_range_func ( uint32_t  a,
uint32_t  b,
cx_rng_u32_range_randfunc_t  randfunc 
)

Generates a random 32-bit unsigned integer with a specified function.

The generated number is taken in the range [a;b[ with uniform distribution.

Parameters
[in]aInclusive low bound.
[in]bExclusive high bound.
[in]randfuncFunction called to generate the random value.
Returns
A 32-bit random number.

cx_rng_u8()

static uint8_t cx_rng_u8 ( void  )

Returns 8 random bits.

Returns
A 8-bit random number.

Back to the files list


Did you find this page helpful?


How would you improve this page for developers?



Getting Started
Theme Features
Customization

Nano Apps