RetroArch
Macros | Functions | Variables
ctr_drbg.c File Reference
#include "mbedtls/config.h"
#include "mbedtls/ctr_drbg.h"
#include <string.h>
#include <stdio.h>
#include "mbedtls/platform.h"
#include "arc4_alt.h"
Include dependency graph for ctr_drbg.c:

Macros

#define CHK(c)
 

Functions

void mbedtls_ctr_drbg_init (mbedtls_ctr_drbg_context *ctx)
 CTR_DRBG context initialization Makes the context ready for mbedtls_ctr_drbg_seed() or mbedtls_ctr_drbg_free(). More...
 
int mbedtls_ctr_drbg_seed_entropy_len (mbedtls_ctr_drbg_context *ctx, int(*f_entropy)(void *, unsigned char *, size_t), void *p_entropy, const unsigned char *custom, size_t len, size_t entropy_len)
 
int mbedtls_ctr_drbg_seed (mbedtls_ctr_drbg_context *ctx, int(*f_entropy)(void *, unsigned char *, size_t), void *p_entropy, const unsigned char *custom, size_t len)
 CTR_DRBG initial seeding Seed and setup entropy source for future reseeds. More...
 
void mbedtls_ctr_drbg_free (mbedtls_ctr_drbg_context *ctx)
 Clear CTR_CRBG context data. More...
 
void mbedtls_ctr_drbg_set_prediction_resistance (mbedtls_ctr_drbg_context *ctx, int resistance)
 Enable / disable prediction resistance (Default: Off) More...
 
void mbedtls_ctr_drbg_set_entropy_len (mbedtls_ctr_drbg_context *ctx, size_t len)
 Set the amount of entropy grabbed on each (re)seed (Default: MBEDTLS_CTR_DRBG_ENTROPY_LEN) More...
 
void mbedtls_ctr_drbg_set_reseed_interval (mbedtls_ctr_drbg_context *ctx, int interval)
 Set the reseed interval (Default: MBEDTLS_CTR_DRBG_RESEED_INTERVAL) More...
 
static int block_cipher_df (unsigned char *output, const unsigned char *data, size_t data_len)
 
static int ctr_drbg_update_internal (mbedtls_ctr_drbg_context *ctx, const unsigned char data[MBEDTLS_CTR_DRBG_SEEDLEN])
 
void mbedtls_ctr_drbg_update (mbedtls_ctr_drbg_context *ctx, const unsigned char *additional, size_t add_len)
 CTR_DRBG update state. More...
 
int mbedtls_ctr_drbg_reseed (mbedtls_ctr_drbg_context *ctx, const unsigned char *additional, size_t len)
 CTR_DRBG reseeding (extracts data from entropy source) More...
 
int mbedtls_ctr_drbg_random_with_add (void *p_rng, unsigned char *output, size_t output_len, const unsigned char *additional, size_t add_len)
 CTR_DRBG generate random with additional update input. More...
 
int mbedtls_ctr_drbg_random (void *p_rng, unsigned char *output, size_t output_len)
 CTR_DRBG generate random. More...
 
int mbedtls_ctr_drbg_write_seed_file (mbedtls_ctr_drbg_context *ctx, const char *path)
 Write a seed file. More...
 
int mbedtls_ctr_drbg_update_seed_file (mbedtls_ctr_drbg_context *ctx, const char *path)
 Read and update a seed file. Seed is added to this instance. More...
 
static int ctr_drbg_self_test_entropy (void *data, unsigned char *buf, size_t len)
 
int mbedtls_ctr_drbg_self_test (int verbose)
 Checkup routine. More...
 

Variables

static const unsigned char entropy_source_pr [96]
 
static const unsigned char entropy_source_nopr [64]
 
static const unsigned char nonce_pers_pr [16]
 
static const unsigned char nonce_pers_nopr [16]
 
static const unsigned char ctr_result_pr [16]
 
static const unsigned char ctr_result_nopr [16]
 
static size_t test_offset
 

Macro Definition Documentation

◆ CHK

