1 // Copyright 2012 The Chromium Authors 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 "crypto/random.h" 6 7 #include <stddef.h> 8 9 #include <vector> 10 11 #include "base/rand_util.h" 12 13 namespace crypto { 14 RandBytes(void * bytes,size_t length)15void RandBytes(void *bytes, size_t length) { 16 // It's OK to call base::RandBytes(), because it's already strongly random. 17 // But _other_ code should go through this function to ensure that code which 18 // needs secure randomness is easily discoverable. 19 base::RandBytes(bytes, length); 20 } 21 RandBytes(base::span<uint8_t> bytes)22void RandBytes(base::span<uint8_t> bytes) { 23 RandBytes(bytes.data(), bytes.size()); 24 } 25 RandBytesAsVector(size_t length)26std::vector<uint8_t> RandBytesAsVector(size_t length) { 27 std::vector<uint8_t> result(length); 28 RandBytes(result); 29 return result; 30 } 31 32 } // namespace crypto 33 34