summaryrefslogtreecommitdiffstats
path: root/base
diff options
context:
space:
mode:
authorjoth@chromium.org <joth@chromium.org@0039d316-1c4b-4281-b951-d872f2087c98>2011-04-11 10:28:46 +0000
committerjoth@chromium.org <joth@chromium.org@0039d316-1c4b-4281-b951-d872f2087c98>2011-04-11 10:28:46 +0000
commit087b8c8ecf6630ab31d30913148e0e613a0ab881 (patch)
tree5b4b8f40859fc0a3a424ef75f385245cb1227205 /base
parent5da80df33dcd871dba15546f482350ef24c095fc (diff)
downloadchromium_src-087b8c8ecf6630ab31d30913148e0e613a0ab881.zip
chromium_src-087b8c8ecf6630ab31d30913148e0e613a0ab881.tar.gz
chromium_src-087b8c8ecf6630ab31d30913148e0e613a0ab881.tar.bz2
Simplify SHA2 implementation
Now portable, implemented as a wrapper over the SecureHash class. BUG=None TEST=base_unittests --gtest_filter=*Sha* --vmodule=*openssl*=3 Review URL: http://codereview.chromium.org/6812048 git-svn-id: svn://svn.chromium.org/chrome/trunk/src@81087 0039d316-1c4b-4281-b951-d872f2087c98
Diffstat (limited to 'base')
-rw-r--r--base/base.gypi6
-rw-r--r--base/sha2.cc17
-rw-r--r--base/sha2_openssl.cc30
3 files changed, 7 insertions, 46 deletions
diff --git a/base/base.gypi b/base/base.gypi
index 3c41a39..44fa935 100644
--- a/base/base.gypi
+++ b/base/base.gypi
@@ -553,10 +553,6 @@
'hmac_nss.cc',
'nss_util.cc',
'nss_util.h',
- # Note that sha2.cc depends on the NSS files bundled into
- # chromium; it does not have the _nss postfix as it is required
- # on platforms besides linux and *bsd.
- 'sha2.cc',
'third_party/nss/blapi.h',
'third_party/nss/blapit.h',
'third_party/nss/sha256.h',
@@ -573,7 +569,6 @@
'hmac_openssl.cc',
'openssl_util.cc',
'openssl_util.h',
- 'sha2_openssl.cc',
],
},],
],
@@ -659,7 +654,6 @@
'openssl_util.h',
'sha2.cc',
'sha2.h',
- 'sha2_openssl.cc',
'string16.cc',
'string16.h',
'sync_socket.h',
diff --git a/base/sha2.cc b/base/sha2.cc
index c0fd0ab..e8c922c 100644
--- a/base/sha2.cc
+++ b/base/sha2.cc
@@ -1,23 +1,20 @@
-// Copyright (c) 2006-2008 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.
#include "base/sha2.h"
+#include "base/crypto/secure_hash.h"
+#include "base/scoped_ptr.h"
#include "base/stl_util-inl.h"
-#include "base/third_party/nss/blapi.h"
-#include "base/third_party/nss/sha256.h"
namespace base {
void SHA256HashString(const std::string& str, void* output, size_t len) {
- SHA256Context ctx;
-
- SHA256_Begin(&ctx);
- SHA256_Update(&ctx, reinterpret_cast<const unsigned char*>(str.data()),
- static_cast<unsigned int>(str.length()));
- SHA256_End(&ctx, static_cast<unsigned char*>(output), NULL,
- static_cast<unsigned int>(len));
+ scoped_ptr<base::SecureHash> ctx(base::SecureHash::Create(
+ base::SecureHash::SHA256));
+ ctx->Update(str.data(), str.length());
+ ctx->Finish(output, len);
}
std::string SHA256HashString(const std::string& str) {
diff --git a/base/sha2_openssl.cc b/base/sha2_openssl.cc
deleted file mode 100644
index afbce2f..0000000
--- a/base/sha2_openssl.cc
+++ /dev/null
@@ -1,30 +0,0 @@
-// 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.
-
-#include "base/sha2.h"
-
-#include <openssl/ssl.h>
-
-#include "base/basictypes.h"
-#include "base/openssl_util.h"
-#include "base/stl_util-inl.h"
-
-namespace base {
-
-void SHA256HashString(const std::string& str, void* output, size_t len) {
- COMPILE_ASSERT(SHA256_LENGTH == SHA256_DIGEST_LENGTH,
- API_and_OpenSSL_SHA256_lengths_must_match);
- ScopedOpenSSLSafeSizeBuffer<SHA256_DIGEST_LENGTH> result(
- reinterpret_cast<unsigned char*>(output), len);
- ::SHA256(reinterpret_cast<const unsigned char*>(str.data()), str.size(),
- result.safe_buffer());
-}
-
-std::string SHA256HashString(const std::string& str) {
- std::string output(SHA256_LENGTH, 0);
- SHA256HashString(str, string_as_array(&output), output.size());
- return output;
-}
-
-} // namespace base