mbed TLS library

Dependents:   HTTPClient-SSL WS_SERVER

Embed: (wiki syntax)

« Back to documentation index

dhm.h File Reference

dhm.h File Reference

Diffie-Hellman-Merkle key exchange. More...

Go to the source code of this file.

Data Structures

struct  dhm_context
 DHM context structure. More...

Functions

void dhm_init (dhm_context *ctx)
 Initialize DHM context.
int dhm_read_params (dhm_context *ctx, unsigned char **p, const unsigned char *end)
 Parse the ServerKeyExchange parameters.
int dhm_make_params (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.
int dhm_read_public (dhm_context *ctx, const unsigned char *input, size_t ilen)
 Import the peer's public value G^Y.
int dhm_make_public (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.
int dhm_calc_secret (dhm_context *ctx, unsigned char *output, 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.
void dhm_free (dhm_context *ctx)
 Free and clear the components of a DHM key.
int dhm_parse_dhm (dhm_context *dhm, const unsigned char *dhmin, size_t dhminlen)
 Parse DHM parameters.
int dhm_parse_dhmfile (dhm_context *dhm, const char *path)
 Load and parse DHM parameters.
int dhm_self_test (int verbose)
 Checkup routine.

Detailed Description

Diffie-Hellman-Merkle key exchange.

Copyright (C) 2006-2013, ARM Limited, All Rights Reserved

This file is part of mbed TLS (https://tls.mbed.org)

This program is free software; you can redistribute it and/or modify it under the terms of the GNU General Public License as published by the Free Software Foundation; either version 2 of the License, or (at your option) any later version.

This program is distributed in the hope that it will be useful, but WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License for more details.

You should have received a copy of the GNU General Public License along with this program; if not, write to the Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA.

Definition in file dhm.h.


Function Documentation

int dhm_calc_secret ( dhm_context ctx,
unsigned char *  output,
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
olenon entry, must hold the size of the destination buffer on exit, holds the actual number of bytes written
f_rngRNG function, for blinding purposes
p_rngRNG parameter
Returns:
0 if successful, or an POLARSSL_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.

Definition at line 346 of file dhm.c.

void dhm_free ( dhm_context ctx )

Free and clear the components of a DHM key.

Parameters:
ctxDHM context to free and clear

Definition at line 399 of file dhm.c.

void dhm_init ( dhm_context ctx )

Initialize DHM context.

Parameters:
ctxDHM context to be initialized

Definition at line 119 of file dhm.c.

int dhm_make_params ( 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 mpi_read_string or mpi_read_binary).
Returns:
0 if successful, or an POLARSSL_ERR_DHM_XXX error code

Definition at line 149 of file dhm.c.

int dhm_make_public ( 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 equal to ctx->P.len
f_rngRNG function
p_rngRNG parameter
Returns:
0 if successful, or an POLARSSL_ERR_DHM_XXX error code

Definition at line 234 of file dhm.c.

int dhm_read_params ( 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 POLARSSL_ERR_DHM_XXX error code

Definition at line 127 of file dhm.c.

int dhm_read_public ( 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 POLARSSL_ERR_DHM_XXX error code

Definition at line 217 of file dhm.c.

int dhm_self_test ( int  verbose )

Checkup routine.

Returns:
0 if successful, or 1 if the test failed

Definition at line 575 of file dhm.c.