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

Macros

#define OUTPUT_LEN   80
 
#define CHK(c)
 

Functions

void mbedtls_hmac_drbg_init (mbedtls_hmac_drbg_context *ctx)
 HMAC_DRBG context initialization Makes the context ready for mbedtls_hmac_drbg_seed(), mbedtls_hmac_drbg_seed_buf() or mbedtls_hmac_drbg_free(). More...
 
void mbedtls_hmac_drbg_update (mbedtls_hmac_drbg_context *ctx, const unsigned char *additional, size_t add_len)
 HMAC_DRBG update state. More...
 
int mbedtls_hmac_drbg_seed_buf (mbedtls_hmac_drbg_context *ctx, const mbedtls_md_info_t *md_info, const unsigned char *data, size_t data_len)
 Initilisation of simpified HMAC_DRBG (never reseeds). (For use with deterministic ECDSA.) More...
 
int mbedtls_hmac_drbg_reseed (mbedtls_hmac_drbg_context *ctx, const unsigned char *additional, size_t len)
 HMAC_DRBG reseeding (extracts data from entropy source) More...
 
int mbedtls_hmac_drbg_seed (mbedtls_hmac_drbg_context *ctx, const mbedtls_md_info_t *md_info, int(*f_entropy)(void *, unsigned char *, size_t), void *p_entropy, const unsigned char *custom, size_t len)
 HMAC_DRBG initial seeding Seed and setup entropy source for future reseeds. More...
 
void mbedtls_hmac_drbg_set_prediction_resistance (mbedtls_hmac_drbg_context *ctx, int resistance)
 Enable / disable prediction resistance (Default: Off) More...
 
void mbedtls_hmac_drbg_set_entropy_len (mbedtls_hmac_drbg_context *ctx, size_t len)
 Set the amount of entropy grabbed on each reseed (Default: given by the security strength, which depends on the hash used, see mbedtls_hmac_drbg_init() ) More...
 
void mbedtls_hmac_drbg_set_reseed_interval (mbedtls_hmac_drbg_context *ctx, int interval)
 Set the reseed interval (Default: MBEDTLS_HMAC_DRBG_RESEED_INTERVAL) More...
 
int mbedtls_hmac_drbg_random_with_add (void *p_rng, unsigned char *output, size_t out_len, const unsigned char *additional, size_t add_len)
 HMAC_DRBG generate random with additional update input. More...
 
int mbedtls_hmac_drbg_random (void *p_rng, unsigned char *output, size_t out_len)
 HMAC_DRBG generate random. More...
 
void mbedtls_hmac_drbg_free (mbedtls_hmac_drbg_context *ctx)
 Free an HMAC_DRBG context. More...
 
int mbedtls_hmac_drbg_write_seed_file (mbedtls_hmac_drbg_context *ctx, const char *path)
 
int mbedtls_hmac_drbg_update_seed_file (mbedtls_hmac_drbg_context *ctx, const char *path)
 
static int hmac_drbg_self_test_entropy (void *data, unsigned char *buf, size_t len)
 
int mbedtls_hmac_drbg_self_test (int verbose)
 

Variables

static const unsigned char entropy_pr []
 
static const unsigned char hmac_result_pr [OUTPUT_LEN]
 
static const unsigned char entropy_nopr []
 
static const unsigned char hmac_result_nopr [OUTPUT_LEN]
 
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

◆ OUTPUT_LEN

#define OUTPUT_LEN   80

Function Documentation

◆ hmac_drbg_self_test_entropy()

static int hmac_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:

◆ mbedtls_hmac_drbg_free()

void mbedtls_hmac_drbg_free ( mbedtls_hmac_drbg_context ctx)

Free an HMAC_DRBG context.

Parameters
ctxHMAC_DRBG context to free.
Here is the call graph for this function:
Here is the caller graph for this function:

◆ mbedtls_hmac_drbg_init()

void mbedtls_hmac_drbg_init ( mbedtls_hmac_drbg_context ctx)

HMAC_DRBG context initialization Makes the context ready for mbedtls_hmac_drbg_seed(), mbedtls_hmac_drbg_seed_buf() or mbedtls_hmac_drbg_free().

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

◆ mbedtls_hmac_drbg_random()

int mbedtls_hmac_drbg_random ( void p_rng,
unsigned char *  output,
size_t  out_len 
)

HMAC_DRBG generate random.

Note: Automatically reseeds if reseed_counter is reached or PR is enabled.

Parameters
p_rngHMAC_DRBG context
outputBuffer to fill
out_lenLength of the buffer
Returns
0 if successful, or MBEDTLS_ERR_HMAC_DRBG_ENTROPY_SOURCE_FAILED, or MBEDTLS_ERR_HMAC_DRBG_REQUEST_TOO_BIG
Here is the call graph for this function:
Here is the caller graph for this function:

