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

Unified Diff: base/secure_hash_openssl.cc

Issue 6276002: Abstracts SHA256 context for NSS / OpenSSL. (Closed) Base URL: svn://svn.chromium.org/chrome/trunk/src
Patch Set: Moves to SecureHash (and other comments) Created 9 years, 11 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/secure_hash_openssl.cc
diff --git a/base/secure_hash_openssl.cc b/base/secure_hash_openssl.cc
new file mode 100644
index 0000000000000000000000000000000000000000..d0adf762232c4a224742483eeb08f034a135a1be
--- /dev/null
+++ b/base/secure_hash_openssl.cc
@@ -0,0 +1,52 @@
+// 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/secure_hash.h"
+
+#include <openssl/ssl.h>
+
+#include "base/basictypes.h"
+#include "base/logging.h"
+#include "base/openssl_util.h"
+#include "base/stl_util-inl.h"
wtc 2011/01/25 19:06:43 Remove this header.
bulach 2011/01/25 20:33:41 Done.
+
+namespace base {
+
+namespace {
+
+class SecureHashSHA256OpenSSL : public SecureHash {
+ public:
+ SecureHashSHA256OpenSSL() {
+ SHA256_Init(&ctx_);
+ }
+
+ virtual ~SecureHashSHA256OpenSSL() {
+ OPENSSL_cleanse(&ctx_, sizeof(ctx_));
+ }
+
+ virtual void Update(const std::string& str) {
+ SHA256_Update(&ctx_, reinterpret_cast<const unsigned char*>(str.data()),
+ str.size());
+ }
+
+ virtual void Finish(void* output, size_t len) {
+ ScopedOpenSSLSafeSizeBuffer<SHA256_DIGEST_LENGTH> result(
+ reinterpret_cast<unsigned char*>(output), len);
+ SHA256_Final(result.safe_buffer(), &ctx_);
+ }
+
+ private:
+ SHA256_CTX ctx_;
+};
+
+} // namespace
+
+SecureHash* SecureHash::Create(Type type) {
+ if (type == TYPE_SHA256)
+ return new SecureHashSHA256OpenSSL();
+ NOTIMPLEMENTED();
+ return NULL;
wtc 2011/01/25 19:06:43 Use a switch statement.
bulach 2011/01/25 20:33:41 Done.
+}
+
+} // namespace base

Powered by Google App Engine
This is Rietveld 408576698