- Minor DHM code cleanup/comments
diff --git a/include/polarssl/dhm.h b/include/polarssl/dhm.h
index f63eefd..e80c45e 100644
--- a/include/polarssl/dhm.h
+++ b/include/polarssl/dhm.h
@@ -64,7 +64,7 @@
* \brief Setup and write the ServerKeyExchange parameters
*
* \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 olen number of chars written
* \param f_rng RNG function
diff --git a/library/dhm.c b/library/dhm.c
index 1f17909..904b592 100644
--- a/library/dhm.c
+++ b/library/dhm.c
@@ -99,20 +99,22 @@
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 );
MPI_CHK( mpi_grow( &ctx->X, n ) );
MPI_CHK( mpi_lset( &ctx->X, 0 ) );
- n = x_size - 1;
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 );
while( mpi_cmp_mpi( &ctx->X, &ctx->P ) >= 0 )
mpi_shift_r( &ctx->X, 1 );
+ /*
+ * Calculate GX = G^X mod P
+ */
MPI_CHK( mpi_exp_mod( &ctx->GX, &ctx->G, &ctx->X,
&ctx->P , &ctx->RP ) );