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 #ifndef CRYPTO_RANDOM_H_ 6 #define CRYPTO_RANDOM_H_ 7 8 #include <stddef.h> 9 10 #include <vector> 11 12 #include "base/containers/span.h" 13 #include "crypto/crypto_export.h" 14 15 namespace crypto { 16 17 // Fills the given buffer with `length` random bytes of cryptographically 18 // secure random numbers. 19 CRYPTO_EXPORT void RandBytes(void *bytes, size_t length); 20 21 // Fills `bytes` with cryptographically-secure random bits. 22 CRYPTO_EXPORT void RandBytes(base::span<uint8_t> bytes); 23 24 // Returns a vector of `length` bytes filled with cryptographically-secure 25 // random bits. 26 CRYPTO_EXPORT std::vector<uint8_t> RandBytesAsVector(size_t length); 27 } 28 29 #endif // CRYPTO_RANDOM_H_ 30