Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(946)

Unified Diff: runtime/bin/crypto_fuchsia.cc

Issue 2204523002: Fuchsia: Use low-level prng call, add test, update test runner. (Closed) Base URL: https://chromium.googlesource.com/external/github.com/dart-lang/sdk/@master
Patch Set: Fix bug Created 4 years, 4 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View side-by-side diff with in-line comments
Download patch
« no previous file with comments | « runtime/bin/builtin_impl_sources.gypi ('k') | runtime/bin/crypto_test.cc » ('j') | no next file with comments »
Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
Index: runtime/bin/crypto_fuchsia.cc
diff --git a/runtime/bin/crypto_fuchsia.cc b/runtime/bin/crypto_fuchsia.cc
index 9423f7cdf9423a3bed545b2f051bb42dae635dc1..04c5f2254760ee7b279625a1190d32a34b5ddcb4 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 + read, len);
+ 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;
}
« no previous file with comments | « runtime/bin/builtin_impl_sources.gypi ('k') | runtime/bin/crypto_test.cc » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698