mirror of
				https://github.com/cuberite/polarssl.git
				synced 2025-10-30 19:20:40 -04:00 
			
		
		
		
	Make RNG parameters mandatory in DHM functions
Signed-off-by: Manuel Pégourié-Gonnard <manuel.pegourie-gonnard@arm.com>
This commit is contained in:
		
							parent
							
								
									f035904060
								
							
						
					
					
						commit
						1a87722bb6
					
				| @ -279,10 +279,10 @@ int mbedtls_dhm_make_public( mbedtls_dhm_context *ctx, int x_size, | |||||||
|  * \param output_size   The size of the destination buffer. This must be at |  * \param output_size   The size of the destination buffer. This must be at | ||||||
|  *                      least the size of \c ctx->len (the size of \c P). |  *                      least the size of \c ctx->len (the size of \c P). | ||||||
|  * \param olen          On exit, holds the actual number of Bytes written. |  * \param olen          On exit, holds the actual number of Bytes written. | ||||||
|  * \param f_rng         The RNG function, for blinding purposes. This may |  * \param f_rng         The RNG function. Must not be \c NULL. Used for | ||||||
|  *                      b \c NULL if blinding isn't needed. |  *                      blinding. | ||||||
|  * \param p_rng         The RNG context. This may be \c NULL if \p f_rng |  * \param p_rng         The RNG context to be passed to \p f_rng. This may be | ||||||
|  *                      doesn't need a context argument. |  *                      \c NULL if \p f_rng doesn't need a context parameter. | ||||||
|  * |  * | ||||||
|  * \return              \c 0 on success. |  * \return              \c 0 on success. | ||||||
|  * \return              An \c MBEDTLS_ERR_DHM_XXX error code on failure. |  * \return              An \c MBEDTLS_ERR_DHM_XXX error code on failure. | ||||||
|  | |||||||
| @ -444,6 +444,9 @@ int mbedtls_dhm_calc_secret( mbedtls_dhm_context *ctx, | |||||||
|     DHM_VALIDATE_RET( output != NULL ); |     DHM_VALIDATE_RET( output != NULL ); | ||||||
|     DHM_VALIDATE_RET( olen != NULL ); |     DHM_VALIDATE_RET( olen != NULL ); | ||||||
| 
 | 
 | ||||||
|  |     if( f_rng == NULL ) | ||||||
|  |         return( MBEDTLS_ERR_DHM_BAD_INPUT_DATA ); | ||||||
|  | 
 | ||||||
|     if( output_size < mbedtls_dhm_get_len( ctx ) ) |     if( output_size < mbedtls_dhm_get_len( ctx ) ) | ||||||
|         return( MBEDTLS_ERR_DHM_BAD_INPUT_DATA ); |         return( MBEDTLS_ERR_DHM_BAD_INPUT_DATA ); | ||||||
| 
 | 
 | ||||||
| @ -453,25 +456,17 @@ int mbedtls_dhm_calc_secret( mbedtls_dhm_context *ctx, | |||||||
|     mbedtls_mpi_init( &GYb ); |     mbedtls_mpi_init( &GYb ); | ||||||
| 
 | 
 | ||||||
|     /* Blind peer's value */ |     /* Blind peer's value */ | ||||||
|     if( f_rng != NULL ) |  | ||||||
|     { |  | ||||||
|     MBEDTLS_MPI_CHK( dhm_update_blinding( ctx, f_rng, p_rng ) ); |     MBEDTLS_MPI_CHK( dhm_update_blinding( ctx, f_rng, p_rng ) ); | ||||||
|     MBEDTLS_MPI_CHK( mbedtls_mpi_mul_mpi( &GYb, &ctx->GY, &ctx->Vi ) ); |     MBEDTLS_MPI_CHK( mbedtls_mpi_mul_mpi( &GYb, &ctx->GY, &ctx->Vi ) ); | ||||||
|     MBEDTLS_MPI_CHK( mbedtls_mpi_mod_mpi( &GYb, &GYb, &ctx->P ) ); |     MBEDTLS_MPI_CHK( mbedtls_mpi_mod_mpi( &GYb, &GYb, &ctx->P ) ); | ||||||
|     } |  | ||||||
|     else |  | ||||||
|         MBEDTLS_MPI_CHK( mbedtls_mpi_copy( &GYb, &ctx->GY ) ); |  | ||||||
| 
 | 
 | ||||||
|     /* Do modular exponentiation */ |     /* Do modular exponentiation */ | ||||||
|     MBEDTLS_MPI_CHK( mbedtls_mpi_exp_mod( &ctx->K, &GYb, &ctx->X, |     MBEDTLS_MPI_CHK( mbedtls_mpi_exp_mod( &ctx->K, &GYb, &ctx->X, | ||||||
|                           &ctx->P, &ctx->RP ) ); |                           &ctx->P, &ctx->RP ) ); | ||||||
| 
 | 
 | ||||||
|     /* Unblind secret value */ |     /* Unblind secret value */ | ||||||
|     if( f_rng != NULL ) |  | ||||||
|     { |  | ||||||
|     MBEDTLS_MPI_CHK( mbedtls_mpi_mul_mpi( &ctx->K, &ctx->K, &ctx->Vf ) ); |     MBEDTLS_MPI_CHK( mbedtls_mpi_mul_mpi( &ctx->K, &ctx->K, &ctx->Vf ) ); | ||||||
|     MBEDTLS_MPI_CHK( mbedtls_mpi_mod_mpi( &ctx->K, &ctx->K, &ctx->P ) ); |     MBEDTLS_MPI_CHK( mbedtls_mpi_mod_mpi( &ctx->K, &ctx->K, &ctx->P ) ); | ||||||
|     } |  | ||||||
| 
 | 
 | ||||||
|     /* Output the secret without any leading zero byte. This is mandatory
 |     /* Output the secret without any leading zero byte. This is mandatory
 | ||||||
|      * for TLS per RFC 5246 §8.1.2. */ |      * for TLS per RFC 5246 §8.1.2. */ | ||||||
|  | |||||||
| @ -150,7 +150,10 @@ void dhm_do_dhm( int radix_P, char *input_P, int x_size, | |||||||
|                                           &sec_srv_len, |                                           &sec_srv_len, | ||||||
|                                           &mbedtls_test_rnd_pseudo_rand, |                                           &mbedtls_test_rnd_pseudo_rand, | ||||||
|                                           &rnd_info ) == 0 ); |                                           &rnd_info ) == 0 ); | ||||||
|     TEST_ASSERT( mbedtls_dhm_calc_secret( &ctx_cli, sec_cli, sizeof( sec_cli ), &sec_cli_len, NULL, NULL ) == 0 ); |     TEST_ASSERT( mbedtls_dhm_calc_secret( &ctx_cli, sec_cli, sizeof( sec_cli ), | ||||||
|  |                                           &sec_cli_len, | ||||||
|  |                                           &mbedtls_test_rnd_pseudo_rand, | ||||||
|  |                                           &rnd_info ) == 0 ); | ||||||
| 
 | 
 | ||||||
