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

Macros

#define DHM_MPI_EXPORT(X, n)
 

Functions

static int dhm_read_bignum (mbedtls_mpi *X, unsigned char **p, const unsigned char *end)
 
static int dhm_check_range (const mbedtls_mpi *param, const mbedtls_mpi *P)
 
void mbedtls_dhm_init (mbedtls_dhm_context *ctx)
 Initialize DHM context. More...
 
int mbedtls_dhm_read_params (mbedtls_dhm_context *ctx, unsigned char **p, const unsigned char *end)
 Parse the ServerKeyExchange parameters. More...
 
int mbedtls_dhm_make_params (mbedtls_dhm_context *ctx, int x_size, unsigned char *output, size_t *olen, int(*f_rng)(void *, unsigned char *, size_t), void *p_rng)
 Setup and write the ServerKeyExchange parameters. More...
 
int mbedtls_dhm_read_public (mbedtls_dhm_context *ctx, const unsigned char *input, size_t ilen)
 Import the peer's public value G^Y. More...
 
int mbedtls_dhm_make_public (mbedtls_dhm_context *ctx, int x_size, unsigned char *output, size_t olen, int(*f_rng)(void *, unsigned char *, size_t), void *p_rng)
 Create own private value X and export G^X. More...
 
static int dhm_update_blinding (mbedtls_dhm_context *ctx, int(*f_rng)(void *, unsigned char *, size_t), void *p_rng)
 
int mbedtls_dhm_calc_secret (mbedtls_dhm_context *ctx, unsigned char *output, size_t output_size, size_t *olen, int(*f_rng)(void *, unsigned char *, size_t), void *p_rng)
 Derive and export the shared secret (G^Y)^X mod P. More...
 
void mbedtls_dhm_free (mbedtls_dhm_context *ctx)
 Free and clear the components of a DHM key. More...
 
int mbedtls_dhm_parse_dhm (mbedtls_dhm_context *dhm, const unsigned char *dhmin, size_t dhminlen)
 Parse DHM parameters in PEM or DER format. More...
 
static int load_file (const char *path, unsigned char **buf, size_t *n)
 
int mbedtls_dhm_parse_dhmfile (mbedtls_dhm_context *dhm, const char *path)
 Load and parse DHM parameters. More...
 
int mbedtls_dhm_self_test (int verbose)
 Checkup routine. More...
 

Variables

static const char mbedtls_test_dhm_params []
 
static const size_t mbedtls_test_dhm_params_len = sizeof( mbedtls_test_dhm_params )
 

Macro Definition Documentation

◆ DHM_MPI_EXPORT

#define DHM_MPI_EXPORT (   X,
  n 
)
Value:
*p++ = (unsigned char)( n >> 8 ); \
*p++ = (unsigned char)( n ); p += n;
int mbedtls_mpi_write_binary(const mbedtls_mpi *X, unsigned char *buf, size_t buflen)
Export X into unsigned binary data, big endian. Always fills the whole buffer, which will start with ...
Definition: bignum.c:695
#define MBEDTLS_MPI_CHK(f)
Definition: bignum.h:48
GLfloat GLfloat p
Definition: glext.h:9809
#define X(a, b)
Definition: bba.c:185
GLdouble n
Definition: glext.h:8396

Function Documentation

◆ dhm_check_range()

static int dhm_check_range ( const mbedtls_mpi param,
const mbedtls_mpi P 
)
static
Here is the call graph for this function:
Here is the caller graph for this function:

◆ dhm_read_bignum()

static int dhm_read_bignum ( mbedtls_mpi X,
unsigned char **  p,
const unsigned char *  end 
)
static
Here is the call graph for this function:
Here is the caller graph for this function:

◆ dhm_update_blinding()

static int dhm_update_blinding ( mbedtls_dhm_context ctx,
int(*)(void *, unsigned char *, size_t)  f_rng,
void p_rng 
)
static
Here is the call graph for this function:
Here is the caller graph for this function:

◆ load_file()

static int load_file ( const char *  path,
unsigned char **  buf,
size_t *  n 
)
static
Here is the call graph for this function:
Here is the caller graph for this function:

◆ mbedtls_dhm_calc_secret()

int mbedtls_dhm_calc_secret ( mbedtls_dhm_context ctx,
unsigned char *  output,
size_t  output_size,
size_t *  olen,
int(*)(void *, unsigned char *, size_t)  f_rng,
void p_rng 
)