◆ mbedtls_hmac_drbg_random_with_add()

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

HMAC_DRBG generate random with additional update input.

Note: Automatically reseeds if reseed_counter is reached or PR is enabled.

Parameters
p_rngHMAC_DRBG context
outputBuffer to fill
output_lenLength of the buffer
additionalAdditional data to update with (can be NULL)
add_lenLength of additional data (can be 0)
Returns
0 if successful, or MBEDTLS_ERR_HMAC_DRBG_ENTROPY_SOURCE_FAILED, or MBEDTLS_ERR_HMAC_DRBG_REQUEST_TOO_BIG, or MBEDTLS_ERR_HMAC_DRBG_INPUT_TOO_BIG.
Here is the call graph for this function:
Here is the caller graph for this function:

◆ mbedtls_hmac_drbg_reseed()

int mbedtls_hmac_drbg_reseed ( mbedtls_hmac_drbg_context ctx,
const unsigned char *  additional,
size_t  len 
)

HMAC_DRBG reseeding (extracts data from entropy source)

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

◆ mbedtls_hmac_drbg_seed()

int mbedtls_hmac_drbg_seed ( mbedtls_hmac_drbg_context ctx,
const mbedtls_md_info_t md_info,
int(*)(void *, unsigned char *, size_t)  f_entropy,
void p_entropy,
const unsigned char *  custom,
size_t  len 
)

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

Parameters
ctxHMAC_DRBG context to be seeded
md_infoMD algorithm to use for HMAC_DRBG
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
Note
The "security strength" as defined by NIST is set to: 128 bits if md_alg is SHA-1, 192 bits if md_alg is SHA-224, 256 bits if md_alg is SHA-256 or higher. Note that SHA-256 is just as efficient as SHA-224.
Returns
0 if successful, or MBEDTLS_ERR_MD_BAD_INPUT_DATA, or MBEDTLS_ERR_MD_ALLOC_FAILED, or MBEDTLS_ERR_HMAC_DRBG_ENTROPY_SOURCE_FAILED.
Here is the call graph for this function:
Here is the caller graph for this function:

◆ mbedtls_hmac_drbg_seed_buf()

int mbedtls_hmac_drbg_seed_buf ( mbedtls_hmac_drbg_context ctx,
const mbedtls_md_info_t md_info,
const unsigned char *  data,
size_t  data_len 
)

Initilisation of simpified HMAC_DRBG (never reseeds). (For use with deterministic ECDSA.)

Parameters
ctxHMAC_DRBG context to be initialised
md_infoMD algorithm to use for HMAC_DRBG
dataConcatenation of entropy string and additional data
data_lenLength of data in bytes
Returns
0 if successful, or MBEDTLS_ERR_MD_BAD_INPUT_DATA, or MBEDTLS_ERR_MD_ALLOC_FAILED.
Here is the call graph for this function:
Here is the caller graph for this function:

◆ mbedtls_hmac_drbg_self_test()

int mbedtls_hmac_drbg_self_test ( int  verbose)
Here is the call graph for this function:

◆ mbedtls_hmac_drbg_set_entropy_len()

void mbedtls_hmac_drbg_set_entropy_len ( mbedtls_hmac_drbg_context ctx,
size_t  len 
)

Set the amount of entropy grabbed on each reseed (Default: given by the security strength, which depends on the hash used, see mbedtls_hmac_drbg_init() )

Parameters
ctxHMAC_DRBG context
lenAmount of entropy to grab, in bytes

◆ mbedtls_hmac_drbg_set_prediction_resistance()

