1 | // Copyright (c) 2012, the Dart project authors. Please see the AUTHORS file |
2 | // for details. All rights reserved. Use of this source code is governed by a |
3 | // BSD-style license that can be found in the LICENSE file. |
4 | |
5 | #ifndef _CRT_RAND_S |
6 | #define _CRT_RAND_S |
7 | #endif |
8 | |
9 | #include "platform/globals.h" |
10 | #if defined(HOST_OS_WINDOWS) |
11 | |
12 | #include "bin/crypto.h" |
13 | |
14 | namespace dart { |
15 | namespace bin { |
16 | |
17 | bool Crypto::GetRandomBytes(intptr_t count, uint8_t* buffer) { |
18 | uint32_t num; |
19 | intptr_t read = 0; |
20 | while (read < count) { |
21 | if (rand_s(&num) != 0) { |
22 | return false; |
23 | } |
24 | for (int i = 0; i < 4 && read < count; i++) { |
25 | buffer[read] = num >> (i * 8); |
26 | read++; |
27 | } |
28 | } |
29 | return true; |
30 | } |
31 | |
32 | } // namespace bin |
33 | } // namespace dart |
34 | |
35 | #endif // defined(HOST_OS_WINDOWS) |
36 | |