7800d2a995
Change-Id: Ic4215ceb00f5a60d21ec1398fd398a9f78a9eb94 Reviewed-on: https://dart-review.googlesource.com/6100 Reviewed-by: Zach Anderson <zra@google.com>
35 lines
888 B
C++
35 lines
888 B
C++
// Copyright (c) 2016, the Dart project authors. Please see the AUTHORS file
|
|
// for details. All rights reserved. Use of this source code is governed by a
|
|
// BSD-style license that can be found in the LICENSE file.
|
|
|
|
#include "platform/globals.h"
|
|
#if defined(HOST_OS_FUCHSIA)
|
|
|
|
#include "bin/crypto.h"
|
|
|
|
#include <zircon/syscalls.h>
|
|
|
|
namespace dart {
|
|
namespace bin {
|
|
|
|
bool Crypto::GetRandomBytes(intptr_t count, uint8_t* buffer) {
|
|
intptr_t read = 0;
|
|
while (read < count) {
|
|
const intptr_t remaining = count - read;
|
|
const intptr_t len =
|
|
(ZX_CPRNG_DRAW_MAX_LEN < remaining) ? ZX_CPRNG_DRAW_MAX_LEN : remaining;
|
|
size_t res = 0;
|
|
const zx_status_t status = zx_cprng_draw(buffer + read, len, &res);
|
|
if (status != ZX_OK) {
|
|
return false;
|
|
}
|
|
read += res;
|
|
}
|
|
return true;
|
|
}
|
|
|
|
} // namespace bin
|
|
} // namespace dart
|
|
|
|
#endif // defined(HOST_OS_FUCHSIA)
|