|     TEST_ASSERT( sec_srv_len == sec_cli_len ); |     TEST_ASSERT( sec_srv_len == sec_cli_len ); | ||||||
|     TEST_ASSERT( sec_srv_len != 0 ); |     TEST_ASSERT( sec_srv_len != 0 ); | ||||||
| @ -206,7 +209,10 @@ void dhm_do_dhm( int radix_P, char *input_P, int x_size, | |||||||
|                                           &sec_srv_len, |                                           &sec_srv_len, | ||||||
|                                           &mbedtls_test_rnd_pseudo_rand, |                                           &mbedtls_test_rnd_pseudo_rand, | ||||||
|                                           &rnd_info ) == 0 ); |                                           &rnd_info ) == 0 ); | ||||||
|     TEST_ASSERT( mbedtls_dhm_calc_secret( &ctx_cli, sec_cli, sizeof( sec_cli ), &sec_cli_len, NULL, NULL ) == 0 ); |     TEST_ASSERT( mbedtls_dhm_calc_secret( &ctx_cli, sec_cli, sizeof( sec_cli ), | ||||||
|  |                                           &sec_cli_len, | ||||||
|  |                                           &mbedtls_test_rnd_pseudo_rand, | ||||||
|  |                                           &rnd_info ) == 0 ); | ||||||
| 
 | 
 | ||||||
|     TEST_ASSERT( sec_srv_len == sec_cli_len ); |     TEST_ASSERT( sec_srv_len == sec_cli_len ); | ||||||
|     TEST_ASSERT( sec_srv_len != 0 ); |     TEST_ASSERT( sec_srv_len != 0 ); | ||||||
|  | |||||||
		Loading…
	
	
			
			x
			
			
		
	
		Reference in New Issue
	
	Block a user
	 Manuel Pégourié-Gonnard
						Manuel Pégourié-Gonnard