Browse Source

[rng] Add ANS X9.82 mandatory start-up tests

ANS X9.82 specifies that the start-up tests shall consist of at least
one full cycle of the continuous tests.

Signed-off-by: Michael Brown <mcb30@ipxe.org>
tags/v1.20.1
Michael Brown 12 years ago
parent
commit
c6b0b3424b
1 changed files with 32 additions and 0 deletions
  1. 32
    0
      src/crypto/entropy.c

+ 32
- 0
src/crypto/entropy.c View File

@@ -351,6 +351,31 @@ static int get_entropy ( entropy_sample_t *entropy ) {
351 351
 	return 0;
352 352
 }
353 353
 
354
+/**
355
+ * Calculate number of samples required for startup tests
356
+ *
357
+ * @ret num_samples	Number of samples required
358
+ *
359
+ * ANS X9.82 Part 2 (October 2011 Draft) Section 8.5.2.1.5 requires
360
+ * that at least one full cycle of the continuous tests must be
361
+ * performed at start-up.
362
+ */
363
+static inline __attribute__ (( always_inline )) unsigned int
364
+startup_test_count ( void ) {
365
+	unsigned int num_samples;
366
+
367
+	/* At least max(N,C) samples shall be generated by the noise
368
+	 * source for start-up testing.
369
+	 */
370
+	num_samples = repetition_count_cutoff();
371
+	if ( num_samples < adaptive_proportion_cutoff() )
372
+		num_samples = adaptive_proportion_cutoff();
373
+	linker_assert ( __builtin_constant_p ( num_samples ),
374
+			startup_test_count_not_constant );
375
+
376
+	return num_samples;
377
+}
378
+
354 379
 /**
355 380
  * Create next nonce value
356 381
  *
@@ -387,6 +412,7 @@ static uint32_t make_next_nonce ( void ) {
387 412
  */
388 413
 int get_entropy_input_tmp ( unsigned int num_samples, uint8_t *tmp,
389 414
 			    size_t tmp_len ) {
415
+	static unsigned int startup_tested = 0;
390 416
 	struct {
391 417
 		uint32_t nonce;
392 418
 		entropy_sample_t sample;
@@ -398,6 +424,12 @@ int get_entropy_input_tmp ( unsigned int num_samples, uint8_t *tmp,
398 424
 	/* Enable entropy gathering */
399 425
 	entropy_enable();
400 426
 
427
+	/* Perform mandatory startup tests, if not yet performed */
428
+	for ( ; startup_tested < startup_test_count() ; startup_tested++ ) {
429
+		if ( ( rc = get_entropy ( &data.sample ) ) != 0 )
430
+			goto err_get_entropy;
431
+	}
432
+
401 433
 	/* 3.  entropy_total = 0
402 434
 	 *
403 435
 	 * (Nothing to do; the number of entropy samples required has

Loading…
Cancel
Save