chromium/third_party/webrtc/rtc_base/crypto_random.cc

/*
 *  Copyright 2004 The WebRTC Project Authors. All rights reserved.
 *
 *  Use of this source code is governed by a BSD-style license
 *  that can be found in the LICENSE file in the root of the source
 *  tree. An additional intellectual property rights grant can be found
 *  in the file PATENTS.  All contributing project authors may
 *  be found in the AUTHORS file in the root of the source tree.
 */

#include "rtc_base/crypto_random.h"

#include <openssl/rand.h>

#include <cstdint>
#include <limits>
#include <memory>
#include <utility>

#include "absl/strings/string_view.h"
#include "rtc_base/checks.h"
#include "rtc_base/logging.h"
#include "rtc_base/synchronization/mutex.h"

// Protect against max macro inclusion.
#undef max

namespace rtc {

namespace {

// The OpenSSL RNG.
class SecureRandomGenerator : public RandomGenerator {};

// A test random generator, for predictable output.
class TestRandomGenerator : public RandomGenerator {};

// TODO: Use Base64::Base64Table instead.
static const char kBase64[64] =;

static const char kHex[16] =;

static const char kUuidDigit17[4] =;

// Lock for the global random generator, only needed to serialize changing the
// generator.
webrtc::Mutex& GetRandomGeneratorLock() {}

// This round about way of creating a global RNG is to safe-guard against
// indeterminant static initialization order.
std::unique_ptr<RandomGenerator>& GetGlobalRng() {}

RandomGenerator& Rng() {}

}  // namespace

void SetDefaultRandomGenerator() {}

void SetRandomGenerator(std::unique_ptr<RandomGenerator> generator) {}

void SetRandomTestMode(bool test) {}

bool InitRandom(int seed) {}

bool InitRandom(const char* seed, size_t len) {}

std::string CreateRandomString(size_t len) {}

static bool CreateRandomString(size_t len,
                               const char* table,
                               int table_size,
                               std::string* str) {}

bool CreateRandomString(size_t len, std::string* str) {}

bool CreateRandomString(size_t len, absl::string_view table, std::string* str) {}

bool CreateRandomData(size_t length, std::string* data) {}

// Version 4 UUID is of the form:
// xxxxxxxx-xxxx-4xxx-yxxx-xxxxxxxxxxxx
// Where 'x' is a hex digit, and 'y' is 8, 9, a or b.
std::string CreateRandomUuid() {}

uint32_t CreateRandomId() {}

uint64_t CreateRandomId64() {}

uint32_t CreateRandomNonZeroId() {}

double CreateRandomDouble() {}

}  // namespace rtc