summaryrefslogtreecommitdiffstats
path: root/base
diff options
context:
space:
mode:
authorpkasting@chromium.org <pkasting@chromium.org@0039d316-1c4b-4281-b951-d872f2087c98>2011-09-28 21:15:27 +0000
committerpkasting@chromium.org <pkasting@chromium.org@0039d316-1c4b-4281-b951-d872f2087c98>2011-09-28 21:15:27 +0000
commitb13b9bdddf305f4992a97508a757600f40232faa (patch)
tree0649e1056f6e6c67921c7104ec406665c5c2b224 /base
parent927c151d93c1d458dc8e92e4b4dcb07874a0c436 (diff)
downloadchromium_src-b13b9bdddf305f4992a97508a757600f40232faa.zip
chromium_src-b13b9bdddf305f4992a97508a757600f40232faa.tar.gz
chromium_src-b13b9bdddf305f4992a97508a757600f40232faa.tar.bz2
Update SHA1_LENGTH -> kSHA1Length to match previous change to SHA256_LENGTH.
(I didn't try and understand or fix why kSHA1Length is in base:: while kSHA256Length is in crypto::.) BUG=92247 TEST=compiles Review URL: http://codereview.chromium.org/7972024 git-svn-id: svn://svn.chromium.org/chrome/trunk/src@103179 0039d316-1c4b-4281-b951-d872f2087c98
Diffstat (limited to 'base')
-rw-r--r--base/metrics/field_trial.cc2
-rw-r--r--base/sha1.h9
-rw-r--r--base/sha1_unittest.cc20
-rw-r--r--base/sha1_win.cc16
4 files changed, 22 insertions, 25 deletions
diff --git a/base/metrics/field_trial.cc b/base/metrics/field_trial.cc
index 99dce41..a18d72c 100644
--- a/base/metrics/field_trial.cc
+++ b/base/metrics/field_trial.cc
@@ -170,7 +170,7 @@ double FieldTrial::HashClientId(const std::string& client_id,
// and trial_name we get into something with a uniform distribution, which
// is desirable so that we don't skew any part of the 0-100% spectrum.
std::string input(client_id + trial_name);
- unsigned char sha1_hash[SHA1_LENGTH];
+ unsigned char sha1_hash[kSHA1Length];
SHA1HashBytes(reinterpret_cast<const unsigned char*>(input.c_str()),
input.size(),
sha1_hash);
diff --git a/base/sha1.h b/base/sha1.h
index ade46cd..80195ce 100644
--- a/base/sha1.h
+++ b/base/sha1.h
@@ -12,19 +12,16 @@
namespace base {
-// This function performs SHA-1 operations.
+// These functions perform SHA-1 operations.
-enum {
- SHA1_LENGTH = 20 // Length in bytes of a SHA-1 hash.
-};
-static const size_t kSHA1Length = 20; // TODO(pkasting): Replace above w/this
+static const size_t kSHA1Length = 20; // Length in bytes of a SHA-1 hash.
// Computes the SHA-1 hash of the input string |str| and returns the full
// hash.
BASE_EXPORT std::string SHA1HashString(const std::string& str);
// Computes the SHA-1 hash of the |len| bytes in |data| and puts the hash
-// in |hash|. |hash| must be SHA1_LENGTH bytes long.
+// in |hash|. |hash| must be kSHA1Length bytes long.
BASE_EXPORT void SHA1HashBytes(const unsigned char* data, size_t len,
unsigned char* hash);
diff --git a/base/sha1_unittest.cc b/base/sha1_unittest.cc
index 406150b..b29fe46 100644
--- a/base/sha1_unittest.cc
+++ b/base/sha1_unittest.cc
@@ -1,4 +1,4 @@
-// Copyright (c) 2009 The Chromium Authors. All rights reserved.
+// Copyright (c) 2011 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.
@@ -20,7 +20,7 @@ TEST(SHA1Test, Test1) {
0x9c, 0xd0, 0xd8, 0x9d };
std::string output = base::SHA1HashString(input);
- for (size_t i = 0; i < base::SHA1_LENGTH; i++)
+ for (size_t i = 0; i < base::kSHA1Length; i++)
EXPECT_EQ(expected[i], output[i] & 0xFF);
}
@@ -36,7 +36,7 @@ TEST(SHA1Test, Test2) {
0xe5, 0x46, 0x70, 0xf1 };
std::string output = base::SHA1HashString(input);
- for (size_t i = 0; i < base::SHA1_LENGTH; i++)
+ for (size_t i = 0; i < base::kSHA1Length; i++)
EXPECT_EQ(expected[i], output[i] & 0xFF);
}
@@ -51,14 +51,14 @@ TEST(SHA1Test, Test3) {
0x65, 0x34, 0x01, 0x6f };
std::string output = base::SHA1HashString(input);
- for (size_t i = 0; i < base::SHA1_LENGTH; i++)
+ for (size_t i = 0; i < base::kSHA1Length; i++)
EXPECT_EQ(expected[i], output[i] & 0xFF);
}
TEST(SHA1Test, Test1Bytes) {
// Example A.1 from FIPS 180-2: one-block message.
std::string input = "abc";
- unsigned char output[base::SHA1_LENGTH];
+ unsigned char output[base::kSHA1Length];
unsigned char expected[] = { 0xa9, 0x99, 0x3e, 0x36,
0x47, 0x06, 0x81, 0x6a,
@@ -68,7 +68,7 @@ TEST(SHA1Test, Test1Bytes) {
base::SHA1HashBytes(reinterpret_cast<const unsigned char*>(input.c_str()),
input.length(), output);
- for (size_t i = 0; i < base::SHA1_LENGTH; i++)
+ for (size_t i = 0; i < base::kSHA1Length; i++)
EXPECT_EQ(expected[i], output[i]);
}
@@ -76,7 +76,7 @@ TEST(SHA1Test, Test2Bytes) {
// Example A.2 from FIPS 180-2: multi-block message.
std::string input =
"abcdbcdecdefdefgefghfghighijhijkijkljklmklmnlmnomnopnopq";
- unsigned char output[base::SHA1_LENGTH];
+ unsigned char output[base::kSHA1Length];
unsigned char expected[] = { 0x84, 0x98, 0x3e, 0x44,
0x1c, 0x3b, 0xd2, 0x6e,
@@ -86,14 +86,14 @@ TEST(SHA1Test, Test2Bytes) {
base::SHA1HashBytes(reinterpret_cast<const unsigned char*>(input.c_str()),
input.length(), output);
- for (size_t i = 0; i < base::SHA1_LENGTH; i++)
+ for (size_t i = 0; i < base::kSHA1Length; i++)
EXPECT_EQ(expected[i], output[i]);
}
TEST(SHA1Test, Test3Bytes) {
// Example A.3 from FIPS 180-2: long message.
std::string input(1000000, 'a');
- unsigned char output[base::SHA1_LENGTH];
+ unsigned char output[base::kSHA1Length];
unsigned char expected[] = { 0x34, 0xaa, 0x97, 0x3c,
0xd4, 0xc4, 0xda, 0xa4,
@@ -103,6 +103,6 @@ TEST(SHA1Test, Test3Bytes) {
base::SHA1HashBytes(reinterpret_cast<const unsigned char*>(input.c_str()),
input.length(), output);
- for (size_t i = 0; i < base::SHA1_LENGTH; i++)
+ for (size_t i = 0; i < base::kSHA1Length; i++)
EXPECT_EQ(expected[i], output[i]);
}
diff --git a/base/sha1_win.cc b/base/sha1_win.cc
index 233749b5..2edfb3d 100644
--- a/base/sha1_win.cc
+++ b/base/sha1_win.cc
@@ -19,20 +19,20 @@ std::string SHA1HashString(const std::string& str) {
if (!CryptAcquireContext(provider.receive(), NULL, NULL, PROV_RSA_FULL,
CRYPT_VERIFYCONTEXT)) {
LOG(ERROR) << "CryptAcquireContext failed: " << GetLastError();
- return std::string(SHA1_LENGTH, '\0');
+ return std::string(kSHA1Length, '\0');
}
{
ScopedHCRYPTHASH hash;
if (!CryptCreateHash(provider, CALG_SHA1, 0, 0, hash.receive())) {
LOG(ERROR) << "CryptCreateHash failed: " << GetLastError();
- return std::string(SHA1_LENGTH, '\0');
+ return std::string(kSHA1Length, '\0');
}
if (!CryptHashData(hash, reinterpret_cast<CONST BYTE*>(str.data()),
static_cast<DWORD>(str.length()), 0)) {
LOG(ERROR) << "CryptHashData failed: " << GetLastError();
- return std::string(SHA1_LENGTH, '\0');
+ return std::string(kSHA1Length, '\0');
}
DWORD hash_len = 0;
@@ -41,7 +41,7 @@ std::string SHA1HashString(const std::string& str) {
reinterpret_cast<unsigned char*>(&hash_len),
&buffer_size, 0)) {
LOG(ERROR) << "CryptGetHashParam(HP_HASHSIZE) failed: " << GetLastError();
- return std::string(SHA1_LENGTH, '\0');
+ return std::string(kSHA1Length, '\0');
}
std::string result;
@@ -51,13 +51,13 @@ std::string SHA1HashString(const std::string& str) {
reinterpret_cast<BYTE*>(WriteInto(&result, hash_len + 1)), &hash_len,
0))) {
LOG(ERROR) << "CryptGetHashParam(HP_HASHVAL) failed: " << GetLastError();
- return std::string(SHA1_LENGTH, '\0');
+ return std::string(kSHA1Length, '\0');
}
- if (hash_len != SHA1_LENGTH) {
+ if (hash_len != kSHA1Length) {
LOG(ERROR) << "Returned hash value is wrong length: " << hash_len
- << " should be " << SHA1_LENGTH;
- return std::string(SHA1_LENGTH, '\0');
+ << " should be " << kSHA1Length;
+ return std::string(kSHA1Length, '\0');
}
return result;