OLD | NEW |
| (Empty) |
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/quic/crypto/quic_random.h" | |
6 | |
7 #include "base/logging.h" | |
8 #include "base/macros.h" | |
9 #include "base/memory/singleton.h" | |
10 #include "crypto/random.h" | |
11 #include "net/quic/quic_bug_tracker.h" | |
12 | |
13 namespace net { | |
14 | |
15 namespace { | |
16 | |
17 class DefaultRandom : public QuicRandom { | |
18 public: | |
19 static DefaultRandom* GetInstance(); | |
20 | |
21 // QuicRandom implementation | |
22 void RandBytes(void* data, size_t len) override; | |
23 uint64_t RandUint64() override; | |
24 void Reseed(const void* additional_entropy, size_t entropy_len) override; | |
25 | |
26 private: | |
27 DefaultRandom() {} | |
28 ~DefaultRandom() override {} | |
29 | |
30 friend struct base::DefaultSingletonTraits<DefaultRandom>; | |
31 DISALLOW_COPY_AND_ASSIGN(DefaultRandom); | |
32 }; | |
33 | |
34 DefaultRandom* DefaultRandom::GetInstance() { | |
35 return base::Singleton<DefaultRandom>::get(); | |
36 } | |
37 | |
38 void DefaultRandom::RandBytes(void* data, size_t len) { | |
39 crypto::RandBytes(data, len); | |
40 } | |
41 | |
42 uint64_t DefaultRandom::RandUint64() { | |
43 uint64_t value; | |
44 RandBytes(&value, sizeof(value)); | |
45 return value; | |
46 } | |
47 | |
48 void DefaultRandom::Reseed(const void* additional_entropy, size_t entropy_len) { | |
49 // No such function exists in crypto/random.h. | |
50 } | |
51 | |
52 } // namespace | |
53 | |
54 // static | |
55 QuicRandom* QuicRandom::GetInstance() { | |
56 return DefaultRandom::GetInstance(); | |
57 } | |
58 | |
59 } // namespace net | |
OLD | NEW |