QUICHE team | a6ef0a6 | 2019-03-07 20:34:33 -0500 | [diff] [blame] | 1 | // Copyright (c) 2012 The Chromium Authors. All rights reserved. |
| 2 | // Use of this source code is governed by a BSD-style license that can be |
| 3 | // found in the LICENSE file. |
| 4 | |
| 5 | #include "net/third_party/quiche/src/quic/core/crypto/quic_random.h" |
| 6 | |
QUICHE team | a6ef0a6 | 2019-03-07 20:34:33 -0500 | [diff] [blame] | 7 | #include "third_party/boringssl/src/include/openssl/rand.h" |
| 8 | #include "net/third_party/quiche/src/quic/platform/api/quic_bug_tracker.h" |
| 9 | |
| 10 | namespace quic { |
| 11 | |
| 12 | namespace { |
| 13 | |
| 14 | class DefaultRandom : public QuicRandom { |
| 15 | public: |
| 16 | DefaultRandom() {} |
| 17 | DefaultRandom(const DefaultRandom&) = delete; |
| 18 | DefaultRandom& operator=(const DefaultRandom&) = delete; |
| 19 | ~DefaultRandom() override {} |
| 20 | |
| 21 | // QuicRandom implementation |
| 22 | void RandBytes(void* data, size_t len) override; |
| 23 | uint64_t RandUint64() override; |
| 24 | }; |
| 25 | |
| 26 | void DefaultRandom::RandBytes(void* data, size_t len) { |
| 27 | RAND_bytes(reinterpret_cast<uint8_t*>(data), len); |
| 28 | } |
| 29 | |
| 30 | uint64_t DefaultRandom::RandUint64() { |
| 31 | uint64_t value; |
| 32 | RandBytes(&value, sizeof(value)); |
| 33 | return value; |
| 34 | } |
| 35 | |
| 36 | } // namespace |
| 37 | |
| 38 | // static |
| 39 | QuicRandom* QuicRandom::GetInstance() { |
| 40 | static DefaultRandom* random = new DefaultRandom(); |
| 41 | return random; |
| 42 | } |
| 43 | |
| 44 | } // namespace quic |