/*
* CPU Jitter Random Number Generator
* (C) 2024 Planck Security S.A.
*
* Botan is released under the Simplified BSD License (see license.txt)
*/

#ifndef BOTAN_JITTER_RNG_H_
#define BOTAN_JITTER_RNG_H_

#include <botan/rng.h>
#include <memory>
#include <string>

namespace Botan {

class Jitter_RNG_Internal;

/**
* RNG using libjitterentropy (https://github.com/smuellerDD/jitterentropy-library)
*/
class BOTAN_PUBLIC_API(3, 6) Jitter_RNG final : public RandomNumberGenerator {
   public:
      /**
      * Create a Jitter_RNG, throwing if libjitterentropy cannot be initialized
      */
      Jitter_RNG();
      ~Jitter_RNG() override;

      Jitter_RNG(const Jitter_RNG& other) = delete;
      /**
      * Move constructor
      */
      Jitter_RNG(Jitter_RNG&& other) = default;
      Jitter_RNG& operator=(const Jitter_RNG& other) = delete;
      Jitter_RNG& operator=(Jitter_RNG&& other) = delete;

      /**
      * Return the name of this RNG type
      * @return the name of this RNG type
      */
      std::string name() const override { return "JitterRNG"; }

      /**
      * Test whether this RNG has been seeded
      * @return true if this RNG is seeded and ready for use
      */
      bool is_seeded() const override { return true; }

      /**
      * Test whether this RNG accepts externally provided input
      * @return false if this RNG is known to ignore provided inputs
      */
      bool accepts_input() const override { return false; }

      /**
      * Clear all internally held values of this RNG
      */
      void clear() override;

   private:
      void fill_bytes_with_input(std::span<uint8_t> out, std::span<const uint8_t> in) override;

      std::unique_ptr<Jitter_RNG_Internal> m_jitter;
};

}  // namespace Botan

#endif
