包布丁 has uploaded this change for review.
Use BCryptGenRandom for Crypto::GetRandomBytes on Windows
The current implementation of Crypto::GetRandomBytes on Windows calls
`rand_s` repeatedly until the buffer is completely filled. However,
`BCryptGenRandom` already provides the similar functionality to fill the
whole buffer at once and thus there is no need to maintain a handcrafted
implementation any more.
Change-Id: I52d990b01b59be872d825f2aa0e30b500a6d3e36
---
M runtime/bin/BUILD.gn
M runtime/bin/crypto_win.cc
2 files changed, 6 insertions(+), 16 deletions(-)
diff --git a/runtime/bin/BUILD.gn b/runtime/bin/BUILD.gn
index 1bc8225..8ab6fca 100644
--- a/runtime/bin/BUILD.gn
+++ b/runtime/bin/BUILD.gn
@@ -214,6 +214,7 @@
"Rpcrt4.lib",
"shlwapi.lib",
"winmm.lib",
+ "bcrypt.lib",
]
if (target_os != "winuwp") {
libs += [ "psapi.lib" ]
@@ -784,6 +785,7 @@
"Rpcrt4.lib",
"shlwapi.lib",
"winmm.lib",
+ "bcrypt.lib",
]
}
}
@@ -958,6 +960,7 @@
"Rpcrt4.lib",
"shlwapi.lib",
"winmm.lib",
+ "bcrypt.lib",
]
}
}
diff --git a/runtime/bin/crypto_win.cc b/runtime/bin/crypto_win.cc
index fd68802..23d52ef 100644
--- a/runtime/bin/crypto_win.cc
+++ b/runtime/bin/crypto_win.cc
@@ -2,31 +2,18 @@
// 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.
-#ifndef _CRT_RAND_S
-#define _CRT_RAND_S
-#endif
-
#include "platform/globals.h"
#if defined(HOST_OS_WINDOWS)
+#include <bcrypt.h>
#include "bin/crypto.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_s(&num) != 0) {
- return false;
- }
- for (int i = 0; i < 4 && read < count; i++) {
- buffer[read] = num >> (i * 8);
- read++;
- }
- }
- return true;
+ return SUCCEEDED(BCryptGenRandom(NULL, buffer, (ULONG)count,
+ BCRYPT_USE_SYSTEM_PREFERRED_RNG));
}
} // namespace bin
To view, visit change 200160. To unsubscribe, or for help writing mail filters, visit settings.
Attention is currently required from: 包布丁.
go/dart-cbuild result: FAILURE (REGRESSIONS DETECTED)
Details: https://goto.google.com/dart-cbuild/find/4f86cd9176625d9883b4315367c6bc7e2fca0f40
Bugs: go/dart-cbuild-bug/4f86cd9176625d9883b4315367c6bc7e2fca0f40
Attention is currently required from: 包布丁.
1 comment:
Patchset:
Thank you for putting together the change!
Have you signed CLA(https://github.com/dart-lang/sdk/blob/master/CONTRIBUTING.md#before-you-contribute) ?
To view, visit change 200160. To unsubscribe, or for help writing mail filters, visit settings.
Attention is currently required from: Alexander Aprelev.
1 comment:
Patchset:
Thank you for putting together the change! […]
Yes, I have already signed CLA.
May I know why CI failed? I could not log in to the website that Dart CI posted for details.
To view, visit change 200160. To unsubscribe, or for help writing mail filters, visit settings.
Attention is currently required from: 包布丁.
Patch set 2:Commit-Queue +2
1 comment:
Patchset:
Yes, I have already signed CLA. […]
Great! The failed CI can be ignored - there was an unrelated problem with the run.
To view, visit change 200160. To unsubscribe, or for help writing mail filters, visit settings.
Attention is currently required from: 包布丁.
CL dart-review.googlesource.com/200160 must be approved before triggering CQ
CL is missing the approving votes on Code-Review, Commit-Message-has-TEST labels.
If you think this is not correct, then your Gerrit project may be misconfigured: check `refs/meta/config`:`project.cfg` or contact maintainers of your project's infrastructure
Attention is currently required from: 包布丁.
Alexander Aprelev uploaded patch set #3 to the change originally created by 包布丁.
Use BCryptGenRandom for Crypto::GetRandomBytes on Windows
The current implementation of Crypto::GetRandomBytes on Windows calls
`rand_s` repeatedly until the buffer is completely filled. However,
`BCryptGenRandom` already provides the similar functionality to fill the
whole buffer at once and thus there is no need to maintain a handcrafted
implementation any more.
TEST=ci
Change-Id: I52d990b01b59be872d825f2aa0e30b500a6d3e36
---
M runtime/bin/BUILD.gn
M runtime/bin/crypto_win.cc
2 files changed, 6 insertions(+), 16 deletions(-)
To view, visit change 200160. To unsubscribe, or for help writing mail filters, visit settings.
Attention is currently required from: 包布丁.
Patch set 3:Code-Review +1Commit-Queue +2
1 comment:
Patchset:
Thank you once again!
To view, visit change 200160. To unsubscribe, or for help writing mail filters, visit settings.
Attention is currently required from: 包布丁.
Patch set 2:Code-Review +1
commi...@chromium.org submitted this change.
Use BCryptGenRandom for Crypto::GetRandomBytes on Windows
The current implementation of Crypto::GetRandomBytes on Windows calls
`rand_s` repeatedly until the buffer is completely filled. However,
`BCryptGenRandom` already provides the similar functionality to fill the
whole buffer at once and thus there is no need to maintain a handcrafted
implementation any more.
TEST=ci
Change-Id: I52d990b01b59be872d825f2aa0e30b500a6d3e36
Reviewed-on: https://dart-review.googlesource.com/c/sdk/+/200160
Reviewed-by: Alexander Aprelev <a...@google.com>
Commit-Queue: Alexander Aprelev <a...@google.com>
---
M runtime/bin/BUILD.gn
M runtime/bin/crypto_win.cc
2 files changed, 6 insertions(+), 16 deletions(-)
To view, visit change 200160. To unsubscribe, or for help writing mail filters, visit settings.
go/dart-cbuild result: SUCCESS
Details: https://goto.google.com/dart-cbuild/find/1731050b29097b7b40d208ec1658f6f20737d276