#define CHK (   c)
Value:
if( (c) != 0 ) \
{ \
if( verbose != 0 ) \
mbedtls_printf( "failed\n" ); \
return( 1 ); \
}
const GLubyte * c
Definition: glext.h:9812

Function Documentation

◆ block_cipher_df()

static int block_cipher_df ( unsigned char *  output,
const unsigned char *  data,
size_t  data_len 
)
static
Here is the call graph for this function:
Here is the caller graph for this function:

◆ ctr_drbg_self_test_entropy()

static int ctr_drbg_self_test_entropy ( void data,
unsigned char *  buf,
size_t  len 
)
static
Here is the call graph for this function:
Here is the caller graph for this function:

◆ ctr_drbg_update_internal()

static int ctr_drbg_update_internal ( mbedtls_ctr_drbg_context ctx,
const unsigned char  data[MBEDTLS_CTR_DRBG_SEEDLEN] 
)
static
Here is the call graph for this function:
Here is the caller graph for this function:

◆ mbedtls_ctr_drbg_free()

void mbedtls_ctr_drbg_free ( mbedtls_ctr_drbg_context ctx)

Clear CTR_CRBG context data.

Parameters
ctxCTR_DRBG context to clear
Here is the call graph for this function:
Here is the caller graph for this function:

◆ mbedtls_ctr_drbg_init()

void mbedtls_ctr_drbg_init ( mbedtls_ctr_drbg_context ctx)

CTR_DRBG context initialization Makes the context ready for mbedtls_ctr_drbg_seed() or mbedtls_ctr_drbg_free().

Parameters
ctxCTR_DRBG context to be initialized
Here is the call graph for this function:
Here is the caller graph for this function:

◆ mbedtls_ctr_drbg_random()

int mbedtls_ctr_drbg_random ( void p_rng,
unsigned char *  output,
size_t  output_len 
)

CTR_DRBG generate random.

Note: Automatically reseeds if reseed_counter is reached.

Parameters
p_rngCTR_DRBG context
outputBuffer to fill
output_lenLength of the buffer
Returns
0 if successful, or MBEDTLS_ERR_CTR_DRBG_ENTROPY_SOURCE_FAILED, or MBEDTLS_ERR_CTR_DRBG_REQUEST_TOO_BIG
Here is the call graph for this function:
Here is the caller graph for this function:

◆ mbedtls_ctr_drbg_random_with_add()

int mbedtls_ctr_drbg_random_with_add ( void p_rng,
unsigned char *  output,
size_t  output_len,
const unsigned char *  additional,
size_t  add_len 
)

CTR_DRBG generate random with additional update input.

Note: Automatically reseeds if reseed_counter is reached.

Parameters
p_rngCTR_DRBG context
outputBuffer to fill
output_lenLength of the buffer
additionalAdditional data to update with (Can be NULL)
add_lenLength of additional data
Returns
0 if successful, or MBEDTLS_ERR_CTR_DRBG_ENTROPY_SOURCE_FAILED, or MBEDTLS_ERR_CTR_DRBG_REQUEST_TOO_BIG
Here is the call graph for this function:
Here is the caller graph for this function:

◆ mbedtls_ctr_drbg_reseed()

int mbedtls_ctr_drbg_reseed ( mbedtls_ctr_drbg_context ctx,
const unsigned char *  additional,
size_t  len 
)

CTR_DRBG reseeding (extracts data from entropy source)

Parameters
ctxCTR_DRBG context
additionalAdditional data to add to state (Can be NULL)
lenLength of additional data
Returns
0 if successful, or MBEDTLS_ERR_CTR_DRBG_ENTROPY_SOURCE_FAILED
Here is the call graph for this function:
Here is the caller graph for this function:

◆ mbedtls_ctr_drbg_seed()

int mbedtls_ctr_drbg_seed ( mbedtls_ctr_drbg_context ctx,
int(*)(void *, unsigned char *, size_t)  f_entropy,
void p_entropy,
const unsigned char *  custom,
size_t  len 
)

CTR_DRBG initial seeding Seed and setup entropy source for future reseeds.

Note: Personalization data can be provided in addition to the more generic entropy source to make this instantiation as unique as possible.

