]> git.ipfire.org Git - thirdparty/ipxe.git/commitdiff
[rng] Add ANS X9.82 mandatory start-up tests
authorMichael Brown <mcb30@ipxe.org>
Mon, 20 Feb 2012 19:26:04 +0000 (19:26 +0000)
committerMichael Brown <mcb30@ipxe.org>
Tue, 21 Feb 2012 12:42:45 +0000 (12:42 +0000)
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>
src/crypto/entropy.c

index 47848368d2e314508c60ef05f2acb20dc67749b0..ab574a94c0cde8cc29632282f073a7b53d640a82 100644 (file)
@@ -351,6 +351,31 @@ static int get_entropy ( entropy_sample_t *entropy ) {
        return 0;
 }
 
+/**
+ * Calculate number of samples required for startup tests
+ *
+ * @ret num_samples    Number of samples required
+ *
+ * ANS X9.82 Part 2 (October 2011 Draft) Section 8.5.2.1.5 requires
+ * that at least one full cycle of the continuous tests must be
+ * performed at start-up.
+ */
+static inline __attribute__ (( always_inline )) unsigned int
+startup_test_count ( void ) {
+       unsigned int num_samples;
+
+       /* At least max(N,C) samples shall be generated by the noise
+        * source for start-up testing.
+        */
+       num_samples = repetition_count_cutoff();
+       if ( num_samples < adaptive_proportion_cutoff() )
+               num_samples = adaptive_proportion_cutoff();
+       linker_assert ( __builtin_constant_p ( num_samples ),
+                       startup_test_count_not_constant );
+
+       return num_samples;
+}
+
 /**
  * Create next nonce value
  *
@@ -387,6 +412,7 @@ static uint32_t make_next_nonce ( void ) {
  */
 int get_entropy_input_tmp ( unsigned int num_samples, uint8_t *tmp,
                            size_t tmp_len ) {
+       static unsigned int startup_tested = 0;
        struct {
                uint32_t nonce;
                entropy_sample_t sample;
@@ -398,6 +424,12 @@ int get_entropy_input_tmp ( unsigned int num_samples, uint8_t *tmp,
        /* Enable entropy gathering */
        entropy_enable();
 
+       /* Perform mandatory startup tests, if not yet performed */
+       for ( ; startup_tested < startup_test_count() ; startup_tested++ ) {
+               if ( ( rc = get_entropy ( &data.sample ) ) != 0 )
+                       goto err_get_entropy;
+       }
+
        /* 3.  entropy_total = 0
         *
         * (Nothing to do; the number of entropy samples required has