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.
5 #include "net/quic/crypto/quic_random.h"
7 #include "base/logging.h"
8 #include "base/memory/singleton.h"
9 #include "crypto/random.h"
15 class DefaultRandom : public QuicRandom {
17 static DefaultRandom* GetInstance();
19 // QuicRandom implementation
20 virtual void RandBytes(void* data, size_t len) OVERRIDE;
21 virtual uint64 RandUint64() OVERRIDE;
22 virtual bool RandBool() OVERRIDE;
23 virtual void Reseed(const void* additional_entropy,
24 size_t entropy_len) OVERRIDE;
28 virtual ~DefaultRandom() {}
30 friend struct DefaultSingletonTraits<DefaultRandom>;
31 DISALLOW_COPY_AND_ASSIGN(DefaultRandom);
34 DefaultRandom* DefaultRandom::GetInstance() {
35 return Singleton<DefaultRandom>::get();
38 void DefaultRandom::RandBytes(void* data, size_t len) {
39 crypto::RandBytes(data, len);
42 uint64 DefaultRandom::RandUint64() {
44 RandBytes(&value, sizeof(value));
48 bool DefaultRandom::RandBool() {
50 RandBytes(&value, sizeof(value));
51 return (value & 1) == 1;
54 void DefaultRandom::Reseed(const void* additional_entropy, size_t entropy_len) {
55 // No such function exists in crypto/random.h.
58 DefaultRandom::DefaultRandom() {
64 QuicRandom* QuicRandom::GetInstance() { return DefaultRandom::GetInstance(); }