Flutter Engine
The Flutter Engine
Loading...
Searching...
No Matches
crypto_win.cc
Go to the documentation of this 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
3// BSD-style license that can be found in the LICENSE file.
4
5#include "platform/globals.h"
6#if defined(DART_HOST_OS_WINDOWS)
7
8#include <bcrypt.h>
9#include "bin/crypto.h"
10
11namespace dart {
12namespace bin {
13
14// see https://docs.microsoft.com/en-us/windows/win32/api/bcrypt/nf-bcrypt-bcryptgenrandom
15#ifndef NT_SUCCESS
16#define NT_SUCCESS(Status) ((NTSTATUS)(Status) >= 0)
17#endif
18
19bool Crypto::GetRandomBytes(intptr_t count, uint8_t* buffer) {
20 if (count <= 0) {
21 return true;
22 }
23 return NT_SUCCESS(BCryptGenRandom(/*hAlgorithm=*/nullptr, buffer,
24 (ULONG)count,
25 BCRYPT_USE_SYSTEM_PREFERRED_RNG));
26}
27
28} // namespace bin
29} // namespace dart
30
31#endif // defined(DART_HOST_OS_WINDOWS)
int count
static bool GetRandomBytes(intptr_t count, uint8_t *buffer)
static const uint8_t buffer[]
DWORD ULONG