|  | @@ -52,6 +52,25 @@ typedef uint8_t noise_sample_t;
 | 
		
	
		
			
			| 52 | 52 |  /** An entropy sample */
 | 
		
	
		
			
			| 53 | 53 |  typedef uint8_t entropy_sample_t;
 | 
		
	
		
			
			| 54 | 54 |  
 | 
		
	
		
			
			|  | 55 | +/** An amount of min-entropy
 | 
		
	
		
			
			|  | 56 | + *
 | 
		
	
		
			
			|  | 57 | + * Expressed as a fixed-point quantity in order to avoid floating
 | 
		
	
		
			
			|  | 58 | + * point calculations.
 | 
		
	
		
			
			|  | 59 | + */
 | 
		
	
		
			
			|  | 60 | +typedef unsigned int min_entropy_t;
 | 
		
	
		
			
			|  | 61 | +
 | 
		
	
		
			
			|  | 62 | +/** Fixed-point scale for min-entropy amounts */
 | 
		
	
		
			
			|  | 63 | +#define MIN_ENTROPY_SCALE ( 1 << 16 )
 | 
		
	
		
			
			|  | 64 | +
 | 
		
	
		
			
			|  | 65 | +/**
 | 
		
	
		
			
			|  | 66 | + * Construct a min-entropy fixed-point value
 | 
		
	
		
			
			|  | 67 | + *
 | 
		
	
		
			
			|  | 68 | + * @v bits		min-entropy in bits
 | 
		
	
		
			
			|  | 69 | + * @ret min_entropy	min-entropy as a fixed-point value
 | 
		
	
		
			
			|  | 70 | + */
 | 
		
	
		
			
			|  | 71 | +#define MIN_ENTROPY( bits ) \
 | 
		
	
		
			
			|  | 72 | +	( ( min_entropy_t ) ( (bits) * MIN_ENTROPY_SCALE ) )
 | 
		
	
		
			
			|  | 73 | +
 | 
		
	
		
			
			| 55 | 74 |  /* Include all architecture-independent entropy API headers */
 | 
		
	
		
			
			| 56 | 75 |  #include <ipxe/null_entropy.h>
 | 
		
	
		
			
			| 57 | 76 |  #include <ipxe/efi/efi_entropy.h>
 | 
		
	
	
		
			
			|  | @@ -87,7 +106,7 @@ void entropy_disable ( void );
 | 
		
	
		
			
			| 87 | 106 |   *
 | 
		
	
		
			
			| 88 | 107 |   * This must be a compile-time constant.
 | 
		
	
		
			
			| 89 | 108 |   */
 | 
		
	
		
			
			| 90 |  | -double min_entropy_per_sample ( void );
 | 
		
	
		
			
			|  | 109 | +min_entropy_t min_entropy_per_sample ( void );
 | 
		
	
		
			
			| 91 | 110 |  
 | 
		
	
		
			
			| 92 | 111 |  /**
 | 
		
	
		
			
			| 93 | 112 |   * Get noise sample
 | 
		
	
	
		
			
			|  | @@ -142,7 +161,7 @@ get_entropy_input ( unsigned int min_entropy_bits, void *data, size_t min_len,
 | 
		
	
		
			
			| 142 | 161 |  
 | 
		
	
		
			
			| 143 | 162 |  	/* Sanity checks */
 | 
		
	
		
			
			| 144 | 163 |  	linker_assert ( ( min_entropy_per_sample() <=
 | 
		
	
		
			
			| 145 |  | -			  ( 8 * sizeof ( noise_sample_t ) ) ),
 | 
		
	
		
			
			|  | 164 | +			  MIN_ENTROPY ( 8 * sizeof ( noise_sample_t ) ) ),
 | 
		
	
		
			
			| 146 | 165 |  			min_entropy_per_sample_is_impossibly_high );
 | 
		
	
		
			
			| 147 | 166 |  	linker_assert ( ( min_entropy_bits <= ( 8 * max_len ) ),
 | 
		
	
		
			
			| 148 | 167 |  			entropy_buffer_too_small );
 | 
		
	
	
		
			
			|  | @@ -151,7 +170,8 @@ get_entropy_input ( unsigned int min_entropy_bits, void *data, size_t min_len,
 | 
		
	
		
			
			| 151 | 170 |  	min_entropy_bits = ( ( min_entropy_bits + 7 ) & ~7 );
 | 
		
	
		
			
			| 152 | 171 |  
 | 
		
	
		
			
			| 153 | 172 |  	/* Calculate number of samples required to contain sufficient entropy */
 | 
		
	
		
			
			| 154 |  | -	min_samples = ( ( min_entropy_bits * 1.0 ) / min_entropy_per_sample() );
 | 
		
	
		
			
			|  | 173 | +	min_samples = ( MIN_ENTROPY ( min_entropy_bits ) /
 | 
		
	
		
			
			|  | 174 | +			min_entropy_per_sample() );
 | 
		
	
		
			
			| 155 | 175 |  
 | 
		
	
		
			
			| 156 | 176 |  	/* Round up to a whole number of samples.  We don't have the
 | 
		
	
		
			
			| 157 | 177 |  	 * ceil() function available, so do the rounding by hand.
 |