Chromium Code Reviews| Index: runtime/bin/crypto_fuchsia.cc |
| diff --git a/runtime/bin/crypto_fuchsia.cc b/runtime/bin/crypto_fuchsia.cc |
| index 9423f7cdf9423a3bed545b2f051bb42dae635dc1..2c1ea1aea685fb1fc23c22a2e6c4c953011b324c 100644 |
| --- a/runtime/bin/crypto_fuchsia.cc |
| +++ b/runtime/bin/crypto_fuchsia.cc |
| @@ -7,20 +7,23 @@ |
| #include "bin/crypto.h" |
| +#include <magenta/syscalls.h> |
| + |
| namespace dart { |
| namespace bin { |
| bool Crypto::GetRandomBytes(intptr_t count, uint8_t* buffer) { |
| - uint32_t num; |
| intptr_t read = 0; |
| while (read < count) { |
| - if (rand_r(&num) != 0) { |
| + const intptr_t remaining = count - read; |
| + const intptr_t len = |
| + (MX_CPRNG_DRAW_MAX_LEN < remaining) ? MX_CPRNG_DRAW_MAX_LEN |
| + : remaining; |
| + const mx_ssize_t res = mx_cprng_draw(buffer, len); |
|
siva
2016/08/02 19:55:13
doesn't buffer have to be updated to buffer+read ?
zra
2016/08/02 20:16:55
Oops. Yes.
|
| + if (res == ERR_INVALID_ARGS) { |
| return false; |
| } |
| - for (int i = 0; i < 4 && read < count; i++) { |
| - buffer[read] = num >> (i * 8); |
| - read++; |
| - } |
| + read += res; |
| } |
| return true; |
| } |