summaryrefslogtreecommitdiffstats
path: root/base/crypto
diff options
context:
space:
mode:
Diffstat (limited to 'base/crypto')
-rw-r--r--base/crypto/capi_util.cc4
-rw-r--r--base/crypto/capi_util.h4
-rw-r--r--base/crypto/rsa_private_key_win.cc17
-rw-r--r--base/crypto/symmetric_key_win.cc53
4 files changed, 43 insertions, 35 deletions
diff --git a/base/crypto/capi_util.cc b/base/crypto/capi_util.cc
index 0499492..cf47a50 100644
--- a/base/crypto/capi_util.cc
+++ b/base/crypto/capi_util.cc
@@ -38,8 +38,8 @@ class CAPIUtilSingleton {
namespace base {
BOOL CryptAcquireContextLocked(HCRYPTPROV* prov,
- const TCHAR* container,
- const TCHAR* provider,
+ LPCWSTR container,
+ LPCWSTR provider,
DWORD prov_type,
DWORD flags)
{
diff --git a/base/crypto/capi_util.h b/base/crypto/capi_util.h
index 8f89828..df7f749 100644
--- a/base/crypto/capi_util.h
+++ b/base/crypto/capi_util.h
@@ -22,8 +22,8 @@ namespace base {
// CRYPT_NEWKEYSET or CRYPT_DELETEKEYSET is specified in the dwFlags
// parameter."
BOOL CryptAcquireContextLocked(HCRYPTPROV* prov,
- const TCHAR* container,
- const TCHAR* provider,
+ LPCWSTR container,
+ LPCWSTR provider,
DWORD prov_type,
DWORD flags);
diff --git a/base/crypto/rsa_private_key_win.cc b/base/crypto/rsa_private_key_win.cc
index 5dd8cca..6c8a34b 100644
--- a/base/crypto/rsa_private_key_win.cc
+++ b/base/crypto/rsa_private_key_win.cc
@@ -1,4 +1,4 @@
-// Copyright (c) 2009 The Chromium Authors. All rights reserved.
+// Copyright (c) 2010 The Chromium Authors. All rights reserved.
// Use of this source code is governed by a BSD-style license that can be
// found in the LICENSE file.
@@ -96,15 +96,15 @@ RSAPrivateKey* RSAPrivateKey::CreateFromPrivateKeyInfo(
dest += pki.exponent2()->size();
memcpy(dest, &pki.coefficient()->front(), pki.coefficient()->size());
dest += pki.coefficient()->size();
- memcpy(dest, &pki.private_exponent()->front(), pki.private_exponent()->size());
+ memcpy(dest, &pki.private_exponent()->front(),
+ pki.private_exponent()->size());
dest += pki.private_exponent()->size();
READ_ASSERT(dest == blob.get() + blob_size);
- if (!CryptImportKey(
- result->provider_, reinterpret_cast<uint8*>(public_key_struc),
- blob_size, NULL, CRYPT_EXPORTABLE, result->key_.receive())) {
+ if (!CryptImportKey(result->provider_,
+ reinterpret_cast<uint8*>(public_key_struc), blob_size, 0,
+ CRYPT_EXPORTABLE, result->key_.receive()))
return NULL;
- }
return result.release();
}
@@ -135,14 +135,13 @@ bool RSAPrivateKey::InitProvider() {
bool RSAPrivateKey::ExportPrivateKey(std::vector<uint8>* output) {
// Export the key
DWORD blob_length = 0;
- if (!CryptExportKey(key_, NULL, PRIVATEKEYBLOB, 0, NULL, &blob_length)) {
+ if (!CryptExportKey(key_, 0, PRIVATEKEYBLOB, 0, NULL, &blob_length)) {
NOTREACHED();
return false;
}
scoped_array<uint8> blob(new uint8[blob_length]);
- if (!CryptExportKey(key_, NULL, PRIVATEKEYBLOB, 0, blob.get(),
- &blob_length)) {
+ if (!CryptExportKey(key_, 0, PRIVATEKEYBLOB, 0, blob.get(), &blob_length)) {
NOTREACHED();
return false;
}
diff --git a/base/crypto/symmetric_key_win.cc b/base/crypto/symmetric_key_win.cc
index 76be8ad..87d715a 100644
--- a/base/crypto/symmetric_key_win.cc
+++ b/base/crypto/symmetric_key_win.cc
@@ -48,8 +48,10 @@ ALG_ID GetAESAlgIDForKeySize(size_t key_size_in_bits) {
// CALG_HMAC.
// If successful, returns true and stores the imported key in |*key|.
// TODO(wtc): use this function in hmac_win.cc.
-bool ImportRawKey(HCRYPTPROV provider, ALG_ID alg, const void* key_data,
- DWORD key_size, ScopedHCRYPTKEY* key) {
+bool ImportRawKey(HCRYPTPROV provider,
+ ALG_ID alg,
+ const void* key_data, DWORD key_size,
+ ScopedHCRYPTKEY* key) {
DCHECK_GT(key_size, 0);
DWORD actual_size = sizeof(PlaintextBlobHeader) + key_size;
@@ -77,8 +79,8 @@ bool ImportRawKey(HCRYPTPROV provider, ALG_ID alg, const void* key_data,
flags |= CRYPT_IPSEC_HMAC_KEY;
}
- BOOL ok = CryptImportKey(provider, actual_key, actual_size, NULL,
- flags, &unsafe_key);
+ BOOL ok =
+ CryptImportKey(provider, actual_key, actual_size, 0, flags, &unsafe_key);
// Clean up the temporary copy of key, regardless of whether it was imported
// sucessfully or not.
@@ -94,7 +96,8 @@ bool ImportRawKey(HCRYPTPROV provider, ALG_ID alg, const void* key_data,
// Attempts to generate a random AES key of |key_size_in_bits|. Returns true
// if generation is successful, storing the generated key in |*key| and the
// key provider (CSP) in |*provider|.
-bool GenerateAESKey(size_t key_size_in_bits, ScopedHCRYPTPROV* provider,
+bool GenerateAESKey(size_t key_size_in_bits,
+ ScopedHCRYPTPROV* provider,
ScopedHCRYPTKEY* key) {
DCHECK(provider);
DCHECK(key);
@@ -161,8 +164,10 @@ bool CheckHMACKeySize(size_t key_size_in_bits, ALG_ID alg) {
// |key_size_in_bits| must be >= 1/2 the hash size of |alg| for security.
// Returns true if generation is successful, storing the generated key in
// |*key| and the key provider (CSP) in |*provider|.
-bool GenerateHMACKey(size_t key_size_in_bits, ALG_ID alg,
- ScopedHCRYPTPROV* provider, ScopedHCRYPTKEY* key,
+bool GenerateHMACKey(size_t key_size_in_bits,
+ ALG_ID alg,
+ ScopedHCRYPTPROV* provider,
+ ScopedHCRYPTKEY* key,
scoped_array<BYTE>* raw_key) {
DCHECK(provider);
DCHECK(key);
@@ -202,7 +207,9 @@ bool GenerateHMACKey(size_t key_size_in_bits, ALG_ID alg,
// and |key|. The inner hash function will be |hash_alg|. If successful,
// returns true and stores the hash in |*hash|.
// TODO(wtc): use this function in hmac_win.cc.
-bool CreateHMACHash(HCRYPTPROV provider, HCRYPTKEY key, ALG_ID hash_alg,
+bool CreateHMACHash(HCRYPTPROV provider,
+ HCRYPTKEY key,
+ ALG_ID hash_alg,
ScopedHCRYPTHASH* hash) {
ScopedHCRYPTHASH safe_hash;
BOOL ok = CryptCreateHash(provider, CALG_HMAC, key, 0, safe_hash.receive());
@@ -228,9 +235,12 @@ bool CreateHMACHash(HCRYPTPROV provider, HCRYPTKEY key, ALG_ID hash_alg,
// |output_buf| must have enough space to accomodate the output of the PRF
// specified by |hash|.
// Returns true if the block was successfully computed.
-bool ComputePBKDF2Block(HCRYPTHASH hash, DWORD hash_size,
- const std::string& salt, size_t iterations,
- uint32 block_index, BYTE* output_buf) {
+bool ComputePBKDF2Block(HCRYPTHASH hash,
+ DWORD hash_size,
+ const std::string& salt,
+ size_t iterations,
+ uint32 block_index,
+ BYTE* output_buf) {
// From RFC 2898:
// 3. <snip> The function F is defined as the exclusive-or sum of the first
// c iterates of the underlying pseudorandom function PRF applied to the
@@ -247,9 +257,8 @@ bool ComputePBKDF2Block(HCRYPTHASH hash, DWORD hash_size,
return false;
// Iteration U_1: Compute PRF for S.
- ok = CryptHashData(safe_hash,
- reinterpret_cast<const BYTE*>(salt.data()), salt.size(),
- 0);
+ ok = CryptHashData(safe_hash, reinterpret_cast<const BYTE*>(salt.data()),
+ salt.size(), 0);
if (!ok)
return false;
@@ -432,10 +441,9 @@ SymmetricKey* SymmetricKey::DeriveKeyFromPassword(Algorithm algorithm,
// a derived key DK:
// DK = T_1 || T_2 || ... || T_l<0..r-1>
for (uint32 block_index = 1; block_index <= L; ++block_index) {
- if (!ComputePBKDF2Block(prf, hLen, salt, iterations,
- block_index, block_offset)) {
+ if (!ComputePBKDF2Block(prf, hLen, salt, iterations, block_index,
+ block_offset))
return NULL;
- }
block_offset += hLen;
}
@@ -474,8 +482,8 @@ SymmetricKey* SymmetricKey::Import(Algorithm algorithm,
return NULL;
ScopedHCRYPTPROV provider;
- BOOL ok = CryptAcquireContext(provider.receive(), NULL, NULL,
- provider_type, CRYPT_VERIFYCONTEXT);
+ BOOL ok = CryptAcquireContext(provider.receive(), NULL, NULL, provider_type,
+ CRYPT_VERIFYCONTEXT);
if (!ok)
return NULL;
@@ -495,13 +503,13 @@ bool SymmetricKey::GetRawKey(std::string* raw_key) {
}
DWORD size = 0;
- BOOL ok = CryptExportKey(key_, NULL, PLAINTEXTKEYBLOB, 0, NULL, &size);
+ BOOL ok = CryptExportKey(key_, 0, PLAINTEXTKEYBLOB, 0, NULL, &size);
if (!ok)
return false;
std::vector<BYTE> result(size);
- ok = CryptExportKey(key_, NULL, PLAINTEXTKEYBLOB, 0, &result[0], &size);
+ ok = CryptExportKey(key_, 0, PLAINTEXTKEYBLOB, 0, &result[0], &size);
if (!ok)
return false;
@@ -515,7 +523,8 @@ bool SymmetricKey::GetRawKey(std::string* raw_key) {
return true;
}
-SymmetricKey::SymmetricKey(HCRYPTPROV provider, HCRYPTKEY key,
+SymmetricKey::SymmetricKey(HCRYPTPROV provider,
+ HCRYPTKEY key,
const void* key_data, size_t key_size_in_bytes)
: provider_(provider), key_(key) {
if (key_data) {