blob: 230264c00c2f80b0019941ca24dd837b73f44d95 [file] [log] [blame]
QUICHE teama6ef0a62019-03-07 20:34:33 -05001// 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 teama6ef0a62019-03-07 20:34:33 -05007#include "third_party/boringssl/src/include/openssl/rand.h"
8#include "net/third_party/quiche/src/quic/platform/api/quic_bug_tracker.h"
9
10namespace quic {
11
12namespace {
13
14class 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
26void DefaultRandom::RandBytes(void* data, size_t len) {
27 RAND_bytes(reinterpret_cast<uint8_t*>(data), len);
28}
29
30uint64_t DefaultRandom::RandUint64() {
31 uint64_t value;
32 RandBytes(&value, sizeof(value));
33 return value;
34}
35
36} // namespace
37
38// static
39QuicRandom* QuicRandom::GetInstance() {
40 static DefaultRandom* random = new DefaultRandom();
41 return random;
42}
43
44} // namespace quic