OLD | NEW |
1 // Copyright 2017 The Chromium Authors. All rights reserved. | 1 // Copyright 2017 The Chromium Authors. All rights reserved. |
2 // Use of this source code is governed by a BSD-style license that can be | 2 // Use of this source code is governed by a BSD-style license that can be |
3 // found in the LICENSE file. | 3 // found in the LICENSE file. |
4 | 4 |
5 #include "base/rand_util.h" | 5 #include "base/rand_util.h" |
6 | 6 |
7 #include <magenta/syscalls.h> | 7 #include <magenta/syscalls.h> |
8 | 8 |
9 #include <algorithm> | 9 #include <algorithm> |
10 | 10 |
(...skipping 10 matching lines...) Expand all Loading... |
21 void RandBytes(void* output, size_t output_length) { | 21 void RandBytes(void* output, size_t output_length) { |
22 size_t remaining = output_length; | 22 size_t remaining = output_length; |
23 unsigned char* cur = reinterpret_cast<unsigned char*>(output); | 23 unsigned char* cur = reinterpret_cast<unsigned char*>(output); |
24 do { | 24 do { |
25 // The syscall has a maximum number of bytes that can be read at once. | 25 // The syscall has a maximum number of bytes that can be read at once. |
26 size_t read_len = | 26 size_t read_len = |
27 std::min(remaining, static_cast<size_t>(MX_CPRNG_DRAW_MAX_LEN)); | 27 std::min(remaining, static_cast<size_t>(MX_CPRNG_DRAW_MAX_LEN)); |
28 | 28 |
29 size_t actual; | 29 size_t actual; |
30 mx_status_t status = mx_cprng_draw(cur, read_len, &actual); | 30 mx_status_t status = mx_cprng_draw(cur, read_len, &actual); |
31 CHECK(status == NO_ERROR && read_len == actual); | 31 CHECK(status == MX_OK && read_len == actual); |
32 | 32 |
33 CHECK(remaining >= actual); | 33 CHECK(remaining >= actual); |
34 remaining -= actual; | 34 remaining -= actual; |
35 cur += actual; | 35 cur += actual; |
36 } while (remaining > 0); | 36 } while (remaining > 0); |
37 } | 37 } |
38 | 38 |
39 } // namespace base | 39 } // namespace base |
OLD | NEW |