mirror of
				https://github.com/cuberite/polarssl.git
				synced 2025-11-03 20:22:59 -05:00 
			
		
		
		
	Fix CTR_DRBG benchmark
You can't reuse a CTR_DRBG context without free()ing it and re-init()ing. This generally happened to work, but was never guaranteed. It could have failed with alternative implementations of the AES module because mbedtls_ctr_drbg_seed() calls mbedtls_aes_init() on a context which is already initialized if mbedtls_ctr_drbg_seed() hasn't been called before, plausibly causing a memory leak. Calling free() and seed() with no intervening init fails when MBEDTLS_THREADING_C is enabled and all-bits-zero is not a valid mutex representation. So add the missing free() and init().
This commit is contained in:
		
							parent
							
								
									69971662bf
								
							
						
					
					
						commit
						f0ebbfb3fc
					
				@ -686,12 +686,13 @@ int main( int argc, char *argv[] )
 | 
			
		||||
        mbedtls_ctr_drbg_context ctr_drbg;
 | 
			
		||||
 | 
			
		||||
        mbedtls_ctr_drbg_init( &ctr_drbg );
 | 
			
		||||
 | 
			
		||||
        if( mbedtls_ctr_drbg_seed( &ctr_drbg, myrand, NULL, NULL, 0 ) != 0 )
 | 
			
		||||
            mbedtls_exit(1);
 | 
			
		||||
        TIME_AND_TSC( "CTR_DRBG (NOPR)",
 | 
			
		||||
                mbedtls_ctr_drbg_random( &ctr_drbg, buf, BUFSIZE ) );
 | 
			
		||||
        mbedtls_ctr_drbg_free( &ctr_drbg );
 | 
			
		||||
 | 
			
		||||
        mbedtls_ctr_drbg_init( &ctr_drbg );
 | 
			
		||||
        if( mbedtls_ctr_drbg_seed( &ctr_drbg, myrand, NULL, NULL, 0 ) != 0 )
 | 
			
		||||
            mbedtls_exit(1);
 | 
			
		||||
        mbedtls_ctr_drbg_set_prediction_resistance( &ctr_drbg, MBEDTLS_CTR_DRBG_PR_ON );
 | 
			
		||||
 | 
			
		||||
		Loading…
	
	
			
			x
			
			
		
	
		Reference in New Issue
	
	Block a user