]> git.ipfire.org Git - thirdparty/ipxe.git/commitdiff
[rng] Record validity within DRBG state
authorMichael Brown <mcb30@ipxe.org>
Mon, 20 Feb 2012 21:24:30 +0000 (21:24 +0000)
committerMichael Brown <mcb30@ipxe.org>
Tue, 21 Feb 2012 12:42:37 +0000 (12:42 +0000)
Treat an empty (zeroed) DRBG as invalid.  This ensures that a DRBG
that has not yet been instantiated (or that has been uninstantiated)
will refuse to attempt to generate random bits.

Signed-off-by: Michael Brown <mcb30@ipxe.org>
src/crypto/drbg.c
src/include/ipxe/drbg.h

index 58e8fa7b52a6820d93ddb9a51f1b008f44c1beeb..88cf3acde657dd32611074cdf45a2088ede7205a 100644 (file)
@@ -151,6 +151,7 @@ int drbg_instantiate ( struct drbg_state *state, const void *personal,
         * in-situ.)
         */
        state->reseed_required = 0;
+       state->valid = 1;
 
        /* 12.  Return SUCCESS and state_handle. */
        return 0;
@@ -187,9 +188,13 @@ int drbg_reseed ( struct drbg_state *state, const void *additional,
         *     If state_handle indicates an invalid or empty internal
         *     state, return an ERROR_FLAG.
         *
-        * (Nothing to do since the memory holding the internal state
-        * was passed in by the caller.)
+        * (Almost nothing to do since the memory holding the internal
+        * state was passed in by the caller.)
         */
+       if ( ! state->valid ) {
+               DBGC ( state, "DRBG %p not valid\n", state );
+               return -EINVAL;
+       }
 
        /* 2.  If prediction_resistance_request is set, and
         *     prediction_resistance_flag is not set, then return an
@@ -273,9 +278,13 @@ int drbg_generate ( struct drbg_state *state, const void *additional,
         *     for the instantiation.  If state_handle indicates an
         *     invalid or empty internal state, then return an ERROR_FLAG.
         *
-        * (Nothing to do since the memory holding the internal state
-        * was passed in by the caller.)
+        * (Almost nothing to do since the memory holding the internal
+        * state was passed in by the caller.)
         */
+       if ( ! state->valid ) {
+               DBGC ( state, "DRBG %p not valid\n", state );
+               return -EINVAL;
+       }
 
        /* 2.  If requested_number_of_bits >
         *     max_number_of_bits_per_request, then return an
index a09d136dd931296fd59d3d1b53b23f5decdef9d1..3cf4584acb137b75ac18883e90ab063bd455c7f5 100644 (file)
@@ -39,6 +39,8 @@ struct drbg_state {
        struct hmac_drbg_state internal;
        /** Reseed required flag */
        int reseed_required;
+       /** State is valid */
+       int valid;
 };
 
 /**