#include "polarssl/config.h"
#include "polarssl/dhm.h"
#include "polarssl/pem.h"
#include "polarssl/asn1.h"
#include <stdlib.h>
#include "polarssl/certs.h"
Go to the source code of this file.
Defines | |
#define | polarssl_malloc malloc |
#define | polarssl_free free |
#define | DHM_MPI_EXPORT(X, n) |
Functions | |
static int | dhm_read_bignum (mpi *X, unsigned char **p, const unsigned char *end) |
static int | dhm_check_range (const mpi *param, const mpi *P) |
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. | |
static int | dhm_update_blinding (dhm_context *ctx, int(*f_rng)(void *, unsigned char *, size_t), void *p_rng) |
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 the components of a DHM key. | |
int | dhm_parse_dhm (dhm_context *dhm, const unsigned char *dhmin, size_t dhminlen) |
Parse DHM parameters. | |
static int | load_file (const char *path, unsigned char **buf, size_t *n) |
int | dhm_parse_dhmfile (dhm_context *dhm, const char *path) |
Load and parse DHM parameters. | |
int | dhm_self_test (int verbose) |
Checkup routine. |
#define DHM_MPI_EXPORT | ( | X, | |||
n | ) |
MPI_CHK( mpi_write_binary( X, p + 2, n ) ); \ *p++ = (unsigned char)( n >> 8 ); \ *p++ = (unsigned char)( n ); p += n;
Referenced by dhm_make_params().
#define polarssl_free free |
#define polarssl_malloc malloc |
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.
ctx | DHM context | |
output | destination buffer | |
olen | number of chars written | |
f_rng | RNG function, for blinding purposes | |
p_rng | RNG parameter |
Definition at line 332 of file dhm.c.
References dhm_check_range(), dhm_update_blinding(), dhm_context::GY, dhm_context::K, MPI_CHK, mpi_copy(), mpi_exp_mod(), mpi_free(), mpi_init(), mpi_mod_mpi(), mpi_mul_mpi(), mpi_size(), mpi_write_binary(), dhm_context::P, POLARSSL_ERR_DHM_BAD_INPUT_DATA, POLARSSL_ERR_DHM_CALC_SECRET_FAILED, dhm_context::RP, dhm_context::Vf, dhm_context::Vi, and dhm_context::X.
Referenced by ssl_parse_client_key_exchange(), ssl_psk_derive_premaster(), ssl_write_client_key_exchange(), and test_suite_dhm_do_dhm().
Definition at line 88 of file dhm.c.
References mpi_cmp_mpi(), mpi_free(), mpi_init(), mpi_lset(), mpi_sub_int(), and POLARSSL_ERR_DHM_BAD_INPUT_DATA.
Referenced by dhm_calc_secret(), dhm_make_params(), dhm_make_public(), and dhm_read_params().
void dhm_free | ( | dhm_context * | ctx | ) |
Free the components of a DHM key.
Definition at line 385 of file dhm.c.
References dhm_context::G, dhm_context::GX, dhm_context::GY, dhm_context::K, mpi_free(), dhm_context::P, dhm_context::pX, dhm_context::RP, dhm_context::Vf, dhm_context::Vi, and dhm_context::X.
Referenced by dhm_parse_dhm(), dhm_read_params(), dhm_self_test(), ssl_handshake_free(), and test_suite_dhm_do_dhm().
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.
ctx | DHM context | |
x_size | private value size in bytes | |
output | destination buffer | |
olen | number of chars written | |
f_rng | RNG function | |
p_rng | RNG parameter |
Definition at line 135 of file dhm.c.
References dhm_check_range(), DHM_MPI_EXPORT, dhm_context::G, dhm_context::GX, dhm_context::len, MPI_CHK, mpi_cmp_int(), mpi_cmp_mpi(), mpi_exp_mod(), mpi_fill_random(), mpi_shift_r(), mpi_size(), dhm_context::P, POLARSSL_ERR_DHM_BAD_INPUT_DATA, POLARSSL_ERR_DHM_MAKE_PARAMS_FAILED, dhm_context::RP, and dhm_context::X.
Referenced by ssl_write_server_key_exchange(), and test_suite_dhm_do_dhm().
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.
ctx | DHM context | |
x_size | private value size in bytes | |
output | destination buffer | |
olen | must be equal to ctx->P.len | |
f_rng | RNG function | |
p_rng | RNG parameter |
Definition at line 220 of file dhm.c.
References dhm_check_range(), dhm_context::G, dhm_context::GX, dhm_context::len, MPI_CHK, mpi_cmp_int(), mpi_cmp_mpi(), mpi_exp_mod(), mpi_fill_random(), mpi_shift_r(), mpi_write_binary(), dhm_context::P, POLARSSL_ERR_DHM_BAD_INPUT_DATA, POLARSSL_ERR_DHM_MAKE_PUBLIC_FAILED, dhm_context::RP, and dhm_context::X.
Referenced by ssl_write_client_key_exchange(), and test_suite_dhm_do_dhm().
static int dhm_read_bignum | ( | mpi * | X, | |
unsigned char ** | p, | |||
const unsigned char * | end | |||
) | [static] |
Definition at line 56 of file dhm.c.
References mpi_read_binary(), POLARSSL_ERR_DHM_BAD_INPUT_DATA, and POLARSSL_ERR_DHM_READ_PARAMS_FAILED.
Referenced by dhm_read_params().
int dhm_read_params | ( | dhm_context * | ctx, | |
unsigned char ** | p, | |||
const unsigned char * | end | |||
) |
Parse the ServerKeyExchange parameters.
ctx | DHM context | |
p | &(start of input buffer) | |
end | end of buffer |
Definition at line 111 of file dhm.c.
References dhm_check_range(), dhm_free(), dhm_read_bignum(), dhm_context::G, dhm_context::GY, dhm_context::len, mpi_size(), and dhm_context::P.
Referenced by ssl_parse_server_dh_params(), and test_suite_dhm_do_dhm().
int dhm_read_public | ( | dhm_context * | ctx, | |
const unsigned char * | input, | |||
size_t | ilen | |||
) |
Import the peer's public value G^Y.
ctx | DHM context | |
input | input buffer | |
ilen | size of buffer |
Definition at line 203 of file dhm.c.
References dhm_context::GY, dhm_context::len, mpi_read_binary(), POLARSSL_ERR_DHM_BAD_INPUT_DATA, and POLARSSL_ERR_DHM_READ_PUBLIC_FAILED.
Referenced by ssl_parse_client_dh_public(), and test_suite_dhm_do_dhm().
int dhm_self_test | ( | int | verbose | ) |
Checkup routine.
Definition at line 544 of file dhm.c.
References dhm_free(), dhm_parse_dhm(), POLARSSL_ERR_X509_FEATURE_UNAVAILABLE, and test_dhm_params.
Referenced by test_suite_dhm_selftest().
static int dhm_update_blinding | ( | dhm_context * | ctx, | |
int(*)(void *, unsigned char *, size_t) | f_rng, | |||
void * | p_rng | |||
) | [static] |
Definition at line 270 of file dhm.c.
References MPI_CHK, mpi_cmp_int(), mpi_cmp_mpi(), mpi_copy(), mpi_exp_mod(), mpi_fill_random(), mpi_inv_mod(), mpi_lset(), mpi_mod_mpi(), mpi_mul_mpi(), mpi_shift_r(), mpi_size(), dhm_context::P, POLARSSL_ERR_MPI_NOT_ACCEPTABLE, dhm_context::pX, dhm_context::RP, dhm_context::Vf, dhm_context::Vi, and dhm_context::X.
Referenced by dhm_calc_secret().
static int load_file | ( | const char * | path, | |
unsigned char ** | buf, | |||
size_t * | n | |||
) | [static] |
Definition at line 476 of file dhm.c.
References POLARSSL_ERR_DHM_FILE_IO_ERROR, POLARSSL_ERR_DHM_MALLOC_FAILED, polarssl_free, and polarssl_malloc.
Referenced by dhm_parse_dhmfile().