Derive and export the shared secret (G^Y)^X mod P.

Parameters
ctxDHM context
outputdestination buffer
output_sizesize of the destination buffer
olenon exit, holds the actual number of bytes written
f_rngRNG function, for blinding purposes
p_rngRNG parameter
Returns
0 if successful, or an MBEDTLS_ERR_DHM_XXX error code
Note
If non-NULL, f_rng is used to blind the input as countermeasure against timing attacks. Blinding is automatically used if and only if our secret value X is re-used and costs nothing otherwise, so it is recommended to always pass a non-NULL f_rng argument.
Here is the call graph for this function:
Here is the caller graph for this function:

◆ mbedtls_dhm_free()

void mbedtls_dhm_free ( mbedtls_dhm_context ctx)

Free and clear the components of a DHM key.

Parameters
ctxDHM context to free and clear
Here is the call graph for this function:
Here is the caller graph for this function:

◆ mbedtls_dhm_init()

void mbedtls_dhm_init ( mbedtls_dhm_context ctx)

Initialize DHM context.

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

◆ mbedtls_dhm_make_params()

int mbedtls_dhm_make_params ( mbedtls_dhm_context ctx,
int  x_size,
unsigned char *  output,
size_t *  olen,
int(*)(void *, unsigned char *, size_t)  f_rng,
void p_rng 
)

Setup and write the ServerKeyExchange parameters.

Parameters
ctxDHM context
x_sizeprivate value size in bytes
outputdestination buffer
olennumber of chars written
f_rngRNG function
p_rngRNG parameter
Note
This function assumes that ctx->P and ctx->G have already been properly set (for example using mbedtls_mpi_read_string or mbedtls_mpi_read_binary).
Returns
0 if successful, or an MBEDTLS_ERR_DHM_XXX error code
Here is the call graph for this function:
Here is the caller graph for this function:

◆ mbedtls_dhm_make_public()

int mbedtls_dhm_make_public ( mbedtls_dhm_context ctx,
int  x_size,
unsigned char *  output,
size_t  olen,
int(*)(void *, unsigned char *, size_t)  f_rng,
void p_rng 
)

Create own private value X and export G^X.

Parameters
ctxDHM context
x_sizeprivate value size in bytes
outputdestination buffer
olenmust be at least equal to the size of P, ctx->len
f_rngRNG function
p_rngRNG parameter
Returns
0 if successful, or an MBEDTLS_ERR_DHM_XXX error code
Here is the call graph for this function:
Here is the caller graph for this function:

◆ mbedtls_dhm_read_params()

int mbedtls_dhm_read_params ( mbedtls_dhm_context ctx,
unsigned char **  p,
const unsigned char *  end 
)

Parse the ServerKeyExchange parameters.

Parameters
ctxDHM context
p&(start of input buffer)
endend of buffer
Returns
0 if successful, or an MBEDTLS_ERR_DHM_XXX error code
Here is the call graph for this function:
Here is the caller graph for this function:

◆ mbedtls_dhm_read_public()

int mbedtls_dhm_read_public ( mbedtls_dhm_context ctx,
const unsigned char *  input,
size_t  ilen 
)

Import the peer's public value G^Y.

Parameters
ctxDHM context
inputinput buffer
ilensize of buffer
Returns
0 if successful, or an MBEDTLS_ERR_DHM_XXX error code
Here is the call graph for this function:
Here is the caller graph for this function:

◆ mbedtls_dhm_self_test()

int mbedtls_dhm_self_test ( int  verbose)

Checkup routine.

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

Variable Documentation

◆ mbedtls_test_dhm_params

const char mbedtls_test_dhm_params[]
static
Initial value:
=
"-----BEGIN DH PARAMETERS-----\r\n"
"MIGHAoGBAJ419DBEOgmQTzo5qXl5fQcN9TN455wkOL7052HzxxRVMyhYmwQcgJvh\r\n"
"1sa18fyfR9OiVEMYglOpkqVoGLN7qd5aQNNi5W7/C+VBdHTBJcGZJyyP5B3qcz32\r\n"
"9mLJKudlVudV0Qxk5qUJaPZ/xupz0NyoVpviuiBOI1gNi8ovSXWzAgEC\r\n"
"-----END DH PARAMETERS-----\r\n"

◆ mbedtls_test_dhm_params_len

const size_t mbedtls_test_dhm_params_len = sizeof( mbedtls_test_dhm_params )
static