Software APIs
Functions
prng.h File Reference

(f5294e3daf)

PRNG for side-channel analysis. More...

#include <stddef.h>
#include <stdint.h>

Go to the source code of this file.

Functions

void prng_seed (uint32_t seed)
 Initializes the random number generator. More...
 
uint32_t prng_rand_uint32 (void)
 Generates a random uint32_t. More...
 
uint8_t prng_rand_byte (void)
 Generates a random byte. More...
 
void prng_rand_bytes (uint8_t *buffer, size_t buffer_len)
 Fills a buffer with random bytes. More...
 

Detailed Description

PRNG for side-channel analysis.

This library provides a Mersenne Twister PRNG that can be used to generate random plaintexts on the device. Generating random plaintexts on the device eliminates the overhead of sending them from the host and can significantly improve capture rate. The host must use the same PRNG to be able to compute the plaintext and the ciphertext of each trace.

TODO(alphan): Replace this with a more efficient PRNG after updating host-side code.

Definition in file prng.h.

Function Documentation

◆ prng_rand_byte()

uint8_t prng_rand_byte ( void  )

Generates a random byte.

The behavior of this function matches the behavior of random.randint(0, 255) in python, which is used by ChipWhisperer's ktp.next().

Returns
A random byte.

Definition at line 163 of file prng.c.

◆ prng_rand_bytes()

void prng_rand_bytes ( uint8_t *  buffer,
size_t  buffer_len 
)

Fills a buffer with random bytes.

The behavior of this function matches the behavior of random.randint(0, 255) in python, which is used by ChipWhisperer's ktp.next().

Parameters
[out]bufferA buffer.
buffer_lenSize of the buffer.
Returns
A random byte.

Definition at line 179 of file prng.c.

◆ prng_rand_uint32()

uint32_t prng_rand_uint32 ( void  )

Generates a random uint32_t.

The behavior of this function matches the behavior of random.randint(0, 0xFFFFFFFF) in python.

Returns
A random uint32_t.

Definition at line 161 of file prng.c.

◆ prng_seed()

void prng_seed ( uint32_t  seed)

Initializes the random number generator.

Parameters
seedSeed to initalize with.

Initializes the random number generator.

TODO(alphan): Using MT for now as a proof of concept to minimize host-side changes. We should probably replace this with a PRNG from xoshiro* family for PRNGs, e.g. xoshiro128++, for better performance and less overhead.

Definition at line 159 of file prng.c.