xref: /aosp_15_r20/external/cronet/net/third_party/quiche/src/quiche/common/quiche_random.h (revision 6777b5387eb2ff775bb5750e3f5d96f37fb7352b)
1 #ifndef QUICHE_COMMON_QUICHE_RANDOM_H_
2 #define QUICHE_COMMON_QUICHE_RANDOM_H_
3 
4 #include <cstddef>
5 #include <cstdint>
6 
7 #include "quiche/common/platform/api/quiche_export.h"
8 
9 namespace quiche {
10 
11 // The interface for a random number generator.
12 class QUICHE_EXPORT QuicheRandom {
13  public:
~QuicheRandom()14   virtual ~QuicheRandom() {}
15 
16   // Returns the default random number generator, which is cryptographically
17   // secure and thread-safe.
18   static QuicheRandom* GetInstance();
19 
20   // Generates |len| random bytes in the |data| buffer.
21   virtual void RandBytes(void* data, size_t len) = 0;
22 
23   // Returns a random number in the range [0, kuint64max].
24   virtual uint64_t RandUint64() = 0;
25 
26   // Generates |len| random bytes in the |data| buffer. This MUST NOT be used
27   // for any application that requires cryptographically-secure randomness.
28   virtual void InsecureRandBytes(void* data, size_t len) = 0;
29 
30   // Returns a random number in the range [0, kuint64max]. This MUST NOT be used
31   // for any application that requires cryptographically-secure randomness.
32   virtual uint64_t InsecureRandUint64() = 0;
33 };
34 
35 }  // namespace quiche
36 
37 #endif  // QUICHE_COMMON_QUICHE_RANDOM_H_
38