Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(765)

Unified Diff: base/crypto/symmetric_key_win.cc

Issue 6683060: Private API for extensions like ssh-client that need access to TCP. (Closed) Base URL: svn://svn.chromium.org/chrome/trunk/src
Patch Set: sigh-nedness Created 9 years, 9 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View side-by-side diff with in-line comments
Download patch
Index: base/crypto/symmetric_key_win.cc
diff --git a/base/crypto/symmetric_key_win.cc b/base/crypto/symmetric_key_win.cc
index 0a1c234a4b585249803949802dd47863961a6367..d36dd1f769fbe4251a7adfe84b029c060af4ee90 100644
--- a/base/crypto/symmetric_key_win.cc
+++ b/base/crypto/symmetric_key_win.cc
@@ -312,6 +312,26 @@ SymmetricKey::~SymmetricKey() {
}
// static
+bool SymmetricKey::GenerateRandomBytes(size_t num_bytes, uint8* out) {
+ if (num_bytes == 0)
+ return true;
+ if (out == NULL)
+ return false;
+
+ ScopedHCRYPTPROV provider;
+ // See comment in GenerateAESKey as to why NULL is acceptable for the
+ // container name.
+ if (!CryptAcquireContext(
+ provider.receive(), NULL, NULL, PROV_RSA_FULL, CRYPT_VERIFYCONTEXT)) {
+ return false;
+ }
+ if (CryptGenRandom(provider, num_bytes, out))
+ return true;
+ else
+ return false;
+}
+
+// static
SymmetricKey* SymmetricKey::GenerateRandomKey(Algorithm algorithm,
size_t key_size_in_bits) {
DCHECK_GE(key_size_in_bits, 8);

Powered by Google App Engine
This is Rietveld 408576698