Commit ff7fe670 authored by Paul Bakker's avatar Paul Bakker
Browse files

- Minor DHM code cleanup/comments

parent f55ec08b
...@@ -64,7 +64,7 @@ int dhm_read_params( dhm_context *ctx, ...@@ -64,7 +64,7 @@ int dhm_read_params( dhm_context *ctx,
* \brief Setup and write the ServerKeyExchange parameters * \brief Setup and write the ServerKeyExchange parameters
* *
* \param ctx DHM context * \param ctx DHM context
* \param x_size private value size in bits * \param x_size private value size in bytes
* \param output destination buffer * \param output destination buffer
* \param olen number of chars written * \param olen number of chars written
* \param f_rng RNG function * \param f_rng RNG function
......
...@@ -99,20 +99,22 @@ int dhm_make_params( dhm_context *ctx, int x_size, ...@@ -99,20 +99,22 @@ int dhm_make_params( dhm_context *ctx, int x_size,
unsigned char *p; unsigned char *p;
/* /*
* generate X and calculate GX = G^X mod P * Generate X as large as possible ( < P )
*/ */
n = x_size / sizeof( t_int ); n = x_size / sizeof( t_int );
MPI_CHK( mpi_grow( &ctx->X, n ) ); MPI_CHK( mpi_grow( &ctx->X, n ) );
MPI_CHK( mpi_lset( &ctx->X, 0 ) ); MPI_CHK( mpi_lset( &ctx->X, 0 ) );
n = x_size - 1;
p = (unsigned char *) ctx->X.p; p = (unsigned char *) ctx->X.p;
for( i = 0; i < n; i++ ) for( i = 0; i < x_size - 1; i++ )
*p++ = (unsigned char) f_rng( p_rng ); *p++ = (unsigned char) f_rng( p_rng );
while( mpi_cmp_mpi( &ctx->X, &ctx->P ) >= 0 ) while( mpi_cmp_mpi( &ctx->X, &ctx->P ) >= 0 )
mpi_shift_r( &ctx->X, 1 ); mpi_shift_r( &ctx->X, 1 );
/*
* Calculate GX = G^X mod P
*/
MPI_CHK( mpi_exp_mod( &ctx->GX, &ctx->G, &ctx->X, MPI_CHK( mpi_exp_mod( &ctx->GX, &ctx->G, &ctx->X,
&ctx->P , &ctx->RP ) ); &ctx->P , &ctx->RP ) );
......
Markdown is supported
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment