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

Unified Diff: crypto/symmetric_key_mac.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: reflected comments Created 9 years, 7 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
« no previous file with comments | « crypto/hmac_win.cc ('k') | no next file » | no next file with comments »
Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
Index: crypto/symmetric_key_mac.cc
diff --git a/crypto/symmetric_key_mac.cc b/crypto/symmetric_key_mac.cc
index 47193a0883311a9ee376721d8fee084734db8734..7c339de03eb034d0935b6bea06d4c89a91cd746d 100644
--- a/crypto/symmetric_key_mac.cc
+++ b/crypto/symmetric_key_mac.cc
@@ -32,14 +32,14 @@ CSSM_KEY_TYPE CheckKeyParams(crypto::SymmetricKey::Algorithm algorithm,
}
}
-void* CreateRandomBytes(size_t size) {
+uint8_t* CreateRandomBytes(size_t size) {
CSSM_RETURN err;
CSSM_CC_HANDLE ctx;
err = CSSM_CSP_CreateRandomGenContext(crypto::GetSharedCSPHandle(),
CSSM_ALGID_APPLE_YARROW,
NULL,
size, &ctx);
- if (err) {
+ if (err != CSSM_OK) {
wtc 2011/05/17 23:37:52 Although I prefer this form, it's more important t
Denis Lagno 2011/05/18 11:53:32 Done.
crypto::LogCSSMError("CSSM_CSP_CreateRandomGenContext", err);
return NULL;
}
@@ -50,7 +50,7 @@ void* CreateRandomBytes(size_t size) {
random_data.Data = NULL;
}
CSSM_DeleteContext(ctx);
- return random_data.Data; // Caller responsible for freeing this
+ return random_data.Data; // Caller responsible for freeing this.
}
inline CSSM_DATA StringToData(const std::string& str) {
@@ -65,16 +65,20 @@ inline CSSM_DATA StringToData(const std::string& str) {
namespace crypto {
-SymmetricKey::~SymmetricKey() {}
+SymmetricKey::~SymmetricKey() {
+ std::fill(key_.begin(), key_.end(), 0);
+}
// static
SymmetricKey* SymmetricKey::GenerateRandomKey(Algorithm algorithm,
size_t key_size_in_bits) {
CheckKeyParams(algorithm, key_size_in_bits);
- void* random_bytes = CreateRandomBytes((key_size_in_bits + 7) / 8);
+ size_t key_size_in_bytes = (key_size_in_bits + 7) / 8;
+ uint8_t* random_bytes = CreateRandomBytes(key_size_in_bytes);
if (!random_bytes)
return NULL;
SymmetricKey *key = new SymmetricKey(random_bytes, key_size_in_bits);
+ std::fill(random_bytes, random_bytes + key_size_in_bytes, 0);
wtc 2011/05/17 23:37:52 You can use memset(random_bytes, 0, key_size_in_
Denis Lagno 2011/05/18 11:53:32 better leave std::fill for consistency
free(random_bytes);
return key;
}
@@ -139,9 +143,9 @@ SymmetricKey* SymmetricKey::Import(Algorithm algorithm,
return new SymmetricKey(raw_key.data(), raw_key.size() * 8);
}
-SymmetricKey::SymmetricKey(const void *key_data, size_t key_size_in_bits)
- : key_(reinterpret_cast<const char*>(key_data),
- key_size_in_bits / 8) {}
+SymmetricKey::SymmetricKey(const void* key_data, size_t key_size_in_bits)
+ : key_(static_cast<const char*>(key_data), key_size_in_bits / 8) {
wtc 2011/05/17 23:37:52 I was told to use reinterpret_cast to cast void* t
Denis Lagno 2011/05/18 11:53:32 Done.
+}
bool SymmetricKey::GetRawKey(std::string* raw_key) {
*raw_key = key_;
« no previous file with comments | « crypto/hmac_win.cc ('k') | no next file » | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698