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