Parameters
ctxCTR_DRBG context to be seeded
f_entropyEntropy callback (p_entropy, buffer to fill, buffer length)
p_entropyEntropy context
customPersonalization data (Device specific identifiers) (Can be NULL)
lenLength of personalization data
Returns
0 if successful, or MBEDTLS_ERR_CTR_DRBG_ENTROPY_SOURCE_FAILED
Here is the call graph for this function:
Here is the caller graph for this function:

◆ mbedtls_ctr_drbg_seed_entropy_len()

int mbedtls_ctr_drbg_seed_entropy_len ( mbedtls_ctr_drbg_context ctx,
int(*)(void *, unsigned char *, size_t)  f_entropy,
void p_entropy,
const unsigned char *  custom,
size_t  len,
size_t  entropy_len 
)
Here is the call graph for this function:
Here is the caller graph for this function:

◆ mbedtls_ctr_drbg_self_test()

int mbedtls_ctr_drbg_self_test ( int  verbose)

Checkup routine.

Returns
0 if successful, or 1 if the test failed
Here is the call graph for this function:

◆ mbedtls_ctr_drbg_set_entropy_len()

void mbedtls_ctr_drbg_set_entropy_len ( mbedtls_ctr_drbg_context ctx,
size_t  len 
)

Set the amount of entropy grabbed on each (re)seed (Default: MBEDTLS_CTR_DRBG_ENTROPY_LEN)

Parameters
ctxCTR_DRBG context
lenAmount of entropy to grab

◆ mbedtls_ctr_drbg_set_prediction_resistance()

void mbedtls_ctr_drbg_set_prediction_resistance ( mbedtls_ctr_drbg_context ctx,
int  resistance 
)

Enable / disable prediction resistance (Default: Off)

Note: If enabled, entropy is used for ctx->entropy_len before each call! Only use this if you have ample supply of good entropy!

Parameters
ctxCTR_DRBG context
resistanceMBEDTLS_CTR_DRBG_PR_ON or MBEDTLS_CTR_DRBG_PR_OFF
Here is the caller graph for this function:

◆ mbedtls_ctr_drbg_set_reseed_interval()

void mbedtls_ctr_drbg_set_reseed_interval ( mbedtls_ctr_drbg_context ctx,
int  interval 
)

Set the reseed interval (Default: MBEDTLS_CTR_DRBG_RESEED_INTERVAL)

Parameters
ctxCTR_DRBG context
intervalReseed interval

◆ mbedtls_ctr_drbg_update()

void mbedtls_ctr_drbg_update ( mbedtls_ctr_drbg_context ctx,
const unsigned char *  additional,
size_t  add_len 
)

CTR_DRBG update state.

Parameters
ctxCTR_DRBG context
additionalAdditional data to update state with
add_lenLength of additional data
Note
If add_len is greater than MBEDTLS_CTR_DRBG_MAX_SEED_INPUT, only the first MBEDTLS_CTR_DRBG_MAX_SEED_INPUT bytes are used, the remaining ones are silently discarded.
Here is the call graph for this function:
Here is the caller graph for this function:

◆ mbedtls_ctr_drbg_update_seed_file()

int mbedtls_ctr_drbg_update_seed_file ( mbedtls_ctr_drbg_context ctx,
const char *  path 
)

Read and update a seed file. Seed is added to this instance.

Parameters
ctxCTR_DRBG context
pathName of the file
Returns
0 if successful, MBEDTLS_ERR_CTR_DRBG_FILE_IO_ERROR on file error, MBEDTLS_ERR_CTR_DRBG_ENTROPY_SOURCE_FAILED or MBEDTLS_ERR_CTR_DRBG_INPUT_TOO_BIG
Here is the call graph for this function:

◆ mbedtls_ctr_drbg_write_seed_file()

int mbedtls_ctr_drbg_write_seed_file ( mbedtls_ctr_drbg_context ctx,
const char *  path 
)

Write a seed file.

