host/prandom.c
/** Initialize the persistent entropy pool to a specified state. If the
  * current entropy pool is uncorrupted, then its state will be mixed in with
  * the specified state.
  * \param initial_pool_state The initial entropy pool state. This must be a
  *                           byte array of length #ENTROPY_POOL_LENGTH bytes.
  * \return false on success, true if an error (couldn't write to
  *         non-volatile memory) occurred.
  */
Initialize the persistent entropy pool to a specified state. If the
current entropy pool is uncorrupted, then its state will be mixed in with
the specified state.
\param initial_pool_state The initial entropy pool state. This must be a
byte array of length #ENTROPY_POOL_LENGTH bytes.
\return false on success, true if an error (couldn't write to
non-volatile memory) occurred.
Initialize the persistent entropy pool to a specified state . If the current entropy pool is uncorrupted then its state will be mixed in with the specified state . \ param initial_pool_state The initial entropy pool state . This must be a byte array of length #ENTROPY_POOL_LENGTH bytes . \ return false on success true if an error ( couldn ' t write to non - volatile memory ) occurred .
bool initialiseEntropyPool(uint8_t *initial_pool_state)
{
    uint32_t hs[8];
    uint8_t current_pool_state[ENTROPY_POOL_LENGTH];
    uint8_t i;
    uint8_t j;
    uint8_t new_pool_data[2*ENTROPY_POOL_LENGTH];
    if (getEntropyPool(current_pool_state))
    {
        return setEntropyPool(initial_pool_state);
    }
    else
    {
        sha256BeginTZ(1);
        for (i = 0, j = 0; i < ENTROPY_POOL_LENGTH; i++)
        {
            new_pool_data[j++] = current_pool_state[i];
            new_pool_data[j++] = initial_pool_state[i];
        }
        sha256WriteTZ(new_pool_data, (uint32_t)(2*ENTROPY_POOL_LENGTH), 1);
        sha256FinishTZ(hs, (uint32_t)32, 1);
        writeHashToByteArrayTZ(current_pool_state, hs, true);
        return setEntropyPool(current_pool_state);
    }
}
bool initialiseEntropyPool ( uint8_t * initial_pool_state ) { uint32_t hs [ 8 ] ; uint8_t current_pool_state [ ENTROPY_POOL_LENGTH ] ; uint8_t i ; uint8_t j ; uint8_t new_pool_data [ 2 * ENTROPY_POOL_LENGTH ] ; if ( getEntropyPool ( current_pool_state ) ) { return setEntropyPool ( initial_pool_state ) ; } else { sha256BeginTZ ( 1 ) ; for ( i = 0 , j = 0 ; i < ENTROPY_POOL_LENGTH ; i ++ ) { new_pool_data [ j ++ ] = current_pool_state [ i ] ; new_pool_data [ j ++ ] = initial_pool_state [ i ] ; } sha256WriteTZ ( new_pool_data , ( uint32_t ) ( 2 * ENTROPY_POOL_LENGTH ) , 1 ) ; sha256FinishTZ ( hs , ( uint32_t ) 32 , 1 ) ; writeHashToByteArrayTZ ( current_pool_state , hs , true ) ; return setEntropyPool ( current_pool_state ) ; } }
Initialize the persistent entropy pool to a specified state.
Initialize the persistent entropy pool to a specified state .
/* Current pool is not valid; Overwrite it. */