1 // Copyright 2017 Google Inc. 2 // 3 // Licensed under the Apache License, Version 2.0 (the "License"); 4 // you may not use this file except in compliance with the License. 5 // You may obtain a copy of the License at 6 // 7 // http://www.apache.org/licenses/LICENSE-2.0 8 // 9 // Unless required by applicable law or agreed to in writing, software 10 // distributed under the License is distributed on an "AS IS" BASIS, 11 // WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 12 // See the License for the specific language governing permissions and 13 // limitations under the License. 14 // 15 /////////////////////////////////////////////////////////////////////////////// 16 17 #ifndef TINK_SUBTLE_RANDOM_H_ 18 #define TINK_SUBTLE_RANDOM_H_ 19 20 #include <memory> 21 #include <string> 22 23 #include "tink/util/secret_data.h" 24 #include "tink/util/status.h" 25 26 namespace crypto { 27 namespace tink { 28 namespace subtle { 29 30 class Random { 31 public: 32 // Fills the given `buffer` with random bytes. 33 static util::Status GetRandomBytes(absl::Span<char> buffer); 34 // Returns a random string of desired length. 35 static std::string GetRandomBytes(size_t length); 36 static uint32_t GetRandomUInt32(); 37 static uint16_t GetRandomUInt16(); 38 static uint8_t GetRandomUInt8(); 39 // Returns length bytes of random data stored in specialized key container. 40 static util::SecretData GetRandomKeyBytes(size_t length); 41 }; 42 43 } // namespace subtle 44 } // namespace tink 45 } // namespace crypto 46 47 #endif // TINK_SUBTLE_RANDOM_H_ 48