Parameters
ctxCTR_DRBG context
pathName of the file
Returns
0 if successful, MBEDTLS_ERR_CTR_DRBG_FILE_IO_ERROR on file error, or MBEDTLS_ERR_CTR_DRBG_ENTROPY_SOURCE_FAILED
Here is the call graph for this function:
Here is the caller graph for this function:

Variable Documentation

◆ ctr_result_nopr

const unsigned char ctr_result_nopr[16]
static
Initial value:
=
{ 0xa0, 0x54, 0x30, 0x3d, 0x8a, 0x7e, 0xa9, 0x88,
0x9d, 0x90, 0x3e, 0x07, 0x7c, 0x6f, 0x21, 0x8f }

◆ ctr_result_pr

const unsigned char ctr_result_pr[16]
static
Initial value:
=
{ 0x34, 0x01, 0x16, 0x56, 0xb4, 0x29, 0x00, 0x8f,
0x35, 0x63, 0xec, 0xb5, 0xf2, 0x59, 0x07, 0x23 }

◆ entropy_source_nopr

const unsigned char entropy_source_nopr[64]
static
Initial value:
=
{ 0x5a, 0x19, 0x4d, 0x5e, 0x2b, 0x31, 0x58, 0x14,
0x54, 0xde, 0xf6, 0x75, 0xfb, 0x79, 0x58, 0xfe,
0xc7, 0xdb, 0x87, 0x3e, 0x56, 0x89, 0xfc, 0x9d,
0x03, 0x21, 0x7c, 0x68, 0xd8, 0x03, 0x38, 0x20,
0xf9, 0xe6, 0x5e, 0x04, 0xd8, 0x56, 0xf3, 0xa9,
0xc4, 0x4a, 0x4c, 0xbd, 0xc1, 0xd0, 0x08, 0x46,
0xf5, 0x98, 0x3d, 0x77, 0x1c, 0x1b, 0x13, 0x7e,
0x4e, 0x0f, 0x9d, 0x8e, 0xf4, 0x09, 0xf9, 0x2e }

◆ entropy_source_pr

const unsigned char entropy_source_pr[96]
static
Initial value:
=
{ 0xc1, 0x80, 0x81, 0xa6, 0x5d, 0x44, 0x02, 0x16,
0x19, 0xb3, 0xf1, 0x80, 0xb1, 0xc9, 0x20, 0x02,
0x6a, 0x54, 0x6f, 0x0c, 0x70, 0x81, 0x49, 0x8b,
0x6e, 0xa6, 0x62, 0x52, 0x6d, 0x51, 0xb1, 0xcb,
0x58, 0x3b, 0xfa, 0xd5, 0x37, 0x5f, 0xfb, 0xc9,
0xff, 0x46, 0xd2, 0x19, 0xc7, 0x22, 0x3e, 0x95,
0x45, 0x9d, 0x82, 0xe1, 0xe7, 0x22, 0x9f, 0x63,
0x31, 0x69, 0xd2, 0x6b, 0x57, 0x47, 0x4f, 0xa3,
0x37, 0xc9, 0x98, 0x1c, 0x0b, 0xfb, 0x91, 0x31,
0x4d, 0x55, 0xb9, 0xe9, 0x1c, 0x5a, 0x5e, 0xe4,
0x93, 0x92, 0xcf, 0xc5, 0x23, 0x12, 0xd5, 0x56,
0x2c, 0x4a, 0x6e, 0xff, 0xdc, 0x10, 0xd0, 0x68 }

◆ nonce_pers_nopr

const unsigned char nonce_pers_nopr[16]
static
Initial value:
=
{ 0x1b, 0x54, 0xb8, 0xff, 0x06, 0x42, 0xbf, 0xf5,
0x21, 0xf1, 0x5c, 0x1c, 0x0b, 0x66, 0x5f, 0x3f }

◆ nonce_pers_pr

const unsigned char nonce_pers_pr[16]
static
Initial value:
=
{ 0xd2, 0x54, 0xfc, 0xff, 0x02, 0x1e, 0x69, 0xd2,
0x29, 0xc9, 0xcf, 0xad, 0x85, 0xfa, 0x48, 0x6c }

◆ test_offset

size_t test_offset
static