| OLD | NEW |
| (Empty) | |
| 1 // Copyright (c) 2011 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. |
| 4 |
| 5 #include "remoting/host/host_secret.h" |
| 6 |
| 7 #include <vector> |
| 8 |
| 9 #include "base/logging.h" |
| 10 #include "base/rand_util.h" |
| 11 #include "base/string_number_conversions.h" |
| 12 |
| 13 namespace remoting { |
| 14 |
| 15 namespace { |
| 16 |
| 17 // 5 digits means 100K possible host secrets with uniform distribution, which |
| 18 // should be enough for short-term passwords, given that we rate-limit guesses |
| 19 // in the cloud and expire access codes after a small number of attempts. |
| 20 const int kMaxHostSecret = 100000; |
| 21 |
| 22 // Generates cryptographically strong random number in the range [0, max). |
| 23 int CryptoRandomInt(int max) { |
| 24 uint64 random_int32; |
| 25 base::RandBytes(&random_int32, sizeof(random_int32)); |
| 26 return random_int32 % max; |
| 27 } |
| 28 |
| 29 } // namespace |
| 30 |
| 31 std::string GenerateSupportHostSecret() { |
| 32 return base::IntToString(CryptoRandomInt(kMaxHostSecret)); |
| 33 } |
| 34 |
| 35 } // namespace remoting |
| OLD | NEW |