void mbedtls_hmac_drbg_set_prediction_resistance ( mbedtls_hmac_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
ctxHMAC_DRBG context
resistanceMBEDTLS_HMAC_DRBG_PR_ON or MBEDTLS_HMAC_DRBG_PR_OFF
Here is the caller graph for this function:

◆ mbedtls_hmac_drbg_set_reseed_interval()

void mbedtls_hmac_drbg_set_reseed_interval ( mbedtls_hmac_drbg_context ctx,
int  interval 
)

Set the reseed interval (Default: MBEDTLS_HMAC_DRBG_RESEED_INTERVAL)

Parameters
ctxHMAC_DRBG context
intervalReseed interval

◆ mbedtls_hmac_drbg_update()

void mbedtls_hmac_drbg_update ( mbedtls_hmac_drbg_context ctx,
const unsigned char *  additional,
size_t  add_len 
)

HMAC_DRBG update state.

Parameters
ctxHMAC_DRBG context
additionalAdditional data to update state with, or NULL
add_lenLength of additional data, or 0
Note
Additional data is optional, pass NULL and 0 as second third argument if no additional data is being used.
Here is the call graph for this function:
Here is the caller graph for this function:

◆ mbedtls_hmac_drbg_update_seed_file()

int mbedtls_hmac_drbg_update_seed_file ( mbedtls_hmac_drbg_context ctx,
const char *  path 
)
Here is the call graph for this function:

◆ mbedtls_hmac_drbg_write_seed_file()

int mbedtls_hmac_drbg_write_seed_file ( mbedtls_hmac_drbg_context ctx,
const char *  path 
)
Here is the call graph for this function:
Here is the caller graph for this function:

Variable Documentation

◆ entropy_nopr

const unsigned char entropy_nopr[]
static
Initial value:
= {
0x79, 0x34, 0x9b, 0xbf, 0x7c, 0xdd, 0xa5, 0x79, 0x95, 0x57, 0x86, 0x66,
0x21, 0xc9, 0x13, 0x83, 0x11, 0x46, 0x73, 0x3a, 0xbf, 0x8c, 0x35, 0xc8,
0xc7, 0x21, 0x5b, 0x5b, 0x96, 0xc4, 0x8e, 0x9b, 0x33, 0x8c, 0x74, 0xe3,
0xe9, 0x9d, 0xfe, 0xdf }

◆ entropy_pr

const unsigned char entropy_pr[]
static
Initial value:
= {
0xa0, 0xc9, 0xab, 0x58, 0xf1, 0xe2, 0xe5, 0xa4, 0xde, 0x3e, 0xbd, 0x4f,
0xf7, 0x3e, 0x9c, 0x5b, 0x64, 0xef, 0xd8, 0xca, 0x02, 0x8c, 0xf8, 0x11,
0x48, 0xa5, 0x84, 0xfe, 0x69, 0xab, 0x5a, 0xee, 0x42, 0xaa, 0x4d, 0x42,
0x17, 0x60, 0x99, 0xd4, 0x5e, 0x13, 0x97, 0xdc, 0x40, 0x4d, 0x86, 0xa3,
0x7b, 0xf5, 0x59, 0x54, 0x75, 0x69, 0x51, 0xe4 }

◆ hmac_result_nopr

const unsigned char hmac_result_nopr[OUTPUT_LEN]
static
Initial value:
= {
0xc6, 0xa1, 0x6a, 0xb8, 0xd4, 0x20, 0x70, 0x6f, 0x0f, 0x34, 0xab, 0x7f,
0xec, 0x5a, 0xdc, 0xa9, 0xd8, 0xca, 0x3a, 0x13, 0x3e, 0x15, 0x9c, 0xa6,
0xac, 0x43, 0xc6, 0xf8, 0xa2, 0xbe, 0x22, 0x83, 0x4a, 0x4c, 0x0a, 0x0a,
0xff, 0xb1, 0x0d, 0x71, 0x94, 0xf1, 0xc1, 0xa5, 0xcf, 0x73, 0x22, 0xec,
0x1a, 0xe0, 0x96, 0x4e, 0xd4, 0xbf, 0x12, 0x27, 0x46, 0xe0, 0x87, 0xfd,
0xb5, 0xb3, 0xe9, 0x1b, 0x34, 0x93, 0xd5, 0xbb, 0x98, 0xfa, 0xed, 0x49,
0xe8, 0x5f, 0x13, 0x0f, 0xc8, 0xa4, 0x59, 0xb7 }

◆ hmac_result_pr

const unsigned char hmac_result_pr[OUTPUT_LEN]
static
Initial value:
= {
0x9a, 0x00, 0xa2, 0xd0, 0x0e, 0xd5, 0x9b, 0xfe, 0x31, 0xec, 0xb1, 0x39,
0x9b, 0x60, 0x81, 0x48, 0xd1, 0x96, 0x9d, 0x25, 0x0d, 0x3c, 0x1e, 0x94,
0x10, 0x10, 0x98, 0x12, 0x93, 0x25, 0xca, 0xb8, 0xfc, 0xcc, 0x2d, 0x54,
0x73, 0x19, 0x70, 0xc0, 0x10, 0x7a, 0xa4, 0x89, 0x25, 0x19, 0x95, 0x5e,
0x4b, 0xc6, 0x00, 0x1d, 0x7f, 0x4e, 0x6a, 0x2b, 0xf8, 0xa3, 0x01, 0xab,
0x46, 0x05, 0x5c, 0x09, 0xa6, 0x71, 0x88, 0xf1, 0xa7, 0x40, 0xee, 0xf3,
0xe1, 0x5c, 0x02, 0x9b, 0x44, 0xaf, 0x03, 0x44 }

◆ test_offset

size_t test_offset
static