#pragma once #include /// @brief The size of the internal buffer when generating entropy constexpr size_t randomNumberBatchSize = 32; /** * @brief A noise source for crypto operations specifically for the ESP32. * */ class ESP32NoiseSource: public NoiseSource { public: /** * \brief Constructs a new random noise source. */ ESP32NoiseSource(); /** * \brief Destroys this random noise source. */ ~ESP32NoiseSource() {} /** * @brief Determine if the noise source is still calibrating itself. * * Noise sources that require calibration start doing so at system startup * and then switch over to random data generation once calibration is complete. * Since no random data is being generated during calibration, the output * from `RNGClass::rand()` and `RNG.rand()` may be predictable. * Use `RNGClass::available()` or `RNG.available()` to determine * when sufficient entropy is available to generate good random values. * * It is possible that the noise source never exits calibration. This can * happen if the input voltage is insufficient to trigger noise or if the * noise source is not connected. Noise sources may also periodically * recalibrate themselves. * * @return Returns true if calibration is in progress; false if the noise * source is generating valid random data. * */ bool calibrating() const override; /** * @brief Stirs entropy from this noise source into the global random * number pool. * * This function should call `output()` to add the entropy from this noise * source to the global random number pool. * * The noise source should batch up the entropy data, providing between * 16 and 48 bytes of data each time. If the noise source does not have * sufficient entropy data at the moment, it should return without stiring * the current data in. */ void stir() override; private: /// @brief Temporary buffer to hold random bytes before handing them to the crypto module uint8_t data[randomNumberBatchSize]; };